• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Compilation error or Exception

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Quick question please what is the difference between a compilation error (or compilation fails) and an exception(programme throws an exception) ?

In the OCA exam, how we would tell if its a compilation error or an exception if we have them both in the multiple choice ?

Thanks in advance
 
Marshal
Posts: 79180
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As you said, in the case of a compile‑time error compilation fails and there is only whatever bytecode was in existence before the attempted compilation.
Exceptions cannot be thrown until the JVM starts.
Compilation is usually started with thee javac command and the JVM is usually started with the java command.

You need to know the rules of syntax; anything breaching those rules will fail to compile.
You need to know the rules of the semantics of the language and when are breached, because that can cause an exception to be thrown.
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To expand a little on Campbell's post, syntax has to do with the structure of the code; semantics has to do with the meaning of the code.  So for example:
This is a syntax error, because there is no method in System.out called printx.  So it is a compile time error.
Here, the structure of the code is fine -- therefor no compile time error.  But what does 1/0 mean?  You can't divide by zero and get any meaningful answer.  So it will be a runtime exception.
reply
    Bookmark Topic Watch Topic
  • New Topic