openthink labs training : diving into java, breaking the surface
TRANSCRIPT
#1
Day #1
Breaking the Surface
A Quick Dip
Wildan [email protected]
http://training.openthinklabs.com/
Come on, the water'sgreat! We'll dive right in and
write some code, then compile andrun it. We're talking syntax, loopingand branching, and a look at what
makes Java so cool. You'll becoding in no time.
The Way Java Works
What you'll do in Java
Avery brief history of Java
Look how easy Itis to write Java.
int size = 27;String name = UFido";Dog rnyDog = new Dog(name, size);x = size – 5 ;if (x < 15) myDog.bark(8);while (x > 3) { myDog.play();}int [ ] numList = {2,4,6,8};System. out. print (“Hello” ) ;System.out.print(“Dog: “ + name);String nurn = “8";int Z = Integar.parselnt(nurn);try { readTheFile(“myFile.txt”) ;}catch(FileNotFoundException ex) { System.out.print(“File not found.");}
Code structure in Java
Anatomy of a class
Writing a class with a main
What can you say In the main method ?
Syntax Fun
Looping and Looping and ...
Bullet Points● Statements end in a semicolon ;
● Code blocks are defined by a pair of curly braces { }
● Declare an int variable with a name and a type: int x;
● The assignment operator Is one equals sign =
● The equals operator uses two equals signs ==
● A while loop runs everything within its block (defined by curly braces) as long as the conditional test Is true.
● If the conditional test is false, the while loop code block won't run, and execution will move down to the code Immediately after the loop block.
● Put a boolean test Inside parentheses: while (x = 4) ( }
Conditional Branching
Sharpen Your Pencil
Coding a Serious Business Application
Monday Morning at Bob's
…...
Let's Write a Program
Reference
● Kathy Sierra & Bert Bates; Head First Java 2nd Edition, O'Reilly, 2002