FREQUENTLY ASKED QUESTIONS IN JAVA
(1) What is token ? Give Examples.
Java token is the smallest individual unit used in a program which has some meaning. Ex- Operators,
Keywords, Identifiers, etc.
(2) What is a Class ?
Class is the group of same types of objects having some attributes and behaviours.
(3) What is an Object ?
An object is an instance of a class, which has some common characteristics and behaviour.
(4) What are the principles of OOPs ?
OOPs has 4 principles and that are Abstraction, Encapsulation, Inheritance and Polymorphism.
(5) What is Abstraction ?
It is an act of representing essential features without including background details.
(6) What is Encapsulation ?
Binding and wrapping of methods and data together into a single unit is called encapsulation.
(7) What is Inheritance ?
It is a feature of object-oriented approach by which one class share the members of another class.
(8) What is Polymorphism ?
It is a feature of object-oriented approach, which allows a function to be used more than one purpose.
(9) What is Data Type ?
Data types are means to identify the type of data.
(10) What is Primitive Data Type ?
The fundamental data types which are not composed of any other data type are known as primitive
data types. Ex- int, char, double, etc.
(11) What is Composite / Reference / Non-primitive data type ?
The user-defined data types that are derived from primitive data types are known as reference data
types. Ex- class, object, array, string, etc.
(12) What are the size of the primitive data types ?
char (2-bytes), Short (2-bytes), int (4-bytes), float (4-bytes), double (8-bytes), long (8-bytes)
(13) What is the hypothetical name of Java ?
OAK was the hypothetical name of Java.
(14) What are Keywords ?
Keywords are the reserved words which convey special meaning to the compiler. Ex- import, int, class,
(15) What is byte code ?
Java compiler translates the source code to an intermediate code called as byte code.
(16) What is JVM ?
JVM(Java Virtual Machine) is a Java interpreter which converts Java byte code to machine code.
(17) What are the two types of Java programs ?
Two types of Java programs are Java Applets and Java Applications.
(18) What is literal and its types ?
A constant value is known as a literal that never changes throughout the program. Six types of literals
are – Integer, Real, Boolean, Character, String and Null.
(19) What is a Package ?
A Package is a collection of classes.
(20) What is Type casting / conversion ?
It is the process of converting a data type to another data type.
1 ANJAN KUMAR NAYAK
FREQUENTLY ASKED QUESTIONS IN JAVA
(21) What is Implicit Type Casting or Coercion ?
It is the process of converting lower type data to higher type data automatically. Ex- int to double
(22) What is Explicit Type Casting ?
It is the process of converting higher type data to lower type data forcefully by the user. Ex- double to int
(23) What is an Expression ?
Expression is a combination of operators and operands.
(24) What are the two types of expressions ?
Pure expression contains same types of operands. Mixed expression contains different types of operands.
(25) What is fall-through ?
If a break statement is not used in a case then the control goes to next case and called as fall-through.
(26) Why is a class called object factory ?
A class can be used to create a number of same kinds of objects. Hence, it is also called as object factory.
(27) Why is Java platform-independent ?
Java uses byte code which is a machine independent code and that make it platform independent.
(28) What is JDK ?
JDK (Java Development Kit) is an environment to develop Java applications and Applets
(29) What is Java API ?
Java API (Application Programming Interface) is a set of classes and interfaces that performs basic programming
tasks.
(30) Name four features of Java ?
Object Oriented, Platform-independent, Secured and Robust.
(31) Which keyword is used to create an object in Java ?
The New keyword is used to create an object in Java.
(32) What is Syntax Error ?
The error occurs due to the grammatical error or punctuation mistake in the programming language.
(33) What is Logical Error ?
The error which occurs in the programming logic is known as logical error.
(34) What is Run Time Error ?
The error occurs at runtime when the compiler does not respond properly while executing a statement
(35) Difference between Unary and Binary operators ?
Unary operator is an arithmetic operator that operates on a single operand. But, binary operator is an
arithmetic operator that operates with two operands.
(36) Name the keyword used for a method that has no return type ?
void
(37) Name the keyword which makes the variable as a class variable ?
static
(38) Difference between Linear Search and Binary Search ?
A linear search is applicable to sorted as well as unsorted data items. But the binary search can takes
place only on sorted data items.
(39) Difference between Searching and Sorting ?
Searching is a system of finding an element among a list of elements. But, sorting is the term used to
arrange a list of elements in a specific order.
(40) What are the two ways of invoking a function ?
(i) Pass by value (ii) Pass by reference
2 ANJAN KUMAR NAYAK
FREQUENTLY ASKED QUESTIONS IN JAVA
(41) How are private members of a class are different from public members ?
A private member is only accessible within a class boundary, but a public member can be accessible
outside the class boundary.
(42) Why an object is called instance of a class ?
Each object of a particular class contains the instance variables declared within the class. Hence, object
is also known as instance of a class.
(43) Difference between next() and nextLine() ?
next() is used to accept a string as a word, but nextLine() accepts a string as a text line.
(44) Difference between formal parameter and actual parameter ?
A formal parameter is used along with the function name while defining a function to receive the value
passed from the caller. But, an actual parameter is the actual value passed to the formal parameter at
the time when a function is invoked.
(45) What is default constructor ?
A constructor that initializes the variables of an object with default initial values.
(46) What is parameterised constructor ?
A constructor that is used to initialize the variables of an object by passing parametric values.
(47) What is copy constructor ?
A constructor that copies the initial values of the instance variable of an object to another object.
(48) What is catch block ?
A catch block is used to report the compiler regarding any error that has occurred during program
execution.
(49) What is pure function ?
A function that doesn’t change the state of an object is called pure function & it always return a value.
(50) What is impure function ?
A function that changes the state of an object is called impure function and it may or may not return
any value.
(51) Name the keyword which is used to store the address of the currently calling object ?
this
(52) Which keyword is used to resolve the conflict between method parameter and instance variable ?
this
(53) Name the package that contains Scanner class ?
java.util.Scanner
(54) Which unit of the class is called, when the object of a class is created ?
Constructor
(55) What is ‘void’ ?
The keyword ‘void’ indicates that the function does not return any value to the caller program.
(56) Name the keyword that informs, that an error has occurred in an I/O (Input/output) operation ?
throws IOException
(57) Which keyword distinguishes instance variable and class variable ?
static
(58) Write a method that converts a string to a primitive integer data type ?
Integer.parseInt(String)
(59) Why a class is known as composite data type ?
A class may contain the data of various types. Hence, it is known as composite data type.
3 ANJAN KUMAR NAYAK
FREQUENTLY ASKED QUESTIONS IN JAVA
(60) Name the keyword that is used for allocating memory to an array ?
new
(61) Name the keyword that causes the control to transfer back to the method call ?
ruturn
(62) What is compound statement ?
When multiple statements are used within curly braces ‘{ }’, then they are known as compound
statements.
(63) How to pass an integer data type ?
Pass by value.
(64) How to pass an array data type ?
Pass by reference.
(65) What is break statement ?
Break statement is used to terminate the control and exits from the iterative loop.
(66) What is continue statement ?
Continue statement is used to returns the control for the next iteration ignoring the rest of the
statements.
(67) What is ‘default’ in a switch case ?
Default is a special case in a switch statement which is automatically invoked if no case matches.
(68) What is protected access specifier ?
When a class members are declared to be protected, then it will treated as private members for the
existing class but can be inherited to another class.
(69) Write any two components of method prototype ?
(i) Method name (ii) return type
(70) What is reusability ?
Using the same data items in multiple cases for different operations is called reusability.
(71) What error occurs, when an array does not have a cell which is likely to be used ?
Array out of bounce error.
(72) Difference between String and String Buffer type data ?
String type allocates fixed length in the memory but String buffer type allocates memory with the
length that is defined by the user.
(73) Name the term which is used to join two strings together ?
concatenation
(74) In what way polymorphism is used in Java Programming ?
Java adopts polymorphism by using function overloading.
(75)
4 ANJAN KUMAR NAYAK