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);
Copy after login

Chinese description: Variable i may be used without assigning a value.

Example description:

int i;
System.out.println(i);
Copy after login

2. Variables are repeatedly defined

Error message:

Abc.java:9: i is already defined in main(java.lang.String[])
                int i = 2;
Copy after login

Chinese description: Variables are repeatedly defined

Example:

 int i = 1;
 int i = 2;
Copy after login

3. Symbol not found:

Test6.java:26: cannot find symbol
symbol  : variable j
location: class Test6
   if(j < 0) {
Copy after login

4. Class not found error

Main.java:4: cannot find symbol
symbol  : class T1
location: class Main
  T1 a = new T1();
Copy after login

5. Method not found error

Main.java:5: cannot find symbol
symbol  : method a()
location: class T
  a.a();
Copy after login

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 {
Copy after login

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)
Copy after login

8. Under the array Subscript out of bounds

java.lang.ArrayIndexOutOfBoundsException: 1
        at Test2.test2(Test2.java:30)
        at Test2.main(Test2.java:6)
Copy after login

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)
Copy after login

10. Null pointer

Exception in thread "main" java.lang.NullPointerException
        at Next.main(Next.java:31)
Copy after login

11 Empty return value

Error message

 Test1.java:54: &#39;void&#39; type not allowed here
   System.out.println(a5.deleteOnExit());
Copy after login

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());
Copy after login

12 Missing return value

asa.java:8: missing return statement
 int fan(){}
                  ^
1 error
Copy after login

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
Copy after login

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");
Copy after login

15. Missing formal parameters

 del() in sms.service.Service cannot be applied to (int)
Copy after login

16.Invalid Method declaration (return type required)

invalid method declaration; return type required
        public byteValue(){
Copy after login

17. It is required to pass in an array, but a string is passed in

array required, but java.lang.String found
                    ^
Copy after login

18 Constructor method not found

Main.java:4: cannot find symbol
symbol  : constructor T()
location: class T
  new T();
Copy after login

19. Number formatting exception                                                                                        

Exception in thread "main" java.lang.NumberFormatException: null 20. .不兼容的类型
错误提示Test1.java:41: incompatible types
found   : java.lang.String[]
required: java.io.File[]
 File [] a3 = a11.list();
中文说明 不兼容的类型
Copy after login

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
Copy after login

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();
Copy after login

23 Static access to non-static (variables)

Test.java:5: non-static variable a cannot be referenced from a static context
                a = 1000;
Copy after login

24. Static access to non-static (methods)

Test.java:6: non-static method fun1() cannot be referenced from a static context
            fun1();                    // 静态的不能调用非静
Copy after login

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
Copy after login

29- Identifier error (identifier is illegal);

asa.java:2: <identifier> expected
 int %%;
            ^
1 error
Copy after login

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
Copy after login

32. Myabstract It belongs to the abstract class and cannot generate objects.

Main.java:6: Myabstract is abstract; cannot be instantiated
Copy after login

33. Interface methods cannot have method bodies

MyInterface.java:2: interface methods cannot have body
Copy after login

34, .It belongs to an abstract class and cannot generate entities

Myabstract is abstract; cannot be instantiated
Copy after login

35. Interface methods cannot have method bodies

interface methods cannot have body
Copy after login

36. Static modification is not allowed here

asa.java:3: modifier static not allowed here
 public static void main(String []args){
     ^    ^
Copy after login

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
Copy after login

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
Copy after login

40 Bracket Exception

asa.java:8: &#39;}&#39; expected
Copy after login

41. The application attempted to create an array with a negative size.

 java.lang.NegativeArraySizeException
Copy after login

42. Abnormal operation conditions

java.lang.ArithmeticException: / by zero
        at Test2.test(Test2.java:16)
        at Test2.main(Test2.java:5)
Copy after login

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

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.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

Square Root in Java Square Root in Java Aug 30, 2024 pm 04:26 PM

Guide to Square Root in Java. Here we discuss how Square Root works in Java with example and its code implementation respectively.

Perfect Number in Java Perfect Number in Java Aug 30, 2024 pm 04:28 PM

Guide to Perfect Number in Java. Here we discuss the Definition, How to check Perfect number in Java?, examples with code implementation.

Random Number Generator in Java Random Number Generator in Java Aug 30, 2024 pm 04:27 PM

Guide to Random Number Generator in Java. Here we discuss Functions in Java with examples and two different Generators with ther examples.

Weka in Java Weka in Java Aug 30, 2024 pm 04:28 PM

Guide to Weka in Java. Here we discuss the Introduction, how to use weka java, the type of platform, and advantages with examples.

Armstrong Number in Java Armstrong Number in Java Aug 30, 2024 pm 04:26 PM

Guide to the Armstrong Number in Java. Here we discuss an introduction to Armstrong's number in java along with some of the code.

Smith Number in Java Smith Number in Java Aug 30, 2024 pm 04:28 PM

Guide to Smith Number in Java. Here we discuss the Definition, How to check smith number in Java? example with code implementation.

Java Spring Interview Questions Java Spring Interview Questions Aug 30, 2024 pm 04:29 PM

In this article, we have kept the most asked Java Spring Interview Questions with their detailed answers. So that you can crack the interview.

Break or return from Java 8 stream forEach? Break or return from Java 8 stream forEach? Feb 07, 2025 pm 12:09 PM

Java 8 introduces the Stream API, providing a powerful and expressive way to process data collections. However, a common question when using Stream is: How to break or return from a forEach operation? Traditional loops allow for early interruption or return, but Stream's forEach method does not directly support this method. This article will explain the reasons and explore alternative methods for implementing premature termination in Stream processing systems. Further reading: Java Stream API improvements Understand Stream forEach The forEach method is a terminal operation that performs one operation on each element in the Stream. Its design intention is

See all articles