Creating the Goodbye Cruel World application - Java
Since its creation about 16 years ago, Java has become ubiquitous. Developers appreciate its "write once, run anywhere" philosophy. If you want to start making use of Java and its many benefits, keep reading.
To start, you will need to create a source file. Left-click on your Start menu and choose All Programs>Accessories>Notepad. When your document opens, type the following code:
Note: All code is case-sensitive, so be sure to type it in exactly as you see it.
/* * This application will print the words “Goodbye Cruel World” across * your monitor. Also note that these are just comments in your code * for other programmers, and is invisible to the compiler. */
class GoodbyeCruelWorldApp { public static void main(String[] args) { System.out.println("Goodbye Cruel World!"); // Displays the string. } }
Save the notepad file to your C: drive (it typically does not matter where you store the file. But in this case we will use your C: drive) under the name "GoodbyeCruelWorldApp.java", being sure to include the quotation marks. Then close your saved file.
Next we must change your source file into a .class File. To do this, left-click on your Start menu and choose the Run command. Type cmd into the pop-up box and press Enter. This will load the Command window, shown below:
In order to compile your Source File, you must change the directory to where your file is located. In the above example the prompt is set to your C: Drive. To change the directory, type cd C: and press Enter.
Next, to display the files within your C: Drive, type dir
You are now able to compile. In the prompt line type javac GoodbyeCruelWorldApp.java and press Enter.
If you type in dir again, you will see the new file, GoodbyeCruelWorldApp.class.
You are now ready to run your first program!
Running Your First Program
Without changing your directory, type java GoodbyeCruelWorldApp at the prompt.
This should display the text: “GoodbyeCruelWorld!” in the prompt window.