In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "how to master java hello world program". In the operation process of actual cases, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!
A program is just a collection of lines of code. It looks like this:
For beginners,"hello world" programs are always unavoidable; learning Java programming is no exception. To be honest, I had a hard time learning these few lines of code in my freshman year of college (I was nineteen)-it took me almost a month to digest the "hello world" program (which is true). I remember that the teacher at that time very "kindly" asked us students to type this code on the notepad, and to run this Mini programs on the command line of the console to print "hello world" on the screen.
It was extremely difficult! I was this close to losing my confidence in some other major with these lines of code. Fortunately, I persevered, and for now, IT is a promising industry, Java is still at the top of the programming language rankings, and I can rely on Java senior development engineer status in an increasingly difficult environment to survive. Seriously, there are several things I don't understand about the "hello world" program:
①. Why do I need public in front of class?
②. Why does the main method have arguments String[] args? It doesn't seem to be working at all.
③. Why does main have to be static void?
Looking at these questions, are you also eager to know why? Mr. Hu Shi, the leader of the New Culture Movement, once said that "the difference between man and beast lies in this 'why'." Although this does not sound so implicit, it is a positive attitude. In learning and life, asking "why" is very helpful for our growth. I believe that, and you're willing to raise your hand.
So now, let me answer the above three questions (please give me zero points for bad answers):
1) public before class is not required; there can only be one public class in a Java file, and the class name (Test) must be consistent with the file name (Test.java).
2) The argument to the main method is a String array, which is conventionally written as String[] args; although the args parameter is not used in the current "hello world" program, the Java compiler requires that the main method must be so (just like Li Bai's father named him "Li Bai", so Li Bai can only be called "Li Bai"); if you want to use the args parameter in the program, you can type it on the command line when running the Java program. To demonstrate how to use the args parameter, let's tweak the above code slightly ("hello world" followed by a space and the first value of the args parameter):
The modified "hello world" program compiles and runs on the command line as follows:
3) static means that the main method is static; static methods can be passed through the "class name. Method name. How to understand this sentence? Let's look at the following code:
Usually, method internals call the method itself (Test.main(args)) as "class name. method name) creates an infinite loop, but we use a static variable i to control the number of loops, up to five times.
4) void means that the main method does not return a result; since the main method is the main method, as the entry of the program, it naturally does not need to return a result, otherwise who will return the result to see? As if you were the commander, you obviously didn't have to report to the commander or division commander.
"Java hello world program how to master" the content of the introduction here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.