Monday, August 6, 2018

First java program through command prompt- Write, Compile and Run.

Introduction of Java Programming language.

Java Programming language is referred to as the OOPS(object-oriented programming language)  Concept. Java is created in 1995 by James Gosling, After Some time It's adopted by the Oracle Company. java represents concepts as "objects" with "fields" (which are attributes that describe the object) and "methods" (actions that the object can make). Basically, java called "WRITE ONCE, RUN ANYWHERE"(WORA). This means java is designed to run on any platform that has a Java virtual machine(JVM). java is easy to learn and understand for beginners. This tutorial is an introduction to writing a program in java.

NOTES:- This beginner tutorial is targeted for the Windows environment.

Components are the requirement to run a simple Java Program!

1. Download and install JDK-Package Software on your computer.

You can download the latest Java JDK Package from java's official website. currently, JDK Java SE 14.0.1 is the latest release for the Java SE Platform

Click here to download the latest JAVA JDK.

 2. Notepad for writing java Programs (Source code)

You can use the computer's simple Notepad for writing the source code of any program.

Or You can download a beautiful Notepad to write/edit code. it is named Sublime Text . in this You can write any programming language. it contains more features.

Click here to download Sublime Text editor.

 3. Command Prompt to Compile & Run Java Programs.

When you write a program in notepad, after that just search CMD on your computer. Press windows button> type CMD > press enter. your cmd will open directly.

Writing a "Hello World" Program.

Open your favorite Notepad (a notepad already has given in computer) and you can use Other Notepad also.

public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello world!");

Now save the program in any folder where you want to save, with .java Extensions.

for example, if your Program's class name is "HelloWorld" so you have to save the program, with the same class name.

Ex:- "".(you can see above-given code ).

Compiling Java Programs.

Now this time to compile the written Java Program "" file, Simply open the Command prompt.

> first open cmd (command prompt) Type the following command to change the current directory to the one where the source file is stored:

cd c:\java

Note:-How to open the directory in the command prompt of any program you can watch the given above video.

>And type the following command for compiling the program file in cmd.


After compiled a successful program, one file will be added in your folder (location of the program) with the name of HelloWorld.class. if you got it's the file your program successfully compiled.

To be run Java programs.

Now you are ready to run your first java program, type the following command again in cmd.

java HelloWorld

After the successful run of this program, you will see the following output in your command prompt.


Important Tips:-

1. After writing any commands in command prompt hit enter key for getting the result.

2. Java programming is case sensitive language, you have to use properly upper case and lower case letters.

No comments:

Post a Comment