You are on page 1of 5

What is an Exception? Exception is a run-time error which arises during the execution of java program.

The term exception in java stands for an exceptional event. It can be defined as abnormal event that arises during the execution and normal flow of program. The exceptional event can also be error in the program

Write the syntax of Interface?


/* File name : Animal.java */ interface Animal { public void eat(); public void travel(); }

What is an Interface?
An interface is a collection of abstract methods. A class implements an interface, thereby inheriting the abstract methods of the interface.

What is an Inner Class ? Inner class is a non-static class which is defined inside another class

Define Interpreter? Java interpreter translates the Java bytecode into the code that can be understood by the Operating System. Define Buffer A buffer is a linear, finite sequence of elements of a specific primitive type. Aside from its content, the essential properties of a buffer are its capacity, limit, and position: A buffer's capacity is the number of elements it contains. The capacity of a buffer is never negative and never changes. A buffer's limit is the index of the first element that should not be read or written. A buffer's limit is never negative and is never greater than the its capacity. A buffer's position is the index of the next element to be read or written. A buffer's position is never negative and is never greater than its limit.

How to declare a class in Java ?


class YourClass extends YourSuperClass implements SomeInterface {

declare your field, constructor, and methods here }

What is an array? array is the static memory allocation. It allocates the memory for the same data type in sequence. It contains multiple values of same types. It also store the values in memory at the fixed size. Multiple types of arrays are used in any programming language such as: one - dimensional, two - dimensional or can say multi - dimensional.

How to declare Array?


int num[]; or int num = new int[2]; What is a general form of a class ?
class clsSample { // Variables static int ctr; int i; int j; // Constructor clsSample() { ctr = 0; i = 0; j = 0; } clsSample(int a, int b, int c) { ctr = a; i = b; j = c; } // Methods int addition() { ctr++; return i + j; } int NumberOfInstances() { return ctr; } }gs

How to overload a method ?


In a class, the concept of method overloading does not allow the external user to be aware about the internal processing of the system

-- It just allows to user to use the different implementations of same name collected together and react appropriately to the supplied parameters to get the desired output. -- Method Overloading, allows the user to achieve the compile time polymorphism. -- Overloaded methods are always the part of the same class. These methods have the same name, but they may take different input parameters. -- The arguments passed to a overloaded method may differ in type or in number, or both. -- Overloaded methods may have the same or different return types.

What is difference between Error and Exception? Ans) An error is an irrecoverable condition occurring at runtime. Such as OutOfMemory error. These JVM errors and you can not repair them at runtime.Though error can be caught in catch block but the execution of application will come to a halt and is not recoverable. While exceptions are conditions that occur because of bad input etc. e.g. FileNotFoundException will be thrown if the specified file does not exist. Or a NullPointerException will take place if you try using a null reference. In most of the cases it is possible to recover from an exception (probably by giving user a feedback for entering proper values etc.)

Describe the new operator with an example. The new operator instantiates a class by allocating memory for a new object and returning a reference to that memory. The new operator also invokes the object constructor.
public class Point { public int x = 0; public int y = 0; //constructor public Point(int a, int b) { x = a; y = b; } }

This class contains a single constructor. You can recognize a constructor because its declaration uses the same name as the class and it has no return type. The constructor in thePoint class takes two integer arguments, as declared by the code (int a, int b). The following statement provides 23 and 94 as values for those arguments:
Point originOne = new Point(23, 94);

Applet

Applet is java program that can be embedded into HTML pages. Java applets runs on the java enables web browsers such as mozila and internet explorer. Applet is designed to run remotely on the client browser, so there are some restrictions on it. Applet can't access system resources on the local computer. Applets are used to make the web site more dynamic and entertaining. Advantages of Applet:

Applets are cross platform and can run on Windows, Mac OS and Linux platform Applets can work all the version of Java Plugin Applets runs in a sandbox, so the user does not need to trust the code, so it can work without security approval Applets are supported by most web browsers Applets are cached in most web browsers, so will be quick to load when returning to a web page User can also have full access to the machine if user allows

Disadvantages of Java Applet:

Java plug-in is required to run applet Java applet requires JVM so first time it takes significant startup time If applet is not already cached in the machine, it will be downloaded from internet and will take time Its difficult to desing and build good user interface in applets compared to HTML technology

What is package? A Package can be defined as a grouping of related types(classes, interfaces, enumerations and annotations ) providing access protection and name space management. Explain the three OOP principles.?
The 4 important OO principles is 1) Encapsulation Encapsulation is the technique of making the fields in a class private and providing access to the fields via public methods. If a field is declared private, it cannot be accessed by anyone outside the class, thereby hiding the fields within the class. For this reason, encapsulation is also referred to as data hiding.

2) Inheritance Inheritance can be defined as the process where one object acquires the properties of another. With the use of inheritance the information is made manageable in a hierarchical order

3) Polymorphism Polymorphism is the ability of an object to take on many forms. The most common use of polymorphism in OOP occurs when a parent class reference is used to refer to a child class object.

4) Abstraction Abstraction refers to the ability to make a class abstract in OOP. An abstract class is one that cannot be instantiated. All other functionality of the class still exists, and its fields, methods, and constructors are all accessed in the same manner. You just cannot create an instance of the abstract class.

Object - Objects have states and behaviors. Example: A dog has states-color, name, breed as well as behaviors -wagging, barking, eating. An object is an instance of a class. Class - A class can be defined as a template/ blue print that describe the behaviors/states that object of its type suppor

You might also like