Skip to main content

How to Run Java Program in CMD Using Notepad



In this section, we will learn how to save, compile, and run (execute) a Java program in Command Prompt (CMD) using notepad.
Before running (execute) a Java program, ensure that Java is installed in the system and the path is properly set. If the path is not properly set, we cannot run the Java program.
We must follow the steps given below to run a Java program.
Open the notepad and write a Java program into it.
Save the Java program by using the class name followed by .java extension.
Open the CMD, type the commands and run the Java program.
Let's create a Java program and run it using the Command Prompt. 

Note📝: We are considering that Java is properly installed and the path is properly set in your system.



 

Step 1: Open the notepad by pressing the Windows Key + R, type notepad and press enter key, or click on the Ok button. It opens the notepad. 

Step 2: Write a Java program that you want to compile and run. We have written the following code in the notepad.


CharArrayToStringExample.java


public class CharArrayToStringExample  
{  
public static void main(String args[])  
{  
//character array  
char[] ch = {'w', 'e', 'l', 'c', 'o', 'm', 'e', ' ' , 't', 'o', ' ', 'J', 'a', 'v', 'a', 't', 'p', 'o', 'i', 'n', 't'};  
//constructor of the String class that parses char array as a parameter  
String string = new String(ch);  
//prints the string  
System.out.println(string);  
}  
}  


Follow us on Instagram

Step 3: To save a Java program press Ctrl + S key and provide the file name. Remember that the file name must be the same as the class name followed by the .java extension.

If you are writing the same Java program (as above) save it by providing the file name CharArrayToStringExample.java press enter key or click on the Save button.

We have saved the above program at the location C:\demo.
Now, we have created and saved the Java program. In the next step, we will compile and run the Java program.

Step 4: To compile and run a Java program, open the Command Prompt by pressing Windows Key + R, type cmd and press enter key or click on the Ok button. It opens the Command Prompt window.


Step 5: In the Command Prompt window, write the following commands.

cd\  
cd demo  

Now we are inside the demo folder where we have saved the Java program.

Step 6: To compile the Java program type the following command:

javac CharArrayToStringExample.java
When we compile a Java program without any error, it creates a .class file with the same name as the file name at the same location (where the program is saved).

Step 7: To run the Java program, type the following command.
Follow us on TikTok

java CharArrayToStringExample

Note that we have not written .java after the file name.


In the above image, welcome to Javatpoint is the output of the program.
║▌║▌║▌║▌





Popular posts from this blog

How to bypass Android Lock Screen Without Reset

 Can you bypass Android lock screen without losing? Wondering how to bypass Android lock screen without factory reset? This post is going to share you three ways of bypassing Android lock screen without data lossing. Let’s check it.  Click here to claim free gift 🧧🎁 card for free. Just a minute of ya time Nowadays, to better protect personal privacy, pay security, or something like that, Android phones enable users to set passwords or fingerprints to lock their devices. However, you may fail to unlock your Android phone if you forgot your lock password, or you can not open the old phone or broken phone. Obviously, you can unlock Android lock screen by hard resetting your phone, but you should know that a full factory reset on devices means wiping it clean of any data. Simply means that it will bring your Android phone to the same condition as it arrived in the box. To avoid losing data, it would be nice if you can bypass Android lock screen without a factory reset. So, you ...

How to make a file invisible by encrypting it.

How to make a file invisible by encrypting it Use the service https://7r6.com/aNLY5d if you are concerned that a file you send might be intercepted and its contents discovered. It transforms the information in the text into a difficult-to-decipher code. You must enter a password to view the file's actual contents. Use of the service: 1. Go to the website at https://7r6.com/aNLY5d (to get the site you have to bypass this site. You will be given a button in green color caption GET LINK) Select the encrypted file by clicking "Browse Files" in step two. 3. Type a password in the box below or create a random one. 4. To encrypt and download an encrypted file, click "Encrypt," then "Encrypted file." 5. Forward the file to your pal, He has to leave . He must visit the same website, get our file, decrypt it using the password we came up with, click "Decrypt," then download it again.

Earn money from Telegram by using EarningGram bot.

EarningGram is the best Telegram bot that allows you to earn money in Telegram. With EarningGram, You can earn as much as 5% of your Telegram referrals' earnings! EarningGram Bot helps you make money by doing simple tasks on your Telegram app. Whatever you want, when you want it. It's fast, easy to use and free. WHY TO ACCUMULATE MORE  Create a Telegram Channel and Earn money every time you send a message. EarningGram bot will automate your Instagram, Facebook, Twitter accounts and also Telegram. Facebook, can be a means of promoting affiliate programs.          GETTING STARTED If you don't have the telegram app download from play store. Click here to lead you to the bot. Tap on the start and do all necessary task you are been asked. You will be asked to submit your Coinbase email. That's the email you used to create your Coinbase account. If you don't have one create one ASAP!!! Create here   Accumulate more by sending your referral link. Minimum pay...