Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to write the code of Java output HelloWorld

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the knowledge of "how to write the code of Java output HelloWorld". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Stepping through the door of JDK development environment installation, we have officially entered the world of Java. Java is an object-oriented programming language, not only absorbs various points of the C++ language, but also abandons the concepts of multiple inheritance, pointers, which are difficult to understand in C++, so it has two features of powerful and easy to use. Its syntax is simpler than c Java +, its biggest advantage is high portability, once written, executed everywhere, today we will practice the first section of code into the line.

Public class HelloWorld {/ / HelloWorld is called class name public static void main (String [] args) {/ / void stands for no return value System.out.println ("HelloWorld") / / print what is inside parentheses and newline-similar to printf function in c language, "HelloWorld" enclosed by double quotation marks is called string type, * Note: there is no string type in c language *} / / the braces inside are called method body} / / the braces outside are called class body, the composition of class body consists of method body and field, the class body exists in source file, and the method exists in class. Statement exists in method

You need to pay attention when writing code

1: in a java file, only one class can be modified by the public keyword, in other words, there can be only one public class

2: the class name modified by the public keyword needs to be the same as the file name (the file name cannot be numbers and Chinese characters). If there is no class modified by public, then the file name can be named at will.

3 programming specification suggestion: the left parenthesis is immediately following the current line, and it is better to leave one space blank.

Four types of names are in the form of a big hump, the big hump-if there is only one word, the initial letter is capitalized, if there are two words, both initials should be capitalized

Main in 5:Java can only be written in this way, which is different from c language.

When the program is finished, all we have to do is compile and run, compile and run the code because I use the code written in notepad++ notepad, so I use the DOC interface to run it here.

First create a new folder, create a new text document in the folder, then rename the text document to the class name modified by the public keyword in the program we wrote, and change the suffix to .java

Note: when modifying the file name suffix if the interface does not appear above, or after compilation when the DOC interface shows that the file name suffix is hidden, we need to unhide, Baidu has a very detailed method file name modification is completed, we have to use notepad++ notepad to open it to write our procedures, at this time with the computer's own notepad can not be opened. Select the file, right-click the mouse, there will be an open option, select notepad++

At this point, write our first Java program on this interface, and then save it with ctrl+s. Note: save the notepad every time you finish writing the program, and then recompile it.

At this point, the source file HelloWorld.java is on disk. We press and hold the windows+r key and enter cmd to enter the DOC interface.

Note: disk c is opened by default at this time. If the source code is saved on another disk, you can enter another disk directly. Enter a cd+ space in the DOC interface, then copy and paste the path where the source code is located, and enter.

Then enter the javac file name .java and enter, which means that the program has been compiled, and the source file generates the HelloWorld.class-- bytecode file by default.

Note: bytecode file-.class file, a class corresponds to a bytecode file, so it is easy to use, if you need HelloWorld, then load the corresponding bytecode file, in java, which class is used, load the class, bytecode file opened with notepad++ is a pile of garbled, it is a binary file, it is to let the machine to identify this time in the just DOC window to re-enter java and file name. On behalf of the completion of the program, we will see that the DOC interface outputs HelloWorld, which means that the program has been compiled and run successfully.

Solution: at compile time: javac HelloWorld.java-encoding utf-8

In this simplest java program compilation, we can see that both javac and java belong to the JDK command. Javac is the compiler of java. The compile command is javac, and the function of the run command, that is, the java,javac command, is to let the Java compiler get the Java application HelloWorld.java. And compile it into a bytecode file that conforms to the java virtual machine specification, that is, a .class file. It is the executable file on the virtual machine, and the virtual machine translates the corresponding bytecode file into the corresponding machine code of the operating system. Java programs finally run to JVM-Java Viture machine (Java virtual machine), which can load .class files into JVM to run. In other words, javac converts the source code of java into bytecode, forms a .class file, and then runs it on a virtual machine. Idea eclipse and others can be regarded as java virtual machines.

So now we know three nouns.

JDK:JAVA development tools

JRE:Java operating environment

JVM:java virtual machine

JDK contains both JRE,JRE and JVM by default (core)

So what is a virtual machine? A virtual machine is equivalent to a computer, and all files have to go to the virtual machine. Cross-platform means that no matter which system, as long as there is JDK, there is JVM. You can compile and run java programs.

This is the end of the content of "how to write Java output HelloWorld code". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report