Java Basics.  To checkout, use: svn co scb07f12/UTORid  Before starting coding always use: svn update.

Slides:



Advertisements
Similar presentations
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Advertisements

Primitives, References and Wrappers Java has the following types defined as part of the java language; int float double byte char boolean long short These.
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Starting Out with Java: From Control Structures through Objects Fourth.
CERTIFICATION OBJECTIVES Use Class Members Develop Wrapper Code & Autoboxing Code Determine the Effects of Passing Variables into Methods Recognize when.
©2004 Brooks/Cole Chapter 7 Strings and Characters.
Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
6/10/2015C++ for Java Programmers1 Pointers and References Timothy Budd.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
Dynamic Memory Allocation in C++. Memory Segments in C++ Memory is divided in certain segments – Code Segment Stores application code – Data Segment Holds.
1 Where did the synchronized methods go? Yes, there still exists the synchronized keyword. public synchronized void foo() {} public void foo(){ aLock.lock();
Pointer. Warning! Dangerous Curves C (and C++) have just about the most powerful, flexible and dangerous pointers in the world. –Most other languages.
Chapter 5: Enhancing Classes Presentation slides for Java Software Solutions Foundations of Program Design Second Edition by John Lewis and William Loftus.
Miscellaneous OOP topics Java review continued. Simple data types & wrapper classes Simple data types are the built-in types provided as part of the Java.
Adapted from Dr. Craig Chase, The University of Texas at Austin.
March 2005Java Programming1. March 2005Java Programming2 Why Java? Platform independence Object Oriented design Run-time checks (fewer bugs) Exception.
Java Methods A & AB Chapter 10 - Strings. Ch 10 Goals Understand Strings indepth Learn strategies to deal with the immutability of Strings Learn how to.
EECE 310: Software Engineering Lecture 2: Understanding Objects in Java and Types.
P Object type and wrapper classes p Object methods p Generic classes p Interfaces and iterators Generic Programming Data Structures and Other Objects Using.
BPJ444: Business Programming using Java Java basics Tim McKenna
Java Data Types. Primitive Data Types Java has 8 primitive data types: – char: used to store a single character eg. G – boolean: used to store true or.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Basics of Java IMPORTANT: Read Chap 1-6 of How to think like a… Lecture 3.
Arrays and ArrayLists in Java L. Kedigh. Array Characteristics List of values. A list of values where every member is of the same type. Each member in.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Defining and Converting Data Copyright Kip Irvine, 2003 Last Update: 11/4/2003.
Comp 248 Introduction to Programming Chapter 4 & 5 Defining Classes Part C Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia.
Some Standard Classes Goals The Object class The String class Wrapper classes The Math class Random Numbers.
Starting Out with Java: From Control Structures through Objects Fifth Edition by Tony Gaddis Chapter 5: Methods.
Types in programming languages1 What are types, and why do we need them?
Lecture 3 Classes, Structs, Enums Passing by reference and value Arrays.
 Structures are like arrays except that they allow many variables of different types grouped together under the same name. For example you can create.
Objects & Classes Weiss ch. 3. So far: –Point (see java.awt.Point) –String –Arrays of various kinds –IPAddress (see java.net.InetAddress) The Java API.
Chapter 5 Objects and Classes Inheritance. Solution Assignments 3 & 4 Review in class…..
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Computer Organization and Design Pointers, Arrays and Strings in C Montek Singh Sep 18, 2015 Lab 5 supplement.
Programming in Java (COP 2250) Lecture 4 Chengyong Yang Fall, 2005.
This will all add up in the end. Assignment operator =Simple Assignment operator Arithmetic Operators +Additive operator – Subtraction operator * Multiplication.
Objects and Variables Local variables – Confined to single context: allocated on stack – Primitive types such as int or object references – Must be initialized.
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
Object Oriented Software Development 4. C# data types, objects and references.
Composition When one class contains an instance variable whose type is another class, this is called composition. Instead of inheritance, which is based.
Functions, Scope, and The Free Store Functions Functions must be declared by a function prototype before they are invoked, return_type Function_name(type,
How to execute Program structure Variables name, keywords, binding, scope, lifetime Data types – type system – primitives, strings, arrays, hashes – pointers/references.
Typecasting References Computer Science 3 Gerb Reference: Objective: Understand how to use the Object class in Java in the context of ArrayLists.
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
CSC 142 F 1 CSC 142 References and Primitives. CSC 142 F 2 Review: references and primitives  Reference: the name of an object. The type of the object.
LESSON 5 – Assignment Statements JAVA PROGRAMMING.
Announcements You will receive your scores back for Assignment 2 this week. You will have an opportunity to correct your code and resubmit it for partial.
Array and Pointers An Introduction Unit Unit Introduction This unit covers the usage of pointers and arrays in C++
Introduction to C Programming CE Lecture 6 Functions, Parameters and Arguments.
1 Chapter 7 Pointers and C-Strings. 2 Objectives  To describe what a pointer is (§7.1).  To learn how to declare a pointer and assign a value to it.
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
“Unboxing” means taking an Integer object and assigning its value to a primitive int. This is done using the.intValue( ) method. Example; Integer z = new.
1 Memory, Arrays & Pointers. Memory 2 int main() { char c; int i,j; double x; cijx.
EECE 309: Software Engineering
Java Primer 1: Types, Classes and Operators
Lecture 10: More on Methods and Scope
Wrapper Classes The java.lang package contains wrapper classes that correspond to each primitive type: Primitive Type Wrapper Class byte Byte short Short.
Variables Title slide variables.
Sridhar Narayan Java Basics Sridhar Narayan
Unit 6 - Variables - Fundamental Data Types
Java for IOI.
Chapter 6 – Methods Topics are:
Reference semantics, variables and names
Java Basics Data Types in Java.
Review: libraries and packages
Java: Variables, Input and Arrays
Subtype Substitution Principle
Presentation transcript:

Java Basics

 To checkout, use: svn co scb07f12/UTORid  Before starting coding always use: svn update  After finished some part of code, use: svn commit  If added a file use: svn add

 Primitive data types: int, boolean, double, long, char -Variable assignment creates a new variable! (new memory location)  Objects: String, ArrayList, Integer -Variable assignment passes a reference to the same object! (same memory location - use ‘new’ to create a new modified object)

 For Objects, use:.equals() (== will check the address in memory)  For Primitive Types, use: ==

 String a = "Joshua"; Strings are immutable! a+a is still a!  StringBuilder c = new StringBuilder("Baby"); String builder is like a mutable String  Arrays: int[][] table = new int[50][30] Can’t change the size once created! (recreate)  ArrayList: ArrayList names = new ArrayList (); Size changes as needed + lots of functions!

 int num = 5 while (num > 0) { num --; }  for (int i = 0; i < 10; i++) { }  String word = ”icantcomeupwithone” for (char letter : word){ System.out.println(letter); }

 Wrapper is an Object class for a primitive type Eg: Integer, Double, … They provide extra functions like conversion: Integer.parseInt(“56”);  Casting is explicit conversion to some Object Object obj = “StringularThing”; String str = (String) obj; Help avoid compiler errors but may cause runtime. Careful!

 Scope is method’s or variable’s visibility  Passing variables to functions: For primitive data types new variable is created in the function’s scope For Objects – a reference to the same Object is passed along to the function’s scope  Refer to Variables and Pointers slide!