Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

OCA- Enthuware Question - Exception Handling

Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Enthuware Question

Which exception will be thrown ?

SomeClass sc = new SomeClass();
(Assume that SomeClass is not available in runtime classpath.)

Can some one explain this?
Posts: 2265
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
aria Pll
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am little bit confuse between these two -


Posts: 1868
Android IntelliJ IDE MySQL Database Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the associated pages on
Thrown when an application tries to load in a class through its string name using:
  • The forName method in class Class.
  • The findSystemClass method in class ClassLoader.
  • The loadClass method in class ClassLoader.

  • but no definition for the class with the specified name could be found.

    Thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class (as part of a normal method call or as part of creating a new instance using the new expression) and no definition of the class could be found.
    The searched-for class definition existed when the currently executing class was compiled, but the definition can no longer be found.
    ------------End Of Java Doc------------

    It appears as though that with NoClassDefFoundError, the program compiled fine, but some time between compiling and running an dependency was moved.
    Where as with ClassNotFoundException this usually(only?) happens when you try to load a class, think database driver, after starting the program using the commands listed above.

    Fairly often, we use something like:

    Which loads all of the classes at the start of the program.
    However we also use forName and/or ClassLoader when loading in drivers for a database and in other cases only after the program starts.
    There could be times that this forName and/or ClassLoader are not even called when using the program. In which case the ClassNotFoundException error is not seen and doesn't occur.
    Yet the NoClassDefFoundError error will most likely be seen or occur if the resources are not setup correctly at the very start of the program execution.

    Looking at the associated pages on may help as you can see the class inheritance and more.
    Luckily we (I haven't taken this exam yet, but will soon) do not need to know about ClassLoader and forName for the OCA 1Z0-808 exam.
    We cannot change unless we survive, but we will not survive unless we change. Evolving tiny ad:
    Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
      Bookmark Topic Watch Topic
    • New Topic