Write and run Java code on the computer for the first time
After you've installed Java and set up a path on your computer, you need to know how to run a simple Java code on your computer. In this article, we will try to write the first Java program, as well as the commands to run this program in cmd.
Be sure to read and follow the instructions in this article so that the process of running the code won't fail: Download and install Java on the computer.
The first Java program
Yes, the most classic code when learning every major programming language is Hello or Hello World.
public class JavaFirst { /* Đây là chương trình Java đầu tiên của tôi. * Nó sẽ in 'Hello World' ra màn hình */ public static void main ( String [] args ) { System . out . println ( "Hello World by Quantrimang" ); // in Hello World } }
Do not wonder if you do not understand anything, just copy the one, then it will be fine.
Run Java code on the computer
Now see how to save the file, compile and run the Java program, make sure you follow the steps below:
- Make sure you have installed Java JDK and tweaked PATH on the computer.
- Open Notepad and paste the code above.
- Save the file as: JavaFirst.java
- Open cmd and go to the directory where you saved the JavaFirst.java file, assuming cmd is in drive C, you save the file in folder E: Java, enter the following command to switch to the folder E: Java.
cd d / E: Java
5. To compile the Java code you entered:
javac JavaFirst.java
Then press Enter. If there are no errors in the code, cmd will take you to the new line. Now if you only install Java JDK without setting PATH, you will receive an error message. If the file name you set is different (other than the class name), you will receive an error message.
6. To run the program, enter the following command:
java JavaFirst
Hello World by TipsMake.com will appear on the screen
The whole process is as follows:
In the next article we will learn about Object and Class in Java.
You should read it
May be interested
- 75 great user interface design ideas you need to know - Part 2after studying the article 75 great user interface design ideas you need to know - part 1, tipsmake.com continues to provide you with a list of 75 great user interface design ideas you need. know - part 2 helps to optimize the user interface in the most effective way. invite you to consult!
- Which operating system should I choose to use when programming?windows, macosx, linux operating systems are good for programmers.
- 5 interesting features about Java 9 you may not know yetlet's tipsmake.com learn 5 interesting features about java 9 you may not know in the article below!
- Learn Ruby programming from 0let tipsmake.com learn about how to learn ruby programming language from 0 in this article!
- 6 useful tips from 11-year experienced programmershow to become a good programmer? let's tipsmake.com learn 6 useful tips from 11-year programmers experience in this article!
- How to become an Android application developer?daily-used mobile applications have changed in the way we conduct business, communicate, entertain and learn new things. invite you with tipsmake.com refer to the article how to become an android application developer below!