Environment setup on windows machine
You can download the Windows version JDK (http://www.oracle.com/technetwork/java/javase/downloads/index.html).
Download and install
Environment variable
- Select Computer from the start menu
- Choose System Properties from the context menu
- Click Advanced system settings > Advanced tab
- Click on Environment Variables, under System Variables, find PATH, and click on it.
- In the Edit windows, modify PATH by adding the location of the class to the value for PATH. If you do not have the item PATH, you may select to add a new variable and add PATH as the name and the location of the class as the value.
- Reopen Command prompt window, and run your java code.
Creating Your First Application
Your first application,
HelloWorldApp
, will simply display the greeting "Hello world!". To create this program, you will:Create a Source File
Open Notepad editor new document type in the following code:
class HelloWorldApp { public static void main(String[] args) { System.out.println("Hello World!"); // Display the string. } }
Save the code in a file with the name
HelloWorldApp.java
. To do this in Notepad, first choose the File > Save As menu item. Then, in the Save As dialog box:- Using the Save in combo box, specify the folder (directory) where you'll save your file. In this example, the directory is
java
on theC
drive. - In the File name text field, type
"HelloWorldApp.java"
, including the quotation marks. - From the Save as type combo box, choose Text Documents (*.txt).
- In the Encoding combo box, leave the encoding as ANSI.
Now click Save, and exit Notepad.
Compile the Source File into a .class File
Open command prompt.
Go to project folder where your program is saved. c:/java/HelloWorldApp.java
Compile java program with "javac" compiler.
e.g: javac HelloWorldApp.java
HelloWorldApp.class
. At the prompt, type dir
to see the new file that was generated, as shown in the following figure.Now that you have a
.class
file, you can run your program.Run the Program
In the same directory, enter the following command at the prompt:
java HelloWorldApp
0 Comments