Parts of a Java Program
/************************************* *Project: LabOneA *Programmer: John Smith *Date: September 23 *Program Name: [Link] **************************************/ import [Link].*; public class Hello { public static void main (String[ ] args) { [Link]("This is a literal print."); [Link]("Yea!"); [Link]("Go Java!"); } }
Remember that Java is case sensitive. The CODE:
/************************************* *Project: LabOneA *Programmer: John Smith *Date: September 23 *Program Name: [Link] **************************************/
Information about the code:
All programs should begin with a commentidentifying the purpose of the program and the programmer. /**documentation */ - documentation commenting. /* text*/ - is the format for block commenting. // text - is the format for single line commenting. Comment statements are ignored by the compiler. It is a message to the reader of the code. The import command tells the computer to find packages that will be needed in the execution of the program. The [Link] package is the only package imported automatically without an explicit command; all other packages need an import command. This package is used for input and output. (Packages are collections of classes (libraries) which contain portable Java bytecode files.)
import [Link].*;
public class Hello
Every Java program is a class. The program starts with the name of the class. This name must be the same name as the . java file in your folder. In this case the file is saved as [Link].
Class names must begin with a letter, an underscore or a dollar sign. Class names may contain only letters, digits, underscores and/or dollar signs. Class names may not use reserved words. A set of French curly braces { } is needed for { every class. A main method is needed for execution to have a place to start. This main method gets executed public static void main (String[ ] args) first. The idea of static will be discussed later. The array of strings parameter is a necessity. A set of French curly braces { } is needed for { main. Output statements: the basic output statement in Java is the [Link]( ) statement. The [Link]( ) line will print what is [Link]("This is a literal between the double quotes" " (called a literal print."); print) and move the printing cursor to the next [Link]("Yea!"); line. [Link]("Go Java!"); The [Link]( ) line will print what is between the double quotes and leave the printing cursor on the same line. Braces are closed to end the program. } }