fastread homefastrread library fastread menu

Java : How to Write, Compile and Run Your First Java Program?

Tutorial by:      Date: 2016-04-19 02:54:35

❰ Previous Next ❱

Before running Java programs you need to install and setup
java. For installation guide read: Java Installation: Downloading, Installing and Setting Path

How to write and run Java programs?

  • Open notepad and write below program.

 

class demo

{

                public
static void main(String…S)

                {

                                System.out.println(“Java
Programming”);

                }

}

  • Now save the file with name demo.java on desktop. Here you can replace demo with any other name that you want.
  • Then open command prompt (cmd) and type cd desktop and press enter to change current directory to desktop.
    We changed directory because our program is saved on desktop.
  • To compile java program type javac demo.java and hit enter. Type java demo to run the program. Remember that here we have to compile
    with program name and execute with class name that we have used in program. The
    java program name and class name can be different.

 

Understand the Program

 

 

System: Get reference id of the device on
which program is running. Here the device is cmd.

out: Store the reference id of device.

println: Throw the output on device.

 

A.java

A.java

A.java

   

class A

 {

}

class A

{

public static void main()

{

}

}

compile

Yes

Yes

Yes

.class file

Not created

Created

Created

execute

No

No

Yes

 

❰ Previous Next ❱


Java

Submit Your Thought, Tutorial, Articls etc.

Submit Your Information India's Number one online promotion website