java编译器错误提示有哪些,java编译器一次不给出所有错误

System.out.println("First eror :: without semicolon ") // first Error

System.Out.println("This second error :: OUT object not used proper :: "); //second error

class TestCompilation

{

public static void main(String []args)

{

System.out.println("Hello no semicolon::")//First Error

System.Out.println("Hello out spell not correctely::"); //Second Error

}

}

whenever i compile above code by JAVAC command in cmd it gives only First Error means not give second Error. In java language partially compiler and partially interpreter and In java first compilation happen so compiler should list out all errors but it gives me only single error. why its happening ? i dont understand so please help me out from this problem..

I think now i am clear about my question means compiler works totally ...

For that i create simple example it will help you to understand the java compiler working .

class TestCompilation

{

public static void main(String []args)

{

Syste.out.rintln("Hello");//First Error

Syste.Out.rintln("Hello");//Second Error (Not printed at compiler time because it syntatically correct as in compiler first phase)

Hitesh542.add(); //there is no such class called Hitesh542.- but compiler thinks that it is right way to call the method. So it passes the first time.

Hitesh542.add()();//Look out here.. There is a problem, that we can't call a method like this..So it will show the error on first lookup.

System.otu.println("Hello")//second Errorasdasdas

if(); //look this is also an error.- A BASIC syntax error shown at the first lookup.

try{

int i = 10 / 0;

}

//Third error

//So bottom line is the JAVA syntatical errors are checked first i.e The SYNTAX of JAVA not the classes or objects.

//But obv is the first thing is Java Compiler should get the Java class first for compilation on proper path. :)

}

}

解决方案

I'd say this has to do with how compilers often work:

Lexical analysis is performed, where the source code is converted into a sequence of "tokens".

The code is parsed, where the compiler checks whether the tokens meet the language syntax. This is where your first line would fail: every statement in Java must be ended with a semicolon.

Semantic analysis is performed, where the compiler tries to resolve variables, methods, etc. according to the list of known symbols - in Java, this would roughly translate to your classpath.

Code is generated where the source statements are translated either into native bytecode or some intermediate bytecode (the latter is the case for Java).

If one of the steps fails, the process must stop, because a compiler cannot perform semantic analysis when the code doesn't meet the syntax.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值