Topics on the exam: 

  (a) basic stuff: objects and classess
  (b) simple expressions and types: for you to evaluate
  (c) decisions and booleans (maybe simplify some expressions

No loops, or anything else. 

Basically Chapters 1-5 from the text, just do the reading assignment. 

In Java there are eight primitive types:

  (a) whole numbers: int, byte, long, short 

  (b) numbers with decimals: double, float 

  (c) booleans (truth values): boolean  

  (d) characters (they act as numbers in the right context): char 

Everything else is a reference type (object of a class). 

Welcome to DrJava.  Working directory is C:\Users\dgerman
> 'a'
'a'
> 1
1
> '7'
'7'
> 7
7
> '7' + 0
55
> 'a'
'a'
> 'A'
'A'
> 'A' + 0
65
> 'C' - 'A'
2
> 'm' - 'n'
-1


Strings are made of characters, but they are objects.

Welcome to DrJava.  Working directory is C:\Users\dgerman
> "abc"
"abc"
> "abc".length()
3
> "abc".charAt(1)
'b'
> "abc".substring(1)
"bc"
> "abc".substring(1, 2)
"b"


I can name them though I don't have to:

Welcome to DrJava.  Working directory is C:\Users\dgerman
> String mike = "whatever";
> "whatever".length()
8
> mike.length()
8


Some characters need to be escaped inside a String:

Welcome to DrJava.  Working directory is C:\Users\dgerman
> "abc".length()
3
> """"".length()
Invalid top level statement
> "\"\"\"".length()
3
> System.out.println("\"\"\"");
"""
> "\"\"\""
"""""
> "\\\".length()
Lexical error at line 1, column 15.  Encountered: <EOF> after : "\"\\\\\\\".length()"
> "\\\\".length()
2
> "\\\\\\".length()
3
> System.out.println("\\\\\\")
\\\


So special characters in strings: \" \\ \n \t \b and who knows what others

Welcome to DrJava.  Working directory is C:\Users\dgerman
> "\n\n\n".length()
3
> "a\nb\nc\n".length()
6
> System.out.println("a\nb\nc\n");
a
b
c

> 'a' + 'b'
195
> "" + 'a' + 'b'
"ab"
> "" + 1 + 2
"12"
> "" + (1 + 2)
"3"


https://www.amazon.com/Art-Taking-Action-Japanese-Psychology/dp/0982427387

Literals

Welcome to DrJava.  Working directory is C:\Users\dgerman
> 1
1
> 1.2
1.2
> true
true
> 'a'
'a'
> 1 + 2
3
> 1 - 2
-1
> 1 - 2 - 3
-4
> 1 - (2 - 3)
2
> 1 / 2 * 4
0
> 4 * 1 / 2 
2
> int n = 3
> n++
3
> n
4
> ++n
5
> n
5
> n++ + ++n // 5 (and n is 6 now) + (n becomes 7) 7 
12
> n
7


Now boolean values:

Welcome to DrJava.  Working directory is C:\Users\dgerman
> 1
1
> 1 + 2
3
> 1 < 2
true
> boolean a = 1 > 2;
> a
false


Operations on booleans: not, and and or. 

  a     b      !a     a && b    a || b 
 true  true   false   true       true 
 true  false          false      true 
 false true   true    false      true 
 false false          false      false 


Simplify this expression: 

  1. a == true simplifies to a (see below)

  2. a == false 

     a      a == false    a        f(a) = !a
    true    false         true       false 
    false   true          false      true 


  3. a && !a


   a       a == true   f(a) = a    true 
  true     true          true      true 
  false    false         false     true 


When you simplify:

  (a) find an equivalent expression

  (b) make sure it's the shortest

So with this finish your reading assignments, look