Java Basics


// Single line comment


/** JavaDoc Comment */

JavaDoc should be avoided due to keep the code clean

Naming Convention

  • Class name identifier should start with capital letter e.g. public class Welcome1
  • Identifier can comprise of letter, number, underscore, and $. But $ should be avoided as it is usually used by compiler for special things.
  • For multi-word class name, use PascalCase.

Java is case-sensitive language

Entry Point

  • public static void main(String[] args)
  • main method must be all lower case letters


  • All classes under java.lang e.g. System, String are automatically imported.

Command Line


> javac
  • .class file (Java byte code) is generated and can be JIT-compiled and execued by JVM


> java Welcome1
Welcome to Java Programming!

Online Documentation

Primitive Types vs. Reference Types

8 Primitive Types

    • boolean
    • byte - 1-byte integer
    • char - 1-byte unsigned integer
    • short - 2-byte integer
    • int - 4-byte (32 bit) integer
    • long - 8-byte (64 bit) integer
    • float - 4-byte decimal number
    • double - 8-byte decimal number
  • All types are initialized with 0 except boolean that is initialized as false.
  • Java guarantees fixed size of each primitive types, not varying by system
  • boolean is not a number in Java

Reference Types

  • All non-primitive types, usually start with Capital leter
  • Is an object so initialized as null
  • Can contain instance variables and methods