Correct Answer : Get Lastest Questions and Answer : Explanation: The compiler is invoked by the javac command. When compiling a Java class, you must include the file name, which houses the main classes including the Java extension. So to run Main.java file we have to use command in option A. TO execute Java program we can use Java command but can't use it for compiling.
Correct Answer : Get Lastest Questions and Answer : Explanation: Not B: IOError and IOException are both checked errors. Not C, not D, not E FileNotFoundException is a checked error.
Checked exceptions: - represent invalid conditions in areas outside the immediate control of the program (invalid user input, database problems, network outages, absent files) - are subclasses of Exception - a method is obliged to establish a policy for all checked exceptions thrown by its implementation (either pass the checked exception further up the stack, or handle it somehow)
Unchecked exceptions: - represent defects in the program (bugs) - often invalid arguments passed to a non-private method. To quote from The Java Programming Language, by Gosling, Arnold, and Holmes: "Unchecked runtime exceptions represent conditions that, generally speaking, reflect errors in your program's logic and cannot be reasonably recovered from at run time." - are subclasses of RuntimeException, and are usually implemented using IllegalArgumentException, NullPointerException, or IllegalStateException - method is not obliged to establish a policy for the unchecked exceptions thrown by its implementation (and they almost always do not do so)
Correct Answer : Get Lastest Questions and Answer : Explanation: The first println statement, System.out.println(array [4][1]);, works fine. It selects the element/array with index 4, {0, 4, 8, 12, 16}, and from this array it selects the element with index 1, 4. Output: 4 The second println statement, System.out.println(array) [1][4]);, fails. It selects the array/element with index 1, {0, 1}, and from this array it try to select the element with index 4. This causes an exception. Output: 4 Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
Exp : A program can use exceptions to indicate that an error occurred. To throw an exception, use the throw statement and provide it with an exception object - a descendant of Throwable - to provide information about the specific error that occurred. A method that throws an uncaught, checked exception must include a throws clause in its declaration.
A program can catch exceptions by using a combination of the try, catch, and finally blocks.
The try block identifies a block of code in which an exception can occur. The catch block identifies a block of code, known as an exception handler, that can handle a particular type of exception. The finally block identifies a block of code that is guaranteed to execute, and is the right place to close files, recover resources, and otherwise clean up after the code enclosed in the try block. The try statement should contain at least one catch block or a finally block and may have multiple catch blocks.
The class of the exception object indicates the type of exception thrown. The exception object can contain further information about the error, including an error message. With exception chaining, an exception can point to the exception that caused it, which can in turn point to the exception that caused it, and so on. Advantage 1: Separating Error-Handling Code from "Regular" Code Advantage 2: Propagating Errors Up the Call Stack Advantage 3: Grouping and Differentiating Error Types
Question : Given the code fragment: What is the result?
1. A B C Work done 2. A B C D Work done 3. A Work done 4. Compilation fails