Influencing policy (training slides from Fast Track Impact)
Java Interview Tips Cognizant Questions Answers
1. Java Interview Questions and Answers for cognizant:
In this Java Interview Questions, I am going to list some of the most important
Java Interview Questions and Answers which will help you in the interview
process. Java is used by approximately 10 Million developers worldwide to develop
applications. It is also used to create applications for trending technologies like
Mobiles. And hence today, Java is used everywhere!
1. What do you understand by java?
Java is an object-oriented computer language.
Java is a fast, secure and reliable languageused for many games, devices
and applications.
2. What are the major Java features?
Object-Oriented – java is based on object-oriented programming where the class and
methods describe about the state and behaviour of object.
Portable – Java program gets converted into Java Byte Codes that can be executed
on any platform without any dependency.
Platform independent – java works on “write once and run anywhere” as it supports
multiple platforms like Windows, Linux, Mac, Sun Solaris, etc.
Robust – Java has a strong memory management as there is no pointer allocations. It
has automatic garbage collection that prohibits memory leaks.
Interpreted – java compiler converts the codes into Java Byte Codes which are then
interpreted and executed by Java Interpreter.
2. What doyoumeanby Object?
A Javaobject is a combinationof data andprocedures workingon the available data.
Objects are created from templatesknownas classes. InJava, an object is created usingthe
keyword"new".
3. What is class inJava?
A class is a user defined blueprint or prototype from which objects are created. It
represents the set of properties or methods that are common to all objects of one type.
4. What is JDK, JREand JVM?
JVM stands for Java Virtual Machine which provides runtime environment for Java
Byte Codes to be executed.
2. JRE stands for Java Runtime Environment that includes sets of files required by
JVM during runtime.
JDK stands for Java Development Kit consists of JRE along with the development
tools required to write and execute a program.
5. Differentiate between String Buffer and String Builder in Java
programming?
String Buffer in java is used to create modifiable String objects. This means
that we can use String Buffer to append, reverse, replace, concatenate and
manipulate Strings or sequence of characters.
Java String Builder class is designed for use as a drop-in replacement for String
Buffer in places where the string buffer was being used by a single thread (as
is generally the case).
6. Difference between Array list And Vector?
An array is nothing but a sequential collection same type of elements, accessed by
their index values.
Java Array List uses an array as the internal programming construct to store
elements.
Vectors in java just another kind of object, of type java.util.Vector.
7. Difference between the Inner Class and Sub Class?
Inner class provides the access rights for the class which is nesting it and that can access all
variables and methods defined in the outer class.
Sub-class provides access to all public and protected methods and fields of its super class.
8. Name the methods of Object Class?
clone() – This method helps to create and return a copy of the object.
equals() – This method helps to compare
finalize() – Called by the garbage collector on an object
getClass() – It helps to return the runtime class of an object.
hashCode() – Helps to return a hash code value for the object.
toString() – helps to return a string representation of the object.
notify(), notifyAll(), and wait() – It helps to synchronize the activities of
independently running threads in a program.
9. What are Loops in Java? What are three types of loops?
Looping is used in programming to execute a statement or a block of
statement repeatedly. There are three types of loops in Java:
3. 1) For Loops
For loops are used in java to execute statements repeatedly for a given number
of times. For loops are used when number of times to execute the statements is
known to programmer.
2) While Loops
While loop is used when certain statements need to be executed repeatedly until
a condition is fulfilled. In while loops, condition is checked first before execution of
statements.
3) Do While Loops
Do While Loop is same as while loop with only differencethat condition is
checked after execution of block of statements. Hence in case of do while loop,
statements are executed at least once.
10. What is Final Keyword in Java? Give an example.
In java, a constant is declared using the keyword Final. Value can be
assigned only once and after assignment, value of a constant can't be
changed.
In below example, a constant with the name const_val is declared and assigned
avalue:
Private Final int const_val=100 When a method is declared as final,it can NOT be
overridden by the subclasses.This method are faster than any other
method,because they are resolved at complied time.
When a class is declares as final,it cannot be subclassed. Example String,Integer
and other wrapper classes.