Op-edRunning Your First Java Core Program With Notepad and CMD

Running Your First Java Core Program With Notepad and CMD

Java programming is widely used by almost maximum amount of developer. It is considered to be one of safest programming languages to code and develop apps and software for personal and commercial purposes. Learning Java programming has a wide range of opportunities in Web Development, Software development and research. Choosing Java as your main programming field has numerous scopes in Information Technology.

In today’s date Java is being used to develop apps for portable devices like mobile, hybrid tabs, etc. Java is also used in various gadgets and vehicles like car, video games etc.

In this article we have included the steps towards running your first Java Program using Notepad and Command Prompt (CMD).

Things you will need

  • Notepad (we recommend Notepad++)
  • Basic knowledge of Command Prompt (CMD)
  • Java Development Kit (JDK)

First check if you have already installed Java using CMD. In order to check if Java is installed or not follow following steps –

  • Press Window Key+R
  • And in run type “CMD” (without quotes)
  • Once cmd promote opens, type “Java” (without quotes) and press enter
  • If it gives following output then it means you have already installed Java on your PC
    Usage: java [-options] class [args...]
               (to execute a class)
       or  java [-options] -jar jarfile [args...]
               (to execute a jar file)
    where options include:
        -d32          use a 32-bit data model if available
        -d64          use a 64-bit data model if available
        -client       to select the "client" VM
        -server       to select the "server" VM
                      The default VM is client.

If it gives different output something like command not recognized, it means you don’t have Java on your PC. Well, you can download and install the latest version of Java from java.com/en/download/

Once you have successfully installed Java on your PC, follow following steps to run your first Java Programme-

  • Go to C:/ drive and create a new folder and name it Codes
  • Open notepad and type following code in it and save it as test.java in C:/Codes/
class test
{
public static void main(String args[])
{
System.out.print("Hello! Isrg Rajan");
}
}
  • Once you have saved the file in the Codes folder as test.java
  • Open command prompt and type cd C:/Codes and pres enter (cd stands for change directory)
  • After changing directory Type javac test.java
  • javac command is used to generate the java class file. In this case it will generate a class file named test.class
  • Once the class file is generated use java test to run your programme
  • In case it results error something like command not reorganized, it means that Java path needs to be set
  • See below on How to Set path in Java-

How to Set Path in Java using CMD?

In order to set path in Java follow following stetps-

  1. Open command prompt and located directory C:\Program Files\Java\jdkx.x.x_xx\bin\ using Windows explorer
  2. Copy the path and in the command promote run following command
  3. set path=[your JDK path] And press enter

That’s all folks!

Isrg Team
Isrg Team
Isrg Team is a member of Digital Pradesh News Networks, a collective of journalists, reporters, writers, editors, lawyers, advocates, professors, and scholars affiliated with the Digital Pradesh News Network.

Latest Updates