java basics. to checkout, use: svn co svn+ssh://(utorid)@mathlab.utsc.utoronto.ca/svn/c...
TRANSCRIPT
![Page 1: Java Basics. To checkout, use: svn co svn+ssh://(UTORid)@mathlab.utsc.utoronto.ca/svn/c scb07f12/UTORid Before starting coding always use: svn update](https://reader036.vdocuments.site/reader036/viewer/2022082322/56649f1f5503460f94c37ffe/html5/thumbnails/1.jpg)
CSCB07 TUTORIAL # 2
Java Basics
![Page 2: Java Basics. To checkout, use: svn co svn+ssh://(UTORid)@mathlab.utsc.utoronto.ca/svn/c scb07f12/UTORid Before starting coding always use: svn update](https://reader036.vdocuments.site/reader036/viewer/2022082322/56649f1f5503460f94c37ffe/html5/thumbnails/2.jpg)
To checkout, use: svn co svn+ssh://(UTORid)@mathlab.utsc.utoronto.ca/svn/cscb07f12/UTORid
Before starting coding always use: svn update
After finished some part of code, use: svn commit
If added a file use:svn add
SVN For Assignments (Review)
![Page 3: Java Basics. To checkout, use: svn co svn+ssh://(UTORid)@mathlab.utsc.utoronto.ca/svn/c scb07f12/UTORid Before starting coding always use: svn update](https://reader036.vdocuments.site/reader036/viewer/2022082322/56649f1f5503460f94c37ffe/html5/thumbnails/3.jpg)
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)
Variables and Pointers (Aliases.java)
![Page 4: Java Basics. To checkout, use: svn co svn+ssh://(UTORid)@mathlab.utsc.utoronto.ca/svn/c scb07f12/UTORid Before starting coding always use: svn update](https://reader036.vdocuments.site/reader036/viewer/2022082322/56649f1f5503460f94c37ffe/html5/thumbnails/4.jpg)
For Objects, use: .equals()(== will check the address in memory)
For Primitive Types, use: ==
Comparisons and Equality(Equality.java)
![Page 5: Java Basics. To checkout, use: svn co svn+ssh://(UTORid)@mathlab.utsc.utoronto.ca/svn/c scb07f12/UTORid Before starting coding always use: svn update](https://reader036.vdocuments.site/reader036/viewer/2022082322/56649f1f5503460f94c37ffe/html5/thumbnails/5.jpg)
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<String> names = new ArrayList<String>();Size changes as needed + lots of functions!
Basic Objects (MoreBasics.java)
![Page 6: Java Basics. To checkout, use: svn co svn+ssh://(UTORid)@mathlab.utsc.utoronto.ca/svn/c scb07f12/UTORid Before starting coding always use: svn update](https://reader036.vdocuments.site/reader036/viewer/2022082322/56649f1f5503460f94c37ffe/html5/thumbnails/6.jpg)
int num = 5while (num > 0) {
num --;}
for (int i = 0; i < 10; i++) {}
String word = ”icantcomeupwithone”for (char letter : word){
System.out.println(letter);}
Loops
![Page 7: Java Basics. To checkout, use: svn co svn+ssh://(UTORid)@mathlab.utsc.utoronto.ca/svn/c scb07f12/UTORid Before starting coding always use: svn update](https://reader036.vdocuments.site/reader036/viewer/2022082322/56649f1f5503460f94c37ffe/html5/thumbnails/7.jpg)
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!
Casting and Wrappers
![Page 8: Java Basics. To checkout, use: svn co svn+ssh://(UTORid)@mathlab.utsc.utoronto.ca/svn/c scb07f12/UTORid Before starting coding always use: svn update](https://reader036.vdocuments.site/reader036/viewer/2022082322/56649f1f5503460f94c37ffe/html5/thumbnails/8.jpg)
Scope is method’s or variable’s visibility Passing variables to functions:
For primitive data types new variable is created in the function’s scopeFor Objects – a reference to the same Object is passed along to the function’s scope
Refer to Variables and Pointers slide!
Scope(Parameters.java Locals.java)