国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home Java JavaBase Common syntax errors in java

Common syntax errors in java

Nov 15, 2019 am 11:03 AM
java Grammatical errors

Common syntax errors in java

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: &#39;void&#39; 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 abstract

31. 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: &#39;;&#39; expected

40 Bracket Exception

asa.java:8: &#39;}&#39; 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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1502
276
How to handle transactions in Java with JDBC? How to handle transactions in Java with JDBC? Aug 02, 2025 pm 12:29 PM

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.

Understanding the Java Virtual Machine (JVM) Internals Understanding the Java Virtual Machine (JVM) Internals Aug 01, 2025 am 06:31 AM

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

How to work with Calendar in Java? How to work with Calendar in Java? Aug 02, 2025 am 02:38 AM

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

Comparing Java Frameworks: Spring Boot vs Quarkus vs Micronaut Comparing Java Frameworks: Spring Boot vs Quarkus vs Micronaut Aug 04, 2025 pm 12:48 PM

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

Understanding Network Ports and Firewalls Understanding Network Ports and Firewalls Aug 01, 2025 am 06:40 AM

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

How does garbage collection work in Java? How does garbage collection work in Java? Aug 02, 2025 pm 01:55 PM

Java's garbage collection (GC) is a mechanism that automatically manages memory, which reduces the risk of memory leakage by reclaiming unreachable objects. 1.GC judges the accessibility of the object from the root object (such as stack variables, active threads, static fields, etc.), and unreachable objects are marked as garbage. 2. Based on the mark-clearing algorithm, mark all reachable objects and clear unmarked objects. 3. Adopt a generational collection strategy: the new generation (Eden, S0, S1) frequently executes MinorGC; the elderly performs less but takes longer to perform MajorGC; Metaspace stores class metadata. 4. JVM provides a variety of GC devices: SerialGC is suitable for small applications; ParallelGC improves throughput; CMS reduces

Comparing Java Build Tools: Maven vs. Gradle Comparing Java Build Tools: Maven vs. Gradle Aug 03, 2025 pm 01:36 PM

Gradleisthebetterchoiceformostnewprojectsduetoitssuperiorflexibility,performance,andmoderntoolingsupport.1.Gradle’sGroovy/KotlinDSLismoreconciseandexpressivethanMaven’sverboseXML.2.GradleoutperformsMaveninbuildspeedwithincrementalcompilation,buildcac

go by example defer statement explained go by example defer statement explained Aug 02, 2025 am 06:26 AM

defer is used to perform specified operations before the function returns, such as cleaning resources; parameters are evaluated immediately when defer, and the functions are executed in the order of last-in-first-out (LIFO); 1. Multiple defers are executed in reverse order of declarations; 2. Commonly used for secure cleaning such as file closing; 3. The named return value can be modified; 4. It will be executed even if panic occurs, suitable for recovery; 5. Avoid abuse of defer in loops to prevent resource leakage; correct use can improve code security and readability.

See all articles