This article is participating in the Java Theme Month – Java Debug Notes Event, see the event link for details

Debug Note < Common Statement writing Errors for Java Beginners >

For Java beginners, there are a few common mistakes you’ll encounter when writing code

The errors are listed below:

Common Mistake 1

The name of the class that public decorates must have the same name as the Java file!

For example, I named the Java code file demo1

Public modifies the class with the name demo2

My code is going to run wrong

public class demo2{
    public static void main(String[] args) {
        System.out.println("Hello Jue Jin!"); }};Copy the code

The output is:

The correct code is:

public class demo1{
    public static void main(String[] args) {
        System.out.println("Hello Jue Jin!"); }};Copy the code

The output is:

Common Mistake # 2

The main() method is the program entry, and void can’t be forgotten!

Error code:

public class demo1{
    public static main(String[] args) {
        System.out.println("Hello Jue Jin!"); }};Copy the code

The output is:

The correct code is:

public class demo1{
    public static void main(String[] args) {
        System.out.println("Hello Jue Jin!"); }};Copy the code

The output is:

Common Mistake 3

Case syntax error, Java language code case sensitive, writing needs specification!

Error code:

public class demo1{
    public static void main(String[] args) {
        system.out.println("Hello Jue Jin!"); }};Copy the code

The output is:

The correct code is:

public class demo1{
    public static void main(String[] args) {
        System.out.println("Hello Jue Jin!"); }};Copy the code

The output is:

Common Mistake # 4

Every Java statement must end with a semicolon!

Error code:

public class demo1{
    public static void main(String[] args) {
        System.out.println("Hello Jue Jin!")}};Copy the code

The output is:

The correct code is:

public class demo1{
    public static void main(String[] args) {
        System.out.println("Hello Jue Jin!"); }};Copy the code

The output is:

Common Mistake # 5

Missing quotes!

Error code:

public class demo1{
    public static void main(String[] args) {
        System.out.println(Hello Jue Jin!);
    }
};
Copy the code

The output is:

The correct code is:

public class demo1{
    public static void main(String[] args) {
        System.out.println("Hello Jue Jin!"); }};Copy the code

The output is: