Visit www.myprogramminglab.com to complete many of these Programming Challenges online and get instant feedback.
1. Your First Java Program
This assignment will help you get acquainted with your Java development software. Here is the Java program you will enter:
// This is my first Java program.
public class MyFirstProgram
{
public static void main(String[] args)
{
System.out.println(“Hello World!”);
}
}
If You Are Using the JDK at the Command Prompt:
1 Use a text editor to type the source code exactly as it is shown. Be sure to place all the punctuation characters and be careful to match the case of the letters as they are shown. Save it to a file named MyFirstProgram.java.
2. After saving the program, go to your operating system’s command prompt and change your current directory or folder to the one that contains the Java program you just created. Then use the following command to compile the program:
javac MyFirstProgram.java
If you typed the contents of the file exactly as shown, you shouldn’t have any syntax errors. If you see error messages, open the file in the editor and compare your code to that shown. Correct any mistakes you have made, save the file, and run the compiler again. If you see no error messages, the file was successfully compiled.
3. Next, enter the following command to run the program:
java MyFirstProgram
Be sure to use the capitalization of MyFirstProgram exactly as it is shown here. You should see the message “Hello World!” displayed on the screen.