Skip to content
Kyle Coberly edited this page Aug 23, 2020 · 5 revisions

Java

  • Works left to right, but uses precedence for math
  • System is part of the java.lang package, which is automatically imported
  • final makes something a constant, and uses THIS_CONVENTION
  • You can cast with parentheses - double someNumber = (int) 2.1 + 3.4
  • if/else, switch, while, for, logic operators are all the same as JS

Vocab

  • Package = Related classes. Token -> Expression -> Statement -> Method -> Class -> Package

Installing

  • sudo apt install openjdk-11-jdk-headless

Hello World

// HelloWorld.class
public class HelloWorld {
  public static void main(String[] args){
    System.out.println("Hello, World!");
  }
}
javac HelloWorld.class
java HelloWorld

Types

  • int
  • String - Compare with .equals, not ==
  • double - Default float
  • boolean
  • char - Get from string with .charAt(position), cast with (char) from unicode

Questions

  • Why are some types uppercase and others lowercase?

Clone this wiki locally