In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article focuses on "what are the most common errors in JAVA at compile time". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what are the most common mistakes in JAVA when compiling?"
What are the most common errors in JAVA at compile time
We will use the following code as a Java sample class as a discussion:
PublicclassGame {
Publicstaticvoidmain (Stringargs []) {
System.out.println ("IfIchoosePaper,")
System.out.println ("AndyouchooseScissors,")
System.out.println ("ThenIwin,andyoulose!")
}
}
Incorrect naming of the Java file-the name of the Java file must exactly match the relevant public class in the code. Therefore, if your code contains a public class "Game", the Java file must be named "Game.Java", not "game.Java", or "GAME.Java", or "MyGame.Java". The name of the file and the name of the public class must match exactly in spelling and case.
Case of code errors-Java is case-sensitive, so "public" is different from "Public" or "puBliC". Novices to Java tend to capitalize their initials, and vice versa, and the code they write fails to compile due to case errors. To further complicate this problem, compile-time error messages are often hidden and unhelpful due to uppercase problems. For example, if you capitalize the first letter of the declaration "publicstaticandvoid" in the main method, you will get the following error message saying that a semicolon is needed, which is really not the root of the problem:
C:\ _ jdk1.7\ bin > JavacGame.Java
Game.Java:3:error:';'expected
PublicStaticVoidmain (Stringargs []) {
1error
What are the most common errors in JAVA at compile time
Mismatched parentheses-you can see every open bracket in your code. It may be a square bracket, parenthesis, or parenthesis, and you need a matching closed bracket. Sometimes, a programmer forgets to close the parentheses of a method, or they remember to close the parentheses of a method, but forget to close the parentheses of the class. No matter how it happens, if the parentheses do not match, you will always get a compile-time error.
For example, the last large parenthesis of a Java class is not closed, and an attempt to compile the code will result in the following compile-time error:
C:\ _ jdk1.7\ bin > JavacGame.Java
Game.Java:11:error:reachedendoffilewhileparsing
}
1error
Personally, whenever I create a new method or class, after typing in the opening parenthesis, I always hit some carriage returns and then add a closing parenthesis. I only start coding the class body or method if the parentheses match. In this way, your parentheses will always match the state, so you don't have to worry about closing parentheses at some point in the future when writing class or method code.
Omitting semicolons-another common coding error in Java that people are increasingly familiar with is the omission of required semicolons. As a rule, each statement must end with a semicolon. Unfortunately, this rule can sometimes be as confusing as it does, especially if you have one that is difficult to figure out whether it is a sentence or not.
For example, in the body of a method, all "system.out.print" calls end with a semicolon. If we forget to add a semicolon to "system.out" in a method body, we will get a compile-time error message, like this:
C:\ _ jdk1.7\ bin > JavacGame.Java
Game.Java:7:error:';'expected
System.out.println ("ThenIwinandyoulose!")
1error
Part of the confusion is that not every line of code you write in Java is a statement. For example, a class declaration is not treated as a statement, so it does not follow a semicolon. Similarly, a method declaration is not treated as a statement, so it does not follow a semicolon. It takes some practice to easily tell which is a statement and which is not, but rest assured that if you do have a statement, it must be followed by a semicolon, or the compiler will start to report an error.
Over time, nuances of any programming language will eventually become commonplace, and Java's well-known requests are no different from other programming languages on the market. If you are new to Java, remember these four tips. If you encounter a compile-time error, see if it is caused by the naming of the Java file, the case of words and letters in the code, mismatched parentheses and semicolons or missing semicolons. Keeping these four problem points in your mind will help you solve Java code troubleshooting problems and hope to ease some of the frustrations of learning the Java programming language.
At this point, I believe that you have a deeper understanding of "what are the most common errors in JAVA at compile time?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.