Language Basics

Control Structures

  • Loops
  • If-else
  • Switch

Same as C!

1
2
3
for (int i = 0; i < someArray.length; i++) {
  // ...
}

Object iteration

1
2
3
for (String s : someStrings) {
  System.out.println(s)
}

Concatenation

We can concatenate a Number and a String through the magic of polymorphism!

1
System.out.println("I am " + 12 + " years old.");

Data Types

  • String
  • Boolean
  • Arrays have a length, with <Array>.length

Packages

  • package to declare a namespace
  • import to import

Niches

Every file is a class

Every file is stored in a class file, even if that file is not related to an object

The class name must be the same as the file name

If your code has

1
class Foo { ... }

You must name that file Foo.java

Program entry point

All entry points (places where the program can start) follow the syntax of the

1
2
3
public static void main(String[] args) {
  // ...
}