In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 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 common mistakes made by beginners in Java?" friends who are interested 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 common mistakes made by novices in Java.
Java errors mainly include two aspects, one is grammatical errors, the other is logic errors.
Syntax error, that is, our code does not conform to the java specification and cannot pass at compile time. Usually, we compile our source program with javac. If there is a syntax error in the code, such as the lack of a semicolon after an expression, the compiler will tell us the error message and the compilation will stop.
Logic errors, that is, we often say Bug, generally there are logic errors in the program can be successfully compiled by the compiler to produce the corresponding bytecode files, that is, class files. However, at the time of implementation, that is, the time of java ourClass, the result is not what we want.
The following problems are very common errors that often occur in some novice code.
1. Java is case-sensitive.
For people who often write VB and Asp programs, it is important to note that the variables money and Money are different.
2. A java source file can contain multiple class, but only one class of public.
Java is an object-oriented programming language, and the compiled bytecode is also a class, namely class. A .java file can contain multiple class, and at compile time, the compiler generates a corresponding class file for each class. It must be noted, however, that a .java file can only contain one public class, and the class name of the public class should be the same as the filename of the .java.
For example, the correct way to write it should be as follows:
A java source file named Test.java with the following contents:
Class A {} class B {} public class Test {}
3. Add. Class when running java program
When you run a java program, you don't need I plus the extension .class, such as
C:\ javac A.java
C:\ java An instead of java A.class
This is because java defaults to finding files with the suffix class, and if you add .class, that is, java A.class, there will be an error:
Exception in thread HelloWorld/class "main" java.lang.NoClassDefFoundError
It means that you can't find this class, because java will write A.class as a package, that is, go to the A directory to find class, but you can't find it, so there will be an error. The error message is the same as the prompt message that your classpath setting is incorrect.
4. The difference between one equal sign and two equal signs
In the Java program, one equal sign is the assignment operator, and two equal signs are the comparison operator. In the program of novice java
Code like this often appears:
Int axi1; int bao2; if (ahumb) System.out.println ("OK")
This is wrong, because what if needs to get is a Boolean value, so the compilation will go wrong.
Because aequb is an assignment operation, which assigns the value of b to an and returns the value to the right of the equal sign, that is, the value of b, for example:
Int astat1; int bread2; int c = (a: + a); System.out.println ("a:" + a); System.out.println ("b:" + b); System.out.println ("c:" + c)
The output is that an is equal to 2, b is equal to 2, and c is also equal to 2, okay?
So, take a look at the following two pieces of code, if you understand, it means you already know the meaning of one equal sign and two equal signs:
Boolean false; boolean baked false.if (averse false) {System.out.println ("axib");} else {System.out.println ("aplastic falseb");}
The result is output "aquib", if replaced by an equal sign
Boolean false; boolea baked false. if (aquib) {System.out.println ("aquib");} else {System.out.println ("aquifolb");}
Then the output is "astatb"
5. The array subscript in java starts with 0
For example, we define an array.
Object [] myArray=new Object [10] indicates that there are 10 elements in the array, starting with myArray [0] and ending with myArray [9]. When using the for loop, you should note that it is correctly written as follows:
For (int iTuno Bandi)
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.