head first java chapter 1

20
Head First Java Chapter 1 Tom Henricksen

Upload: tom-henricksen

Post on 17-Feb-2017

166 views

Category:

Software


0 download

TRANSCRIPT

Head First Java Chapter 1Tom Henricksen

The Way Java Works● Source

● Compiler

● Output(code)

● Virtual Machine

Code Structure in Java

● Source

● Class

● Method

Eclipse

Eclipse

Eclipse

Eclipse

Eclipse

Eclipse

HelloWorldpublic class HelloWorld {

public static void main (String[] args) {

System.out.println(“Hello World”);

}

}

Run your application

Run your application

Statements//declaration

String name;

//assignment

name = “Tom”;

//method call

double d = Math.Random();

Loopswhile (score > 10) {

score = score + 1;

}

For (int v = 0; v < 5; v++) {

System.out.println(v);

}

Branchingif (x = 10) {

System.out.println(“x is ten”);

} else {

System.out.println(“x is NOT ten”);

}

Boolean tests< (less than)

> (greater than)

== (equality)

while (x < 10) {

x = x + 1;

}

NameLoop.javapublic class NameLoop {

public static void main (String[] args) {

int x = 1;

while (x < 10) {

System.out.println(“My name is Tom!”)

}

}

Java Basics● Statements end with a semicolon;

● Code blocks are defined by 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 ==

Java Basics● A while loop runs everything within its block as long as

conditional test is true

● If the conditional is false, the while loop code block won’t

run, and execution will move down

● Put your boolean test within parentheses

while (x==4) {}

Exercise