Over 3 years we help companies reach their financial and branding goals. Parenthesys Technologies is a values-driven technology agency dedicated to digital transformation, eCommerce and product engineering.

Contacts

Mumbai, Maharashtra, India

+91 8779776685


Follow Us

Java Learning

How to write first Java code and Run using Command Prompt?

It is a very easy and 2 minutes read to learn how to write first Java code and Run using Command Prompt in your machine. Firstly, you will need two prerequisites installed in your computer:

  1. Java SE Development Kit: To access all Java features.
  2. Simple Text Editor: We will use “Windows Notepad” to write and save Java code in .java extension.

Secondly, we will use following three steps to learn how to write your first java program and run:

  • Step 1: Write Java program in Notepad and Save as .java extension.
  • Step 2: Compile Java program in Command Prompt
  • Step 3: Run Java program in Command Prompt
Step 1. Write your first Java program in Notepad:

You need to copy and paste below code in the Notepad and save as .java extension.

class first_program {
   public static void main(String args[]){
      System.out.println("Welcome to Parenthesys Technologies");
   }
}
Step 2. Compile Java program in Command Prompt:

Before running the Java program, you need to compile it. To know how to compile and run Java program, open Command Prompt and you have to locate the file saved in your computer and use javac directory_name command. Suppose, you have saved first_program.java file in your Desktop folder then use:

cd Desktop
javac first_program.java

javac stands for Java Compile. You have successfully compiled the Java program. Now, the last step is to Run it.

Step 3. Run Java program in Command Prompt:

Since, we have already compiled the Java program using javac command. So, to Run the java code we will use java command. Simply, put the below code (for first_program.java) and enter:

java first_program.java

You should see below Output after you run the program:

Welcome to Parenthesys Technologies

Lastly, this is how it should look in the command prompt:

how-to-write-first-java-code

So, you have learnt “How to write the first Java code without any IDE“. Now, We will go ahead and use this method to write more advanced Java codes in the coming tutorial.

This article is written by Engineers from Parenthesys Technologies. Follow us on Linkedin for Company News, Jobs and Latest Article on technology.

Leave a comment

Your email address will not be published. Required fields are marked *