Richard's J2SE Day 2, The ABCs of Programming
=================================================================
Old notes from "Sams Teach Yourself Java 2 in 21 Days" (still vaild, but different page number)
=================================================================
(P38)
- Java = classes + objects = methods + variables
- methods = statements + expressions
3 kinds of varialbes (P39)
- instance variables, class variables, local variables.
- instance variables > define object's attributes
- class variables > define attributes of an entire class of objects
- local varialbe > used inside method definitions or smaller blocks of statements
(P40) examples of defining variables
Naming variables
- start with a letter, an _, or a $
- after first letter, any letters of numbers (unicode character number)
- case sensitive
Variable Types (P41)
- type > basic data type, name of a class or interface, an array
- 8 basic data types (primitive types): byte, short, int, long, float, double, char, boolean
- assignment operation =
Constant (P43)
final float PI = 3.141592;
Comments (P45)
//
/* */
Literals (P45)
What you type is what you get. Numbers, characters, and strings etc
Number Literals (P46)
long integer > e.g. pennyTotal = pennyTotal + 4L; //value 4 as a long integer
octal numbering > prepending a 0, e.g. 0777
hexadecimal > 0x, e.g. 0x12 or 0xFF
floating point . as default double > double myGPA = 3.85;
floating point F as float > float piValue = 3.1415927F;
e or E, exponents in floating point > double x = 12e22; double y = 19E-95;
Boolean Literals (P47)
true and false (1 and 0 does not work for Java)
Character Literals (P47)
'a'.
'#'
Table 2.2 Character Escape Codes \
String Literals (P48)
" "
character escape code \"
Expression and Operatiors (P49)
arithmetic
+ - * / %
assignment
= += -= *= /=
incrementing, decrementing
++ --
comparisions
== != < > <= >=
logical
AND = & or &&
Or = | or ||
XOR = ^
NOT = !
(P56) Table 2.6 Operator Precedence
String Arithmetic (P57)
Concatenate, +
(P61) Exercise variables.java
=================================================================
New notes from "Sams Teach Yourself Java 6 in 21 Days"
=================================================================
3 variable types:
- one of the 8 primitive data types
- name of a class or interface
- an array
Example NewVariable done in NetBean, only a main() method