Interpreting Java syntax

Introduction to Java

Jim White

Java Developer

Class

$$

  • A container to organize code

One class with some code inside

Introduction to Java

Class

$$

  • A container to organize code

Many classes

Introduction to Java

Defining class

class Greeting {





}
  • {} mark where class begins and ends
Introduction to Java

Class and the main method

class Greeting {


public static void main(String[] args) { }
}
  • Code runs inside the method main()
Introduction to 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

Introduction to Java

Println as a calculator

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

System.out.println(1+2);
} }
3
Introduction to 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
Introduction to Java

Let's practice!

Introduction to Java

Preparing Video For Download...