Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

1.

1 java program and explain the syntax expression and statement


2. public class FindEvenOrOddNumber {
3.
4.
public static void main(String[] args) {
5.
6.
int[] numbers = new int[]{1,2,3,4,5,6,7,8,9,10};
7.
8.
for(int i=0; i < numbers.length; i++){
9.
10.
if(numbers[i]%2 == 0)
11.
System.out.println(numbers[i] + " is even number.");
12.
else
13.
System.out.println(numbers[i] + " is odd number.");

The class name here is FindEvenOrOddNumber in this code uses the int
or integer for the numbers 1-10 and in this code uses if and else statement
for us to know if the number is an odd or even.
2. difference between error and exception
Recovering from Error is not possible. The only solution to errors is to
terminate the execution but in exception can be handle by the try and catch .
3. 5 high level programming languages.
BASIC, COBOL, C, C++, FORTRAN
4. why to handle exception?
The normal flow of the program is disrupted and the program will terminate
abnormally.
5.explain the following
Classnotfoundexception:
the Java Virtual Machine tries to load a particular class and the
specified class cannot be found in the classpath.
Interruptedexception:
It happens when something calls interrupt() on the thread. This
article by Brian Goetz explains the interruption mechanism and how
you should handle InterruptedExceptions.
Illegalaccesssexception:
thrown when an application tries to reflectively create an instance
(other than an array), set or get a field, or invoke a method, but the currently

executing method does not have access to the definition of the specified
class, field, method or constructor.
Runtimeexception:
the superclass of those exceptions that can be thrown during the
normal operation of the Java Virtual Machine. RuntimeException and its
subclasses are unchecked exceptions.

You might also like