Interpreting Java syntax

Introduzione a Java

Jim White

Java Developer

Class

$$

  • A container to organize code

One class with some code inside

Introduzione a Java

Class

$$

  • A container to organize code

Many classes

Introduzione a Java

Defining class

class Greeting {





}
  • {} mark where class begins and ends
Introduzione a Java

Class and the main method

class Greeting {


public static void main(String[] args) { }
}
  • Code runs inside the method main()
Introduzione a Java

Case, semicolons, and white space

  • Java is case sensitive

    • main ≠ Main
  • Every line inside the method ends with ;

    • System.out.println("Hello!");
  • Indentation is only used to improve readability

2 valid examples with and without identation

Introduzione a Java

Println as a calculator

class PrintlnAsCalculator {
  public static void main(String[] args) {

System.out.println(1+2);
} }
3
Introduzione a Java

Adding comments

class PrintlnAsCalculator {
  public static void main(String[] args) {

// We can use println as a calculator
System.out.println(1+2); } }
3

$$

  • Comments make code easier to read
Introduzione a Java

Let's practice!

Introduzione a Java

Preparing Video For Download...