Fundamental of Java Programming Oral Question Bank
Fundamental of Java Programming Oral Question Bank
Unit 1
1. What are the features of java?
1. Simple
2. Object-Oriented
3. Portable
4. Platform independent
5. Secured
6. Robust
7. Architecture neutral
8. Interpreted
9. High Performance
10. Multithreaded
11. Distributed
12. Dynamic
2. Difference between JDK, JRE, and JVM.
JDK is abbreviated as Java Development Kit which has a physical existence. It can be considered as a kit
inside which resides the JRE along with developing tools within it. The programmers and developers
mostly use it.
JVM is abbreviated as Java Virtual Machine, is basically a dummy machine or you can say an
abstract machine which gives Java programmers a runtime environment for executing the Bytecode.
For each execution of your program, the JDK and JRE come into use, and they go within the JVM
to run the Java source code.
JRE is abbreviated as Java Runtime Environment, as the name suggests used as a package that gives
an environment to run the Java program on your machine
3. What is bytecode?
Bytecode is a highly optimized set of instructions designed to be executed by the java run-time system.
Which is called the java virtual machine (JVM). JVM is an interpreter for bytecode.
4. What is a variable? What are the different types of variables?
Variable are locations in the memory that can hold values. Java has three kinds of variable
namely,
Instance variable
Local variable
Class variable
Local variables are used inside blocks as counts or in methods as temporary variables. Once the
block or the method is executed, the variable ceases to exist. Instance variable are used to define
attributes or the state of a particular object. These are used to store information needed by multiple
methods in the objects.
5. What are the difference between static variable and instance variable?
The data or variables, defined within a class are called instance variables.
Instance variables declared as static are, essentially, global variables. When objects of its class are
declared, no copy of a static variable is made.
6.What are primitive datatypes in java?
There are 8 types of primitive data types:
1. boolean data type
2. byte data type
3. char data type
4. short data type
5. int data type
6. long data type
7. float data type
8. double data type
7. Define Array? How to declare an array?
Java array is an object which contains elements of a similar data type. It is a data structure where
we store similar elements. We can store only a fixed set of elements in a Java array.
There are two types of array.
1. Single Dimensional Array
2. Multidimensional Array
int a[]=new int[5];//declaration
8. List out the operator in Java.
1. Arithmetic Operators
2. Increment and Decrement Operators
3. Bitewise Operators
4. Relational Operators
5. Logical Operators
6. Assignment Operators
9.what is object?
An object is an instance of a class. A class is a template or blueprint from which objects are
created. So, an object is the instance(result) of a class.
1. An object is a real-world entity.
2. An object is a runtime entity.
3. The object is an entity which has state and behavior.
4. The object is an instance of a class.
10.Define Construcor?
Constructor in java is a special type of method that is used to initialize the object. Java
constructor is invoked at the time of object creation. It constructs the values i.e. provides data
for the object that is why it is known as constructor.
11. What are the Types of java constructors?
There are two types of constructors: 1. Default constructor (no-arg constructor) 2. Parameterized
constructor
12.What is meant by garbage collection?
It frees memory allocated to objects that are not being used by the program any more - hence the
name "garbage".In certain languages like C++, dynamically allocated objects must be manually
released by use of a delete operator. In Java deallocation happens automatically. The technique
that accomplishes this is called garbage collection.
13.Define method?
Methods are functions that operates on instances of classes in which they are defined. Objects can
communicate with each other using methods and can call methods in other classes. Just as there are
class and instance variable, there are class and instance methods. Instance methods apply and
operate on an instance of the class while class methods operate on the class.
14. What is the use of ‘this’ Keyword?
1. this can be used to refer current class instance variable.
2. this can be used to invoke current class method (implicitly)
3. this() can be used to invoke current class constructor.
4. this can be passed as an argument in the method call.
5. this can be passed as argument in the constructor call.
6. this can be used to return the current class instance from the method.
15. What gives java it’s “write once and run anywhere” nature?
All Java programs are compiled into class files that contain byte codes. These byte codes can be
run in any platform and hence java is said to be platform independent.
16. Why Java is Platform Independent.
Java is platform independent because it can run on any platform i.e on windows,mac etc. ...
Because it contains its own virtual machine which have JRE which runs java program as byte
code. You may have different JRE for differentplatforms .Once you installed it in your system you
can run any java application on it.
17. Why Java is Architecture-Neutral.
Java was designed to support applications on networks. To enable a Javaapplication to execute
anywhere on the network, the compiler generates anarchitecture-neutral object file format--the
compiled code is executable on many processors, given the presence of the Java runtime system
18 .What is finalize() method?
Finalize () method is used just before an object is destroyed and can be called just prior to garbage
collection
Unit-2
}
}
3. What are the uses of the keyword ‘final’?
• The class can be declared as final, if instances or subclasses are not to be created.
• The variables are declared as final, value of the variable must be provided at the time of
declaration.
• The Method can be declared as final indicating that they cannot be overridden by subclasses.
4. What are static methods?
Static methods and variables can be used independently of any object. To do so, you need only
specify the name of their class following by the dot operator.
5. What is inheritance?
In Object-Oriented programming, inheritance refers to the properties of a class being available to
many other classes. A derived class / sub class is one that has been created from an existing class.
Inheritance is the process of deriving a class from a super class or a base class. No changes are made
to the base class. The derived class has a larger set of properties that its base class. Inheritance has
two advantages
a) Reusability of code
b) Data and methods of a super class are physically available to its subclasses
6. What is the use of ‘Super’ Keyword? Give an example.
Usage of ‘super’ keyword’
1. The first calls the superclass constructor
2. To access a member of the superclass that has been hidden by a member of a subclass
7. Difference between method overloading and method overriding in java.
Overloading Overriding
Private, static and final methods can be Private, static and final methods can not be
overloaded. override.
UNIT-3
1. What is a package?
Packages contain a set of classes in order to ensure that class names are unique. Packages are
containers for classes that are used to compartmentalize the class name space. Packages are stored
in a hierarchical manner and are explicitly imported into new class definition. A period is used as
separator to enable this.
2. Write a note on import statement?
Classes external to a program be imported before they can be used. To import a class
the import keyword should be used as given below
import <classname>
The classes in Java are arranged in hierarchical order. The Java library consists of a number of
package. These package contain a set of related classes. The whole path of the class must be
specified to import a class from the Java library, For instance, to import the Data class from
the util package use the following code.
import java.util.Date;
It is also possible to import all classes that belong to a package using the * symbol.
3.Explain the usage of Java packages
This is a way to organize files when a project consists of multiple modules. It also helps resolve
naming conflicts when different packages have classes with the same names. Packages access
level also allows you to protect data from being used by the nonauthorized classes.
4. Define interface?
An interface is a collection of abstract behavior that individual classes can implement. It is defined
like a class. An interface consists of a set of method definition. Any class implementing it should
provide code for all its methods.
5 What is the useful of Interfaces?
a) Declaring methods that one or more classes are expected to implement
b) Capturing similarities between unrelated classes without forcing a class relationship.
c) Determining an object’s programming interface without revealing the actual body of the class.
1. Define an exception.
An exception is an abnormal condition, which occurs during the execution of a program Exceptions
are erroneous events like division by zero, opening of a file that does not exist, etc. A java execution
is an object, which describes the error condition that has materialized in the program.
2. How to access package from another package? [Remembering]
There are three ways to access the package from outside the package.
1. import package.*;
2. import package.classname;
3. fully qualified name.
3. What are the types of Exception in Java.
There are mainly two types of exceptions: checked and unchecked. Here, an error is considered as
the unchecked exception.
1. Checked Exception
2. Unchecked Exception.
4. Difference between Checked and Unchecked Exceptions
1) Checked Exception
The classes which directly inherit Throwable class except RuntimeException and Error are known
as checked exceptions e.g. IOException, SQLException etc. Checked exceptions are checked at
compile-time.
2) Unchecked Exception
The classes which inherit RuntimeException are known as unchecked exceptions e.g.
ArithmeticException, NullPointerException, ArrayIndexOutOfBoundsException etc. Unchecked
exceptions are not checked at compile-time, but they are checked at runtime
5. What are the keyword in Exception.
1. try
2. catch
3. throw
4. throws
5. finally
6. What is use of try block?
The "try" keyword is used to specify a block where we should place exception code. The try block
must be followed by either catch or finally. It means, we can't use try block alone.
7. What is catch block?
The "catch" block is used to handle the exception. It must be preceded by try block which means
we can't use catch block alone. It can be followed by finally block later.
8. What is use of ‘throw statement’ give an example? (or) state the purpose of the throw
statement.
Whenever a program does not want to handle exception using the try block, it can use the throws
clause. The throws clause is responsible to handle the different types of exceptions generated by the
program. This clause usually contains a list of the various types of exception that are likely to occur
in the program.
9. What is throws in java?
The Java throws keyword is used to declare an exception. It gives an information to the
programmer that there may occur an exception so it is better for the programmer to provide the
exception handling code so that normal flow can be maintained.
return_type method_name() throws exception_class_name{
//method code }
10. Difference between throw and throws
s.no throw throws
1 Java throw keyword is used to Java throws keyword is used to declare an
explicitly throw an exception. exception.
2 Checked exception cannot be Checked exception can be propagated with
propagated using throw only. throws.
11. What is finally in Java with example?
Java Finally Block Examples. The finally block always executes immediately after try-catch block
exits. The finally block is executed incase even if an unexpected exception occurs ..... The runtime
system always executes the code within the finallyblock regardless of what happens in the try
block.
12. What is the difference between error and exception?
An Error "indicates serious problems that a reasonable application should not try to catch."
An Exception "indicates conditions that a reasonable application might want to catch." Error along
with RuntimeException & their subclasses are uncheckedexceptions. All other Exception classes
are checked exceptions.
13. How does nested try catch work in Java? [ Analyzing]
Nested try catch blocks. Exception handlers can be nested within one another. Atry, catch or a
finally block can in turn contains another set of try catch finally sequence. In such a scenario,
when a particular catch block is unable to handle an Exception, this exception is rethrown.
UNIT-4
1. How to create Thread.
There are two ways to create a thread:
1. By extending Thread class
2. By implementing Runnable interface.