Creating your First Java Program
There are three basic steps to create and run your program. They are :-
1. Write the code
2. Compile your program
3. Run the program
Here's a sample :
1. Write the code
For this step, you will require a simple text editor, like notepad, notepad++ (for windows users), TextWrangler (for Mac users), gedit (for Linux users).
Write your code using these text editors, and save the file name with the extension java (filename.java). Remember, the filename will be the same as the name of the main class.
Here's an example of a Hello World Program :
public class HelloWorld
{
public static void main(String args[])
{
System.out.println("Hello \n World");
}
}
2. Compile the code
Open PowerShell (in Windows), or Terminal(for Linux and Mac). Go to the directory where your file is saved using the cd command, and type:
where FileName is the name of your file. Your code is now being compiled. If there are any errors in your code, they will be displayed, else a blinking cursor is displayed.
3. Run the code
Type:
Your program will now run. Comment below if you have any doubts.
Happy Coding!
Thursday, 20 November 2014