Java Tutorial

Basic Concepts

Object Oriented Concepts

Coming Tutorials

>Home>Java Tutorial>Write Simple Welcome Java Program in CMD

Java Tutorial

Basic Concepts

Object Oriented Concepts

Coming Tutorials



First Simple Hello Java Program

It is the time to write your first simple welcome java program, to develop the java programs without IDEs(Integrated Development Environment) like Netbeans, Eclipse, etc. you will require the following tools. If you want to develop a java program using an IDEs the visit writing a Java program in Netbeans and Java program in Eclipse IDE

Java Environment Setup / Required Tools to Develop a Java Program

1. Text Editor

Any text editor like notepad, notepad++, Sublime Text, etc. is enough to write the java source code.

I will recommend the Sublime Text 3 because it has colourful theme, differentiate the variables, methods, and class by using separate colours.

You can download here the Sublime Text 3 and then install it that will not take more time.

2. JDK- Java Development Kit

You need to install the Java JDK to develop the Java program. Download the latest version of JDK here.

The Java Virtual Machine Specification is a document that formally describes or provides some rules for implementation of the Java Virtual Machine. For JVM there is a single Java Virtual Machine Specification which ensures that all implementations are interoperable or relevant.

Setting Path in Environment Variable

After installing the JDK, copy the Java path C:\Program Files\Java\jdk1.8.0_60\bin (this may be different in case of depending on JDK version and computer architecture).

Following are the steps required to configure permenent path.

Step -1: Right click on My Computer --> select properties.


Step -2: Click on Advanced System Setting.


Step-3: Click on Environment Variables.



Step-4: Click on "New" button if there is no path variable available.

If there already is a path variable then, select the path variable and click on "Edit" button.



Step 5: Enter “path” in variable name and paste copied java bin folder path into variable value textfield.

If there already is a path variable value then, at the first (before existing variable value) paste the java path ended with a semicolon ‘;’ if not available then simply paste the java path.

Note: Here, semicolon ‘;’ works as a value separator. Therefore, if there are multiple values then separate them with semicolons.



Step 6: Click OK from all the opened popup boxes.


All the required environmental setup is done, now open the command prompt(you should open a new command prompt after setting the path) and type “javac” and press enter key, then you should see a big list of options it means you have successfully set the path. But, if you get “javac is not a internal or external command” then you may have to repeat the same steps by checking correct JDK location.


Writing First Simple Welcome Java Program


class HelloJava
{
public static void main(String[] args)
{
System.out.println("Welcome to Java - Topper Skills");
   }
  }

For explanation of the above program refer class in java and main method of java.

Save the file to your working directory(say D:\javaprog) with .java extension, in this case firstjava.java.

Note: You can take any name as file name with .java extension if and only if you do not have a public class. If you made the “HelloJava” class public then your source file name should be “HelloJava.java”.


How to run Java program through command prompt (CMD)?

Step 1: Open the command prompt.

Step 2: Change directory location to your working directory(D:javaprog).

To change the directory type D: and press enter key, now type cd javaprog and press enter key. You must see D:\javaprog> on the command prompt.

Step 3: Compile the source code.

javac firstjava.java press enter.

Step 4: Execute byte code.

java HelloJava press enter key.



Share the article to help your friends