Welcome to October 5. 

-bash-4.2$ pwd
/u/dgerman/apache/htdocs/c212/fall2020
-bash-4.2$ ls -ld 1005a.phps
-rw-r--r-- 1 dgerman faculty 25 Oct  5 15:08 1005a.phps
-bash-4.2$ date
Mon Oct  5 15:09:09 EDT 2020
-bash-4.2$

Chapter 1: Java. Simplest program. 
Chapter 2: Using Objects. BigInteger syntax. 
Chapter 3: User-Defined Types.
Chapter 4: Assignments, Types, Variables, Expressions. 
Chapter 5: Booleans. Decisions. if Statements. 
Chapter 6: Loops (while, for, do-while).
Chapter 7: arrays and ArrayList's. 

After this: static members, inheritance, polymorphism, abstract classes, interfaces.

These are concepts without which the language cannot function. They're part of the language. 

After that you have to identify significant packages libraries and work with them.


Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop\lecture 13
> int[] a
> a = new int[10]
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
> a[4] = -1
-1
> a
{ 0, 0, 0, 0, -1, 0, 0, 0, 0, 0 }
> import java.util.ArrayList
> ArrayList<String> b
> b = new ArrayList<String>()
[]
> b
[]
> b.size()
0
> b.add("Once")
true
> b.add("upon")
true
> b.add("a")
true
> b
[Once, upon, a]
> b.add("time")
true
> b.add(" in America.")
true
> b
[Once, upon, a, time,  in America.]
> b.size()
5
> b.remove(4)
" in America."
> b
[Once, upon, a, time]
> b.add("in")
true
> b.add("America")
true
> b
[Once, upon, a, time, in, America]


--

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop\lecture 13
> int[] a = new int[3]
> a
{ 0, 0, 0 }
> String[] b // declaration (b is to be used to refer to an array of String objects)
> b = new String[6]
{ null, null, null, null, null, null }
> b[4] = "in"
"in"
> b
{ null, null, null, null, in, null }
> b[1] = "upon"
"upon"
> b
{ null, upon, null, null, in, null }
> b[2] = "a"
"a"
> b[5] = "America"
"America"
> b[0] = "Once"
"Once"
> b
{ Once, upon, a, null, in, America }
> b[3] = "time"
"time"
> b
{ Once, upon, a, time, in, America }
>

--

In Java there are two kinds of types: 

(a) primitive types: byte, short, int, long, float, double, boolean, char 

Values of primitive types are not objects. They are more primitive than that. 

(b) user-defined types (also known as: classes, reference types) 

Values of (b) are objects. Objects don't fit into a variable. Values of (a) do. 

--

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop\lecture 13
> int[] a; // declaration
> String[] b; // also OK
> import java.util.ArrayList;
> ArrayList<int> c; // not allowed for ArrayLists to store values of primitive type
Static Error: Type has incompatible bounds
> ArrayList<Integer> c; 
> c = new ArrayList<Integer>();
> c
[]
> c.add(1)
true
> c
[1]
> c.add(3)
true
> c
[1, 3]
> c.add(-2)
true
> c
[1, 3, -2]


--

All elements in an array must be of the same type. 

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop\lecture 13
> int[] a; // declaration
> int b[]; // declaration
> a = new int[3];
> a[2] = -1;
> a
{ 0, 0, -1 }
> // a is pointing to an array of ints
> // so does b and it's more intuitive
> int[] c[] // if you use c with an index it will give you a int[] (which is an array)  
> int[][] d // same kind of declaration
> int e[][] // same as c and d above 
> // debatable which one c or e are more intuitive
> int[][] u // declaration of a two-dimensional array
> import java.util.ArrayList;
> ArrayList<ArrayList<Integer>> m
> m
null
> m = new ArrayList<ArrayList<Integer>>
Incomplete expression
> m = new ArrayList<ArrayList<Integer>>()
[]
> m.add(new ArrayList<Integer>())
true
> m
[[]]
> m.add(new ArrayList<Integer>())
true
> m
[[], []]
> m.get(0).add(3)
true
> m
[[3], []]
> m.get(1).add(5)
true
> m.get(1).add(2)
true
> m
[[3], [5, 2]]


--

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop\lecture 13
> int[][] a
> a = new int[3][3]
{ { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } }
> a[2]
{ 0, 0, 0 }
> a[2] = new int[5]
{ 0, 0, 0, 0, 0 }
> a
{ { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0, 0, 0 } }
> a[2] = new int[3]
{ 0, 0, 0 }
> a
{ { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } }
> a[2][1] = -1 
-1
> a
{ { 0, 0, 0 }, { 0, 0, 0 }, { 0, -1, 0 } }
> int[] b
> b = a[1]
{ 0, 0, 0 }
> b
{ 0, 0, 0 }
> a[1]
{ 0, 0, 0 }
> b[2] = 5
5
> b
{ 0, 0, 5 }
> a[1]
{ 0, 0, 5 }
> a
{ { 0, 0, 0 }, { 0, 0, 5 }, { 0, -1, 0 } }
> a[1][2] += 1
6
> a
{ { 0, 0, 0 }, { 0, 0, 6 }, { 0, -1, 0 } }
> b[2] += 1
7
> b
{ 0, 0, 7 }
> a
{ { 0, 0, 0 }, { 0, 0, 7 }, { 0, -1, 0 } }
> a[1]
{ 0, 0, 7 }


--

Polymorphism 

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop\lab05
> Circle a = new Circle()
> a
Circle@6282fceb
> Rectangle b = new Rectangle()
> b
Rectangle@58ca1f32
> Circle[] c = new Circle[2]
> c[0] = a
Circle@6282fceb
> c[1] = b
Static Error: Bad types in assignment: from Rectangle to Circle
> Rectangle[] d = new Rectangle[2]
> d[0] = a
Static Error: Bad types in assignment: from Circle to Rectangle
> d[1] = b
Rectangle@58ca1f32
> Object[] e = new Object[2]
> e[0] = a
Circle@6282fceb
> e[1] = b
Rectangle@58ca1f32
> e
{ Circle@6282fceb, Rectangle@58ca1f32 }


--

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop\lab05
> Shape[] a = new Shape[2]
> a
{ null, null }
> a[0] = new Circle()
Circle@3abda43
> a[1] = new Rectangle()
Rectangle@74eb8365
> a
{ Circle@3abda43, Rectangle@74eb8365 }
> Object[] b = new Object[2]
> b[0] = new Integer(12)
12
> b[1] = new Boolean(true)
true
> b
{ 12, true }


--

Can you represent any for loop as a while or do-while? Yes.

Can you represent any while loop as a for or do-while? Yes.

Can you represent any do-while loop as a while or for? Yes.

--

public class Shape /* extends Object */ {
  
}

class Circle extends Shape {
   
}

class Rectangle extends Shape {
  
}

--

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop\lab05
> import java.util.Arrays
> int[] a = new int[4]
> a
{ 0, 0, 0, 0 }
> a[3] = 1
1
> a
{ 0, 0, 0, 1 }
> int[] b = Arrays.copyOf(a, 5)
> b
{ 0, 0, 0, 1, 0 }
> b[4] = 6
6
> b
{ 0, 0, 0, 1, 6 }
> a
{ 0, 0, 0, 1 }
> b = Arrays.copyOf(b, b.length+3)
{ 0, 0, 0, 1, 6, 0, 0, 0 }
> b
{ 0, 0, 0, 1, 6, 0, 0, 0 }
> b[b.length-1] = -2
-2
> b
{ 0, 0, 0, 1, 6, 0, 0, -2 }


--

See you Wednesday!

--