About Question enthuware.ocajp.i.v7.2.1368 :

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
convertor
Posts: 7
Joined: Mon Jan 27, 2014 6:25 am
Contact:

About Question enthuware.ocajp.i.v7.2.1368 :

Post by convertor »

> Taking the length of null as if it were an array.

what does it mean? For example?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1368 :

Post by admin »

int[] intArray = null;
System.out.println(intAray.length);
If you like our products and services, please help us by posting your review here.

convertor
Posts: 7
Joined: Mon Jan 27, 2014 6:25 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1368 :

Post by convertor »

thank you

crux terminatus
Posts: 12
Joined: Sat Feb 22, 2014 3:55 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1368 :

Post by crux terminatus »

I would like to suggest adding the expressions checked exception ('thrown by the application') and unchecked exception ('thrown by the JVM') to the explanation, as these are also widely used. E.g. OCA Java SE 7 Programmer I Certification Guide by Mala Gupta and Introduction to Java Programming by Y. Daniel Liang both contain them.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1368 :

Post by admin »

Not sure what you mean by "checked exception ('thrown by the application')" because it is not necessary that a checked exception is always thrown by the application and unchecked exception is always thrown by the jvm.
If you like our products and services, please help us by posting your review here.

crux terminatus
Posts: 12
Joined: Sat Feb 22, 2014 3:55 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1368 :

Post by crux terminatus »

I think I misunderstood this one.

So, ClassCastException, NullPointerException, SecurityException, IllegalStateException, IllegalArgumentException are all unchecked (runtime) exceptions. Whether an exception is checked or not has no relevance to what throws it - the JVM, or the application. Correct?

The question asks me to identify exceptions 'usually thrown'. Here's what the books I read have to say:

IllegalArgumentException
Gupta:
programmers usually use this exception to validate the arguments that are passed to a method.
OK, clear.

Liang: just states that an application can create an instance of it and throw it. Doesn't give clues to usual usage. (Says runtime exceptions are usually thrown by the JVM.)

IllegalStateException
Gupta:
As an author of code, you can throw IllegalStateException...
To me, this just means it's an option for me, not anything done usually.
Liang: Doesn't even mention it.

I understand the question and the answer. I'm just unsure as to where I should have learnt the info contained within. :)

gparLondon
Posts: 63
Joined: Fri Oct 31, 2014 6:31 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1368 :

Post by gparLondon »

A quick way to determine who should throw an exception is to see if the exception extends java.lang.Error. Errors are always thrown only by the JVM.
What is your opinion about "AssertionError" and NumberFormatException? are they thrown by JVM or program/application?

According to K&B book, both of them are thrown programmatically.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1368 :

Post by admin »

AssertionError is never thrown programmatically/explicitly by a programmer (A programmer legally can, but should not). A programmer writes assertions and if the assertion fails, AssertionError is thrown by the JVM.

NumberFormatException is never thrown by the JVM automatically. It is thrown by the programmer explicitly.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

gparLondon
Posts: 63
Joined: Fri Oct 31, 2014 6:31 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1368 :

Post by gparLondon »

Thanks, for your reply.

winddd
Posts: 18
Joined: Wed Feb 11, 2015 10:48 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1368 :

Post by winddd »

SecurityException extends RuntimeException: Usually thrown by the JVM.  It is thrown by the security manager upon security violation. For example, when a java program runs in a sandbox (such as an applet) and it tries to use prohibited APIs such as File I/O, the security manager throws this exception.
Wrong. SecurityException is never thrown by JVM, it's thrown by the java runtime libraries.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1368 :

Post by admin »

It is correct. It is not thrown explicitly by application code but thrown by the security manager, which is part of the jvm.
If you like our products and services, please help us by posting your review here.

winddd
Posts: 18
Joined: Wed Feb 11, 2015 10:48 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1368 :

Post by winddd »

Security manager (java.lang.SecurityManager) is part of jrl, not jvm. Formulations have to be exact. Any exception, which raised by "throw new " in java code can't be considered generated by jvm. Your answer is incorrect.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1368 :

Post by admin »

You are right. This has been updated.
thank you for your feedback!
If you like our products and services, please help us by posting your review here.

__Bill
Posts: 25
Joined: Thu Mar 27, 2014 11:35 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1368 :

Post by __Bill »

enthuware.ocajp.i.v7.2.1017 says SecurityException is thrown by the application programmer

enthuware.ocajp.i.v7.2.1368 still says SecurityException is thrown by the JVM

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1368 :

Post by admin »

Fixed.
thank you for your feedback!
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 27 guests