/* SaysHello.java Example of a Java class with a main method which prints stuff out */ // classes in Java are organized into packages // this line tells Java which package this class is in package helloworld.chapin; // example class with a main method // this is a class -- the basic unit in Java // the name of the class is SaysHello // everything inside the curly braces is part of the class public class SaysHello { // note, if you put code HERE it is "in your main class" but not "in the main" // main method is the part of the program that runs // it must be declared exactly like this public static void main(String[] args) { // everything inside the curly braces is part of the main method // so code you put here is "in the main" // System.out is part of an existing Java library // someone else wrote it, we can use it // println is a method that knows how to print // it will print whatever we put into the parentheses // what we put in the parens are called arguments // use double quotes to say exactly what to print System.out.println("Hello World"); // print( prints without a new line // \n is a special code for putting in a new line // this does the same thing as // System.out.println(" hell "); // System.out.println("world "); System.out.print("Oh "); System.out.print(" hell \n world \n"); // no arguments --> all we get is a new line System.out.println(); // another way to get a new line System.out.print("\n"); // some things are tricky to print, use \ to "escape" them so Java knows what you mean System.out.println("I can print double quote \" "); System.out.println("I can print backslash \\ "); System.out.println("Bye now."); } // main method ends here // if you put code here it is "in your main class" but not "in the main" } // class ends here // no code should ever go here