Headstrong java questions for practice,Headstrong recruitment practice question papers
1 What is a class?
A class is a blueprint, or prototype, that defines the variables and the methods common to all objects of a certain kind.
2 What is a object?
An object is a software bundle of variables and related methods.An instance of a class depicting the state and behavior at that particular time in real world.
3 What is a method?
Encapsulation of a functionality which can be called to perform specific tasks.
4 What is encapsulation? Explain with an example.
Encapsulation is the term given to the process of hiding the implementation details of the object. Once an object is encapsulated, its implementation details are not immediately accessible any more. Instead they are packaged and are only indirectly accessible via the interface of the object
5 What is inheritance?
Explain with an example. Inheritance in object oriented programming means that a class of objects can inherit properties and methods from another class of objects.
6 What is polymorphism?
Explain with an example. In object-oriented programming, polymorphism refers to a programming language's ability to process objects differently depending on their data type or class. More specifically, it is the ability to redefine methods for derived classes. For example, given a base class shape, polymorphism enables the programmer to define different area methods for any number of derived classes, such as circles, rectangles and triangles. No matter what shape an object is, applying the area method to it will return the correct results. Polymorphism is considered to be a requirement of any true object-oriented programming language
7 Is multiple inheritance allowed in Java? No, multiple inheritance is not allowed in Java.
8 What is interpreter and compiler?
Java interpreter converts the high level language code into a intermediate form in Java called as bytecode, and then executes it, where as a compiler converts the high level language code to machine language making it very hardware specific
9 What is JVM?
The Java interpreter along with the runtime environment required to run the Java application in called as Java virtual machine(JVM)
10 What are the different types of modifiers? There are access modifiers and there are other identifiers. Access modifiers are public, protected and private. Other are final and static.
15 What are the access modifiers in Java?
There are 3 access modifiers. Public, protected and private, and the default one if no identifier is specified is called friendly, but programmer cannot specify the friendly identifier explicitly.
16 What is a wrapper class?
They are classes that wrap a primitive data type so it can be used as a object
17 What is a static variable and static method? What's the difference between two?
The modifier static can be used with a variable and method. When declared as static variable, there is only one variable no matter how instances are created, this variable is initialized when the class is loaded. Static method do not need a class to be instantiated to be called, also a non static method cannot be called from static method.
18 What is garbage collection?
Garbage Collection is a thread that runs to reclaim the memory by destroying the objects that cannot be referenced anymore.
19What is abstract class?
Abstract class is a class that needs to be extended and its methods implemented, aclass has to be declared abstract if it has one or more abstract methods.
20What is meant by final class, methods and variables?
This modifier can be applied to class method and variable. When declared as final class the class cannot be extended. When declared as final variable, its value cannot be changed if is primitive value, if it is a reference to the object it will always refer to the same object, internal attributes of the object can be changed.
21 What is interface?
Interface is a contact that can be implemented by a class, it has method that need implementation.
22 What is method overloading?
Overloading is declaring multiple method with the same name, but with different argument list.
23 What is method overriding?
Overriding has same method name, identical arguments used in subclass.
24 What is singleton class?
Singleton class means that any given time only one instance of the class is present, in one JVM.
25 What is the difference between an array and a vector?
Number of elements in an array are fixed at the construction time, whereas the number of elements in vector can grow dynamically.
26 What is a constructor?
In Java, the class designer can guarantee initialization of every object by providing a special method called a constructor. If a class has a constructor, Java automatically calls that constructor when an object is created, before users can even get their hands on it. So initialization is guaranteed.
27 What is casting?
Conversion of one type of data to another when appropriate. Casting makes explicitly converting of data.
28 What is the difference between final, finally and finalize?
The modifier final is used on class variable and methods to specify certain behaviour explained above. And finally is used as one of the loop in the try catch blocks, It is used to hold code that needs to be executed whether or not the exception occurs in the try catch block. Java provides a method called finalize( ) that can be defined in the class. When the garbage collector is ready to release the storage ed for your object, it will first call finalize( ),and only on the next garbage-collection pass will it reclaim the objects memory. So finalize( ),gives you the ability to perform some important cleanup at the time of garbage collection.
29 What is are packages?
A package is a collection of related classes and interfaces providing access protection and namespace management.
30 What is a super class and how can you call a super class?
31 When a class is extended that is derived from another class there is a relationship is created, the parent class is referred to as the super class by the derived class that is the child. The derived class can make a call to the super class using the keyword super. If used in the constructor of the derived class it has to be the first statement.
32 What is meant by a Thread?
Thread is defined as an instantiated parallel process of a given program.
33 What is multi-threading?
Multi-threading as the name suggest is the scenario where more than one threads are running.
34 What are two ways of creating a thread? Which is the best way and why?
Two ways of creating threads are, one can extend from the Java.lang.Thread and can implement the rum method or the run method of a different class can be called which implements the interface Runnable, and the then implement the run() method. The latter one is mostly used as first due to Java rule of only one class inheritance, with implementing the Runnable interface that problem is sorted out.
35 What is deadlock?
Deadlock is a situation when two threads are waiting on each other to release a resource. Each thread waiting for a resource which is held by the other waiting thread. In Java, this resource is usually the object lock obtained by the synchronized keyword.
36 What are the three types of priority?
MAX_PRIORITY which is 10, MIN_PRIORITY which is 1, NORM_PRIORITY which is 5.
37 What is the use of synchronizations?
Every object has a lock, when a synchronized keyword is used on a piece of code the, lock must be obtained by the thread first to execute that code, other threads will not be allowed to execute that piece of code till this lock is released.
38 What are synchronized methods and synchronized statements? Synchronized methods are methods that are used to control access to an object. For example, a thread only executes a synchronized method after it has acquired the lock for the method's object or class. Synchronized statements are similar to synchronized methods. A synchronized statement can only be executed after a thread has acquired the lock for the object or class referenced in the synchronized statement.
39 What are different ways in which a thread can enter the waiting state?
A thread can enter the waiting state by invoking its sleep() method, blocking on I/O, unsuccessfully attempting to acquire an object's lock, or invoking an object's wait() method. It can also enter the waiting state by invoking its (deprecated) suspend() method.
40 Can a lock be acquired on a class?
Yes, a lock can be acquired on a class. This lock is acquired on the class's Class object.
41 What's new with the stop(),suspend() and resume() methods in new JDK 1.2?
The stop(),suspend() and resume() methods have been deprecated in JDK 1.2.
42 What is the preferred size of a component?
The preferred size of a component is the minimum component size that will allow the component to display normally.
43 What method is used to specify a container's layout?
The setLayout() method is used to specify a container's layout. For example, setLayout(new FlowLayout()); will be set the layout as FlowLayout.
44 Which containers use a FlowLayout as their default layout?
The Panel and Applet classes use the FlowLayout as their default layout.
45 What state does a thread enter when it terminates its processing?
46 When a thread terminates its processing, it enters the dead state.
47 What is the Collections API?
The Collections API is a set of classes and interfaces that support operations on collections of objects. One example of class in Collections API is Vector and Set and List are examples of interfaces in Collections API.
48 What is the List interface?
The List interface provides support for ordered collections of objects. It may or may not allow duplicate elements but the elements must be ordered.
49 How does Java handle integer overflows and underflows?
It uses those low order bytes of the result that can fit into the size of the type allowed by the operation.
50 What is the Vector class?
The Vector class provides the capability to implement a growable array of objects. The main visible advantage of this class is programmer needn't to worry about the number of elements in the Vector.
51 What modifiers may be used with an inner class that is a member of an outer class?
A (non-local) inner class may be declared as public, protected, private, static, final, or abstract.If a method is declared as protected, where may the method be accessed? A protected method may only be accessed by classes or interfaces of the same package or by subclasses of the class in which it is declared.
52 What is an Iterator interface?
The Iterator interface is used to step through the elements of a Collection.
How many bits are used to represent Unicode, ASCII, UTF-16, and UTF-8 characters? Unicode requires 16 bits, ASCII require 7 bits (although the ASCII character set uses only 7 bits, it is usually represented as 8 bits),UTF-8 represents characters using 8, 16, and 18 bit patterns, UTF-16 uses 16-bit and larger bit patterns
53 What is the difference between yielding and sleeping?
Yielding means a thread returning to a ready state either from waiting, running or after creation, where as sleeping refers a thread going to a waiting state from running state. With reference to Java, when a task invokes its yield() method, it returns to the ready state and when a task invokes its sleep() method, it returns to the waiting state
54 What are wrapper classes?
Wrapper classes are classes that allow primitive types to be accessed as objects. For example, Integer, Double. These classes contain many methods which can be used to manipulate basic data types
55 Does garbage collection guarantee that a program will not run out of memory?
No, it doesn't. It is possible for programs to use up memory resources faster than they are garbage collected. It is also possible for programs to create objects that are not subject to garbage collection. The main purpose of Garbage Collector is recover the memory from the objects which are no longer required when more memory is needed.
Name Component subclasses that support painting? The following classes support painting: Canvas, Frame, Panel, and Applet.
56 What is a native method?
A native method is a method that is implemented in a language other than Java. For example, one method may be written in C and can be called in Java.
57 How can you write a loop indefinitely?
for(;;) //for loop
while(true); //always true
58 Can an anonymous class be declared as implementing an interface and extending a class?
An anonymous class may implement an interface or extend a superclass, but may not be declared to do both.
59 What is the purpose of finalization?
The purpose of finalization is to give an unreachable object the opportunity to perform any cleanup processing before the object is garbage collected. For example, closing a opened file, closing a opened database Connection.
60 What invokes a thread's run() method?
After a thread is started, via its start() method or that of the Thread class, the JVM invokes the thread's run() method when the thread is initially executed.
61 What is the GregorianCalendar class?
The GregorianCalendar provides support for traditional Western calendars.
62 What is the SimpleTimeZone class?
The SimpleTimeZone class provides support for a Gregorian calendar.
63 What is the Properties class?
The properties class is a subclass of Hashtable that can be read from or written to a stream. It also provides the capability to specify a set of default values to be used.
63 What is the purpose of the Runtime class?
The purpose of the Runtime class is to provide access to the Java runtime system.
64 What is the purpose of the System class?
The purpose of the System class is to provide access to system resources.
65 What is the purpose of the finally clause of a try-catch-finally statement?
The finally clause is used to provide the capability to execute code no matter whether or not an exception is thrown or caught. For example,
try
{
//some statements
}
catch
{
// statements when exception is cought
}
finally
{
//statements executed whether exception occurs or not
}
66 What is the Locale class?
The Locale class is used to tailor program output to the conventions of a particular geographic, political, or cultural region.
67What must a class do to implement an interface? It must provide all of the methods in the interface and identify the interface in its implements clause.
68 What is the difference between an Abstract class and Interface?
69 What is user defined exception?
70 What do you know about the garbage collector?
71 What is the difference between java and c++?
72 In an htm form I have a button which makes us to open another page in 15 seconds. How will you do that?
73 What is the difference between process and threads?
74 What is update method called?
75 Have you ever used HashTable and Directory?
76 What are statements in Java?
77 What is a JAR file?
78 What is JNI?
79 What is the base class for all swing components?
80 What is JFC?
81 What is the difference between AWT and Swing?
Considering notepad/IE or any other thing as process, What will happen if you start notepad or IE 3 times ? Where three processes are started or three threads are started?
82 How does thread synchronization occur in a monitor?
83 Is there any tag in htm to upload and download files?
84 Why do you canvas?
85 How can you know about drivers and database information ?
86 What is serialization?
87 Can you load the server object dynamically? If so what are the 3 major steps involved in it?
88 What is the layout for toolbar?
89 What is the difference between Grid and Gridbaglayout?
90 How will you add panel to a frame?
91 Where are the card layouts used?
92 What is the corresponding layout for card in swing?
93 What is light weight component?
94 Can you run the product development on all operating systems?
95 What are the benefits if Swing over AWT?
96 How can two threads be made to communicate with each other?
97 What are the files generated after using IDL to java compiler?
98 What is the protocol used by server and client?
99 What is the functionability stubs and skeletons?
100 What is the mapping mechanism used by java to identify IDL language?
101 What is serializable interface?
102 What is the use of interface?
103 Why is java not fully objective oriented?
104 Why does java not support multiple inheritance?
105 What is the root class for all java classes?
106 What is polymorphism?
107 Suppose if we have a variable 'I' in run method, if I can create one or more thread each thread will occupy a separate copy or same variable will be shared?
108 What are virtual functions?
109 Write down how will you create a Binary tree?
110 What are the traverses in binary tree?
111 Write a program for recursive traverse?
112 What are session variable in servlets?
113 What is client server computing?
114 What is constructor and virtual function? Can we call a virtual function in a constructor?
115 Why do we use oops concepts? What is its advantage?
116 What is middleware? What is the functionality of web server?
117 Why is java not 100% pure oops?
118 When will you use an interface and abstract class?
119 What is the exact difference in between Unicast and Multicast object? Where will it be used?
120 What is the main functionality of the remote reference layer?
121 How do you download stubs from Remote place?
122 I want to store more than 10 objects in a remote server? Which methodology will follow?
123 What is the main functionality of Prepared Statement?
124 What is meant by Static query and Dynamic query?
124 What are Normalization Rules? Define Normalization?
125 What is meant by Servelet? What are the parameters of service method?
126 What is meant by Session? Explain something about HTTP Session Class?
127 In a container there are 5 components. I want to display all the component names, how will you do that?
128 Why there are some null interface in JAVA? What does it mean? Give some null interface in JAVA?
129 Tell some latest versions in JAVA related areas?
130 What is meant by class loader? How many types are there? When will we use them?
131 What is meant by flickering?
132 What is meant by distributed application? Why are we using that in our application?
133 What is the functionality of the stub?
134 Explain about version control?
135 Explain 2-tier and 3-tier architecture?
136 What is the role of Web Server?
137 How can we do validation of the fields in a project?
138 What is meant by cookies? Explain the main features?
139 Why java is considered as platform independent?
140 What are the advantages of java over C++?
141 How java can be connected to a database?
142 What is thread?
143 What is difference between Process and Thread?
144 Does java support multiple inheritance? if not, what is the solution?
145 What are abstract classes?
146 What is an interface?
147 What is the difference abstract class and interface?
148 What are adapter classes?
149 what is meant wrapper classes?
150 What are JVM.JRE, J2EE, JNI?
151 What are swing components?
152 What do you mean by light weight and heavy weight components?
153 What is meant by function overloading and function overriding?
154 Does java support function overloading, pointers, structures, unions or linked lists?
155 What do you mean by multithreading?
156 What are byte codes?
157 What are streams?
158 What is user defined exception?
160 In an htm page form I have one button which makes us to open a new page in 15 seconds. How will you do that?