first program in java

First Program in Java

Java Programming Tutorials
Share to others

In here we are going to test out first program in java.

The things you need are,

  • The Java SE Development Kit

If you’re still struggling with installing Java, please check here.

  • A Text Editor

In here we going to use simple text editor which is free in all operating systems. Or else we can use IDEs, but if you’re a completely beginner, we recommend you to use normal text editor until you get clear idea about the Java programming. If not, you might face difficulties in later.

Follow below steps to complete your first program

Create source code

  1. Open notepad, you can simply search on start menu.
open notepad in widows

2. Create source code.

  • Declare class name as you like, in here I get as Hello.
  • Next, Declare the main method public static void main(String []arg)
  • Then, type what you want to print or display on when program executed. In here we get as ‘Hello World’.
Hello world in notepad
class Hello
	public static void main(String[] args)
		System.out.println("Hello World");


  • Class name always begins with capital letter, use camel case at all the time Eg: FirstProgram.
  • After declare the class and the main method use open and close brackets {}. Because, once you type a long code with hundreds of lines, it is very much easy to identify to single code snippet.  
  • Save the program in your directory. Make sure to change the file extension to .java, Eg: And give save type as All Files.

Convert source code to byte code

3. Go to your directory and click right mouse button while pressing Shift. (Shift + Right mouse button)

Next, select Open Powershell window here as marked in figure. Then, type javac to compile the code.

locate powershell in a folder
compile the code using powershell

4. After compile the code check your directory weather new file created or not. If there is another file as Hello.class, your compile process complete and ready to execute the first program.

class file of a java program

Execute the program

5. Again, head back to powershell window and type java Hello to execute the file.

java Hello
execute the java program

So, if you are complete above steps you’r first java program is executed successfully.

Hope you learnt something here, So, let meet in another tutorial.

Share to others