Java Lesson 1: First Program- Hello World!

Key Points:

  • Java is an object oriented programming language that is owned by Oracle.
  • All Java Programs have a main method:
    public static void main(String[] args) {
  • In Java you can use many variable types:
    int var1;
    double var2;
    String var3;
    array var4[];
  • To output a phrase:
    System.out.println(“Your phrase”);
  • To output a variable:
    System.out.println(varName);
  • To output both a variable and phrase:
    System.out.println(“Your phrase ” + varName);
  • You can also comment out your code if you need to, this helps with debugging which I will talk about later!

Code of Program: 

package helloworld;

/**
*
* @author Zachary Murphy
*/
public class HelloWorld {

//main method of program
public static void main(String[] args) {
//variable declarations
int myAge = 20;
int myBirthYear = 1996;
String myName = “Zachary Murphy”;

//outputs
System.out.println(“Hello World!!!”);
System.out.println(“My name is ” + myName + “, I am ” + myAge + ” years old.”);
System.out.println(“I was born in ” + myBirthYear + “.”);
}

}

View Code On GitHub!