Survey
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
BRC
1/28/16
Sample Program 1
File Name: HelloWorld.java
1
2
3
4
5
6
7
public class HelloWorld
{
public static void main (String[] args)
{
System.out.println("Hello World");
}
}
Program Notes:
1. Line numbers are for reference. They are NOT part of the program. Do not include
them when you write a program.
2. Incorrect punctuation, spelling, and case (upper and lower) will result in compile errors.
3. The file name (without extension) must match the public class name in line 1.
4. These symbols come in pairs (missing symbols cause compiler errors):
• Curly braces {}
• Parenthesis ()
• Square brackets []
• Quotes
o Double " (used for more than one letter) see line 5
o Single ‘ (used for only 1 letter) example var1 = ‘a’;
5. Lines can be terminated by semicolons (line 5) or curly braces (line 1 and line 3)
Commands:
Compile: The java compiler is invoked with the javac command. The compiler
translates the program into binary code:
javac HelloWorld.java
If no errors are found the compile command outputs a class file (HelloWorld.class)
Run: The java command runs the output of the compiler (HelloWorld.class). The file
extension (.class) is not included in the java command.
java HelloWorld
Output from this command:
Hello World
Page 1 of 1