Sample Paper for Java Programming Language

Mar 27 • Engineering Sample Papers • 14651 Views • 12 Comments on Sample Paper for Java Programming Language

Sample Paper for Java Programming Language given with their solutions for core java and advance java.Sample Paper for Java Programming Language will very helpful for those who want to improve their skills in Java Programming.This page include all the basic terminology of Java Programming and cover all the concept and principal in Java.

Before going on Sample Paper for Java Programming Language we will introduce Java Programming Language in brief.

Introduction of Java Programming Language

JAVA is a programming language, which is based on the concept of object oriented programming.It is a simple, secure, portable, object oriented, robust, interpreted, architecture neutral programming language.By using Java a Programmer can build Desktop Application and Web Application as well.


Java Question and Answer

Java Sample Paper

Sample Paper for Java Programming Language

Q.1 Answer the following questions:

(a) What is JAVA?

Ans–   (i) JAVA is a programming language, which is based on the concept of object oriented programming.

(ii) JAVA is a simple, secure, portable, object oriented, robust, interpreted, architecture neutral programming language.

     (b) What is Byte code?

Ans–  (i) The key that allows Java to solve both the security and the portability problems, the output of a Java Compiler is not executable code, rather it is byte code.

(ii) Byte code is a highly optimized set of instructions designed to be executed by the java run time system, which is called Java Virtual Machine (JVM).

(c) Write a java program to compute the area of a circle.

Ans  Class Circle


Public static void main(String args[])


double pi, r, a;

pi= 3.1416;

r= Double.parse Double(args[0]);

a= r*r*pi;

System.Out.println(“Area of circle is”+a);



(d) What is Class and Object?

Ans-  (i) A Class defines the properties  (variables and methods) that is shared by all its objects. It is the blue print for the creation of objects.

(ii) An Object is the basic entity of object oriented programming language. It is an instance of class. It takes the properties and uses the behavior defined in the class.

(e) What is Encapsulation?

Ans  Encapsulation is the process of binding together the methods and data variables as a single entity. It keeps both the data and functionality code safe from the outside interference.

(f) Define Constructor.

Ans–  It is a special method having the following characteristics:

(i)   Same name as class.

(ii)   Defined as public

(iii)  Can accept arguments.

(iv)   Can be overloaded.

(v)    To initialize the object.

(vi)   Always invoked at the time of creation of any object.

(vii)  Does not have any return type, not even void.

 (g) Define Abstract Class.

Ans  Abstract class is a special type of class which contain abstract and non abstract methods. No objects can be created of an abstract class.

(h) What is Interface?

Ans– (i) An Interface is essentially a collection of constants and abstract methods.

(ii) It can contain either constant or abstract method or both.

(i)   What is the function of destroy()?

Ans  The destroy() is called only on that time, when the browser need to shut down.

(j) Describe Delegation Event Model.

Ans–  (i) The event handling mechanism in Java are handled through a model called Delegation Event Model.

(ii) This model is a modern approach to handle the events by defining stranded and consistent mechanisms to generate and process events.

2.      How Java is different from C++ ? Explain.

Ans  Java is different from C++ by the following reasons:

(i)   Java does not include structures or unions.

(ii)  Java does not support operator overloading.

(iii) Java does not support pre-processor directives.

(iv) Java does not perform any automatic type conversions that result in a loss of precision.

(v) Java does not allow default arguments.

(vi) Java does not support the inheritance of multiple super classes by a sub class.

(vii) Although Java support constructors, it does not have destructors. It does, however, add finalize() function.

(viii) Java does not support typedef.

(ix) It is not possible to declare unsigned integers in Java.

(x) Java does not allow go to.

(xi) Java does not have the delete operator.

(xii) The << and >> in Java are not overloaded for i/o operations.

(xiii) In Java, objects are passed by reference only.

3. Write a Java program to find the sum of first 100 prime numbers.


             Class Prime


Public static void main(String args[])


int n=1, sum=0, i, k, c=0;

while (c<100)



while (k<n)








sum= sum+n;

System.out.println(“ “+n);





System.out.println(“Sum of first 100 prime number is:”+sum);



4. What is Dynamic method dispatch? Explain with an example.

Ans  It is a mechanism by which a call to an overridden method at run time, rather than compile    time.


Class A


Void show ()


System.out.println (“I am from A”);



Class B extends A


Void show ()


System.out.println (“I am from B”);



Class C extends C


Void show ()


System.out.println (“I am from C”);



Class ABC


public static void main (String args[])


A a= new A ();

B b= new B ();

C c= new C ();

A x;

x=a; ();

x=b; ();

x=c; ();



5. What is Applet ? How it is differ from Application? Explain.

Ans Applets are small window based applications that are accessed on an internet server and run as a part of web document. After an applet carries on the client, it has limited access to resources. So that it can produce an arbitrary multimedia user interface and run complex computations without introducing the risk of virus.

        Applet vs Application:

(i)  Applets are small programs while applications are larger programs.

(ii) Applets does not have the main () method while in an application, execution starts from the main () method.

(iii) Applets can run in our browser’s window or in an applet viewer, where application are used in command line.

(iv) Applets are designed for client programming purpose while the applications don’t have such type of criteria.

(v)  Applets are GUI based programs while applications are CUI based programs.

(vi)  Applets are designed just for handling the client site problems, while java applications are designed to work with the client as well as server.

(vii)  Applications are designed to exists in a secure area, while the applets are typically used.

6. What is Event class ? Write a program for mouse event handler.

Ans. Event classes are used to handle Java event handling. It is the super class for all events. It produces a constructor as “ EventObject (Object x)”.

Mouse event Handler:

import java.awt.*;

import java.awt.event.*;

import java.applet.*;

/* <applet code= “MouseEvents” width=300 height=100>



public class MouseEvents extends Applet implements Mouselistener, MouseMotionListener


String msg=” “;

int mouseX=0, mousey=0;

public void init ()





public void mouseClicked (MouseEvent me)




msg= “Mouse clicked.”;



public void mouseEntered (MouseEvent me)




msg= “Mouse entered.”;



public void mouseExited (MouseEvent me)




msg= “Mouse exited.”;



public void mousePressed (MouseEvent me)


mouseX=me.getX ();

mousey=me.getY ();

msg= “Down.”;



public void mouseReleased (MouseEvent me)


mouseX= me.getX ();

mousey= me.getY ();

msg= “Up.”;



public void mouseDragged (MouseEvent me)


mouseX= me.getX ();

mousey= me.getY ();

msg= “*”;

showStatus (“Dragging mouse at”+mouseX+”,”+mouseY);



public void mouseMoved (MouseEvent me)


showStatus (“Moving mouse at”+me.getX()+”,”+me.getY());


Public void paint (Graphics g)


g.drawString (msg,mouseX,mouseY);



Basic Interview Questions on Core Java

1.what  is a transient variable?

Ans A transient variable is a variable that may not be serialized.

2.Why do threads block on I/O?

Ans Threads block on i/o (that is enters the waiting state) so that other threads may execute while the i/o Operation is performed.

3 Is null a keyword?

Ans The null value is not a keyword.

4 Which characters may be used as the second character of an identifier, but not as the first character of an identifier?

Ans The digits 0 through 9 may not be used as the first character of an identifier but they may be used after the first character of an identifier.

5 How does Java handle integer overflows and underflows?

Ans It uses those low order bytes of the result that can fit into the size of the type allowed by the operation.

6 What are wrapped classes?

Ans Wrapped classes are classes that allow primitive types to be accessed as objects.

7 Can an object’s finalize() method be invoked while it is reachable?

Ans An object’s finalize() method cannot be invoked by the garbage collector while the object is still reachable. However, an object’s finalize() method may be invoked by other objects.

8 What value does readLine() return when it has reached the end of a file?

Ans The readLine() method returns null when it has reached the end of a file.

9 What is clipping?

Ans Clipping is the process of confining paint operations to a limited area or shape.

10 When a thread blocks on I/O, what state does it enter?

Ans A thread enters the waiting state when it blocks on I/O.

11 What is the difference between a MenuItem and a CheckboxMenuItem?

Ans The CheckboxMenuItem class extends the MenuItem class to support a menu item that may be checked or unchecked.

12 In which package are most of the AWT events that support the event-delegation model defined?

Ans Most of the AWT-related events of the event-delegation model are defined in the java.awt.event package. The AWTEvent class is defined in the java.awt package.

13 What must a class do to implement an interface?

Ans It must provide all of the methods in the interface and identify the interface in its implements clause.

14 What is the purpose of the wait(), notify(), and notifyAll() methods?

Ans The wait(),notify(), and notifyAll() methods are used to provide an efficient way for threads to wait for a shared resource. When a thread executes an object’s wait() method, it enters the waiting state. It only enters the ready state after another thread invokes the object’s notify() or notifyAll() methods.

15 How are Java source code files named?

Ans A Java source code file takes the name of a public class or interface that is defined within the file. A source code file may contain at most one public class or interface. If a public class or interface is defined within a source code file, then the source code file must take the name of the public class or interface. If no public class or interface is defined within a source code file, then the file must take on a name that is different than its classes and interfaces. Source code files use the .java extension.

Solved Interview Question of Java

Basic Interview Question on Java

AJAX (Asynchronus Java Script and XML)

Tell us Your Queries, Suggestions and Feedback

Your email address will not be published.

« »