Creating Your First Java Application, Hello World! Java

Create Your First Application Program

public class HelloWorld { // class start

    public static void main(String[] args) { // method start
        System.out.println("Hello World! Java.");
    }
}

Notes When Writing Source Code

  • English uppercase and lowercase letters are distinguished.
  • When saving, the file name must match the class name, and the extension is .java.
  • HelloWorld.java
  • Compile
    javac HelloWorld.java
    
  • Run
    java HelloWorld
    

Class Definition

  • Because Java programs are written in units of classes, a class must be defined in the source file.
  • By convention, a class name starts with an uppercase letter.
  • Class components(properties, methods, and so on) are placed inside { }.
  • When saving a source file, the file name must match the class name. This excludes cases where multiple classes exist in one file.

Defining the main(String[] args) Method

  • At least one must exist for an application program to run.
  • It is the entry point of the program, is called first by the JVM, and sequentially executes the statements written inside the main method block.
  • The JVM recognizes a statement ending with a semicolon(;) as one command statement.
  • Comments are used to make program source code easier to understand and do not affect compilation or execution.