Common grammatical errors in java
Grammar errors are problems that do not comply with grammatical rules, such as If you multiply two strings, of course it is wrong. It is what is commonly called a bad sentence.
The following is a list of common grammatical errors in Java. I hope it will be helpful to Java beginners.
1. The variable may not be initialized
Error message:
Abc.java:9: variable i might not have been initialized System.out.println(i);
Chinese description: Variable i may be used without assigning a value.
Example description:
int i; System.out.println(i);
2. Variables are repeatedly defined
Error message:
Abc.java:9: i is already defined in main(java.lang.String[]) int i = 2;
Chinese description: Variables are repeatedly defined
Example:
int i = 1; int i = 2;
3. Symbol not found:
Test6.java:26: cannot find symbol symbol : variable j location: class Test6 if(j < 0) {
4. Class not found error
Main.java:4: cannot find symbol symbol : class T1 location: class Main T1 a = new T1();
5. Method not found error
Main.java:5: cannot find symbol symbol : method a() location: class T a.a();
6. Class not found
Error message
Test.java:1: class Test1 is public, should be declared in a file named Test1.java public class Test1 {
Chinese description test1 is public and must be declared in the file
Example description
Create a file as Test; open it in the tool and write like this public class Test11 { }; This error will be reported
7 The class cannot be found (the class name is inconsistent with the file name)
NoClassDefFoundError: asa (wrong name: ASA)
8. Under the array Subscript out of bounds
java.lang.ArrayIndexOutOfBoundsException: 1 at Test2.test2(Test2.java:30) at Test2.main(Test2.java:6)
9. String subscript out of bounds
java.lang.StringIndexOutOfBoundsException: String index out of range: 6 at java.lang.String.charAt(String.java:558) at Test2.test3(Test2.java:41) at Test2.main(Test2.java:7)
10. Null pointer
Exception in thread "main" java.lang.NullPointerException at Next.main(Next.java:31)
11 Empty return value
Error message
Test1.java:54: 'void' type not allowed here System.out.println(a5.deleteOnExit());
Chinese description; void return value is not allowed here
Example description If a void method is declared, Then it cannot be output directly
Public static void edit() {} System.out.println(Test.edit());
12 Missing return value
asa.java:8: missing return statement int fan(){} ^ 1 error
13 There is no need to return a value in a method without a return value
asa.java:10: cannot return a value from method whose result type is void return a; ^ 1 error
14. The referenced method has incorrect parameters
Next.java:66: cannot find symbol symbol : method createTempFile(java.lang.String,java.lang.String,java.lang.String) location: class java.io.File File ll = f.createTempFile("let","java","aaa");
15. Missing formal parameters
del() in sms.service.Service cannot be applied to (int)
16.Invalid Method declaration (return type required)
invalid method declaration; return type required public byteValue(){
17. It is required to pass in an array, but a string is passed in
array required, but java.lang.String found ^
18 Constructor method not found
Main.java:4: cannot find symbol symbol : constructor T() location: class T new T();
19. Number formatting exception ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
Exception in thread "main" java.lang.NumberFormatException: null 20. .不兼容的類型 錯(cuò)誤提示Test1.java:41: incompatible types found : java.lang.String[] required: java.io.File[] File [] a3 = a11.list(); 中文說(shuō)明 不兼容的類型
20 Integer number too large Definition value (integer) is too large
21. Non-static methods cannot be referenced in a static context
non-static method cannot be referenced from a static context
22. It is not a static method but is called in a static way (class name. method )
Main.java:5: non-static method fun1() cannot be referenced from a static context Test.fun1();
23 Static access to non-static (variables)
Test.java:5: non-static variable a cannot be referenced from a static context a = 1000;
24. Static access to non-static (methods)
Test.java:6: non-static method fun1() cannot be referenced from a static context fun1(); // 靜態(tài)的不能調(diào)用非靜
25.continue outside of loop (error report that occurs when continue is placed outside the for loop)
26.illegal start of expression expression that violates the rules (Error report that occurs when the second expression in the for loop is placed outside or inside the for loop)
27 asa.java:6: unreachable statement Unreachable statement (statement placed inside
cannot be reached after continue or break, and there cannot be statements after continue and break)
28 break is placed outside the loop statement
asa.java:8: break outside switch or loop break; ^ 1 error
29- Identifier error (identifier is illegal);
asa.java:2: <identifier> expected int %%; ^ 1 error
30. The method body was not found or declared abstract ( Method)
MyAbstract.java:6: missing method body, or declare abstract31. This class is not an abstract class or there is no override. The overridden method fun1() has Abstract methods must be of abstract class
MyAbstract.java:1: MyAdstract is not abstract and does not override abstract method fun1() in MyAdstract
32. Myabstract It belongs to the abstract class and cannot generate objects.
Main.java:6: Myabstract is abstract; cannot be instantiated
33. Interface methods cannot have method bodies
MyInterface.java:2: interface methods cannot have body
34, .It belongs to an abstract class and cannot generate entities
Myabstract is abstract; cannot be instantiated
35. Interface methods cannot have method bodies
interface methods cannot have body
36. Static modification is not allowed here
asa.java:3: modifier static not allowed here public static void main(String []args){ ^ ^
37—Type that cannot be changed (String type cannot be converted to Int type)
asa.java:4: inconvertible types found : java.lang.String required: int int b=(int)a; ^ 1 error
38.possible loss of precision found: long ;required:byte ; var=varlong Possible loss of precision (loss will be caused when a larger integer is converted to a smaller one, but no loss will be caused when a small integer is converted to a larger one.)
39 delimiter Exception
asa.java:5: ';' expected
40 Bracket Exception
asa.java:8: '}' expected
41. The application attempted to create an array with a negative size.
java.lang.NegativeArraySizeException
42. Abnormal operation conditions
java.lang.ArithmeticException: / by zero at Test2.test(Test2.java:16) at Test2.main(Test2.java:5)
43 Abstract methods cannot be modified by final (abstract things of abstract classes must be Inheritance)
44. Abstract methods cannot be modified by private (abstract things in abstract classes must be inherited)
php Chinese website, a large number of free Java introductory tutorials, welcome to learn online!
The above is the detailed content of Common syntax errors in java. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

The settings.json file is located in the user-level or workspace-level path and is used to customize VSCode settings. 1. User-level path: Windows is C:\Users\\AppData\Roaming\Code\User\settings.json, macOS is /Users//Library/ApplicationSupport/Code/User/settings.json, Linux is /home//.config/Code/User/settings.json; 2. Workspace-level path: .vscode/settings in the project root directory

To correctly handle JDBC transactions, you must first turn off the automatic commit mode, then perform multiple operations, and finally commit or rollback according to the results; 1. Call conn.setAutoCommit(false) to start the transaction; 2. Execute multiple SQL operations, such as INSERT and UPDATE; 3. Call conn.commit() if all operations are successful, and call conn.rollback() if an exception occurs to ensure data consistency; at the same time, try-with-resources should be used to manage resources, properly handle exceptions and close connections to avoid connection leakage; in addition, it is recommended to use connection pools and set save points to achieve partial rollback, and keep transactions as short as possible to improve performance.

DependencyInjection(DI)isadesignpatternwhereobjectsreceivedependenciesexternally,promotingloosecouplingandeasiertestingthroughconstructor,setter,orfieldinjection.2.SpringFrameworkusesannotationslike@Component,@Service,and@AutowiredwithJava-basedconfi

Use classes in the java.time package to replace the old Date and Calendar classes; 2. Get the current date and time through LocalDate, LocalDateTime and LocalTime; 3. Create a specific date and time using the of() method; 4. Use the plus/minus method to immutably increase and decrease the time; 5. Use ZonedDateTime and ZoneId to process the time zone; 6. Format and parse date strings through DateTimeFormatter; 7. Use Instant to be compatible with the old date types when necessary; date processing in modern Java should give priority to using java.timeAPI, which provides clear, immutable and linear

TheJVMenablesJava’s"writeonce,runanywhere"capabilitybyexecutingbytecodethroughfourmaincomponents:1.TheClassLoaderSubsystemloads,links,andinitializes.classfilesusingbootstrap,extension,andapplicationclassloaders,ensuringsecureandlazyclassloa

ChromecanopenlocalfileslikeHTMLandPDFsbyusing"Openfile"ordraggingthemintothebrowser;ensuretheaddressstartswithfile:///;2.SecurityrestrictionsblockAJAX,localStorage,andcross-folderaccessonfile://;usealocalserverlikepython-mhttp.server8000tor

Pre-formanceTartuptimeMoryusage, Quarkusandmicronautleadduetocompile-Timeprocessingandgraalvsupport, Withquarkusoftenperforminglightbetterine ServerLess scenarios.2.Thyvelopecosyste,

Networkportsandfirewallsworktogethertoenablecommunicationwhileensuringsecurity.1.Networkportsarevirtualendpointsnumbered0–65535,withwell-knownportslike80(HTTP),443(HTTPS),22(SSH),and25(SMTP)identifyingspecificservices.2.PortsoperateoverTCP(reliable,c
