0% found this document useful (0 votes)
16 views16 pages

vvi

Uploaded by

ashish kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views16 pages

vvi

Uploaded by

ashish kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

1. What are the differences between C++ and Java?

Concept.

C++ is not platform-independent; the principle behind C++ programming is “write


once, compile anywhere.”

In contrast, because the byte code generated by the Java compiler is platform-
independent, it can run on any machine, Java programs are written once and run
everywhere.

Languages Compatibility.

C++ is a programming language that is based on the C programming language. Most


other high-level languages are compatible with C++.

Most of the languages of Java are incompatible. Java is comparable to those of C and
C++.

Interaction with the library.

It can access the native system libraries directly in C++. As a result, it’s better for
programming at the system level.

Java’s native libraries do not provide direct call support. You can use Java Native
Interface or access the libraries.

Characteristics.

C++ distinguishes itself by having features that are similar to procedural and object-
oriented languages. The characteristic that sets Java apart is automatic garbage
collection. Java doesn’t support destructors at the moment.

The semantics of the type.

Primitive and object types in C++ have the same kind of semantics. The primitive and
object and classes of Java, on the other hand, are not consistent.

In the context of Compiler and Interpreter.

Java refers to a compiled and interpreted language. In contrast, C++ is only a


compiled language.

In Java, the source code is the compiled output is a platform-independent byte code.

In C++, the source program is compiled into an object code that is further executed to
produce an output
2. List the features of the Java Programming language?

A few of the significant features of Java Programming Language are:

Easy: Java is a language that is considered easy to learn. One fundamental concept of
OOP Java has a catch to understand.

Secured Feature: Java has a secured feature that helps develop a virus-free and
tamper-free system for the users.

OOP: OOP stands for Object-Oriented Programming language. OOP signifies that, in
Java, everything is considered an object.

Independent Platform: Java is not compiled into a platform-specific machine; instead,


it is compiled into platform-independent bytecode. This code is interpreted by the
Virtual Machine on which the platform runs.

3. What do you get in the Java download file? How do they


differ from one another?

We get two major things along with the Java Download file.

JDK - Java Development Kit

JRE - Java Runtime Environment

JDK JRE
Abbreviation for JavaDevelopment
Abbreviation for Java Runtime Environment
Kit
JDK is a dedicated kit for solely JRE is a set of software and library designed
software development for executing Java Programs
Unlike JVM, JDK is Platform
Unlike JVM, JRE is also Platform Dependent
Dependent
JDK package is a set of tools for JRE Package is one that only supports files and
debugging and Developing libraries for a runtime environment
JDK package will be provided with JRE Package does not get an installer but has
an installer file only a runtime environment

4. What is a ClassLoader?

A classloader in Java is a subsystem of Java Virtual Machine, dedicated to loading


class files when a program is executed; ClassLoader is the first to load the executable
file. Java has Bootstrap, Extension, and Application classloaders.
5. What are the Memory Allocations available in JavaJava?

Java has five significant types of memory allocations.

 Class Memory
 Heap Memory
 Stack Memory
 Program Counter-Memory
 Native Method Stack Memory

6. What are the differences between Heap and Stack Memory in


Java?

Stack memory in data structures is the amount of memory allocated to each individual
programme. It is a fixed memory space. Heap memory, in contrast, is the portion that
was not assigned to the Java code but will be available for use by the Java code when
it is required, which is generally during the program's runtime.

7. Will the program run if we write static public void main?

Yes, the program will successfully execute if written so. Because, in Java, there is no
specific rule for the order of specifiers

8. What is the default value stored in Local Variables?

Neither the Local Variables nor any primitives and Object references have any default
value stored in them.

9. Explain the expected output of the following code segment?

public class Simplilearn

{ public static void main (String args[])

{ System.out.println(100 + 100 +“Simplilearn");

System.out.println(“E-Learning Company" + 100 + 100);

} }

The answers for the two print statements are as follows.

 200Simplilearn
 E-Learning Company100100
10. What is an Association?

An Association can be defined as a relationship that has no ownership over another.


For example, a person can be associated with multiple banks, and a bank can be
related to various people, but no one can own the other.

11. What do you mean by aggregation?

The term aggregation refers to the relationship between two classes best described as
a “whole/part” and “has-a” relationship. This kind is the most specialized version of
an association relationship. It contains the reference to another class and is said to
have ownership of that class.

12. Define Copy Constructor in Java

A Copy Constructor in Java is a constructor that initializes an object through another


object of the same class.

13. What is a Marker Interface?

An empty interface in Java is referred to as a Marker interface. Serializable and


Cloneable are some famous examples of Marker Interface.

14. What is Object Cloning?

An ability to recreate an object entirely similar to an existing object is known as


Object Cloning in Java. Java provides a clone() method to clone a current object
offering the same functionality as the original object.

15. Can Java be said to be the complete object-oriented


programming language

No, Java cannot be treated as a complete object-oriented programming language.

16. What is an object-oriented paradigm?

A Paradigm that is based on the concepts of “Objects.” It contains data and code. Data
that is in the form of fields, and regulation, that is in the form of procedures. The
exciting feature of this paradigm is that the object’s procedures can access and often
modify the data fields themselves.

17. Define Wrapper Classes in Java.

In Java, when you declare primitive datatypes, then Wrapper classes are responsible
for converting them into objects(Reference types).
18. What is a singleton class in Java? And How to implement a
singleton class?

A class that can possess only one object at a time is called a singleton class. To
implement a singleton class given steps are to be followed:

1. Make sure that the class has only one object


2. Give global access to that object

19. Define package in Java.

The package is a collective bundle of classes and interfaces and the necessary libraries
and JAR files. The use of packages helps in code reusability.

20. Can you implement pointers in a Java Program?

Java Virtual Machine takes care of memory management implicitly. Java's primary
motto was to keep programming simple. So, accessing memory directly through
pointers is not a recommended action. Hence, pointers are eliminated in Java.

21. Differentiate between instance and local variables.

For instance, variables are declared inside a class, and the scope of variables in
javascript is limited to only a specific object.

A local variable can be anywhere inside a method or a specific block of code. Also,
the scope is limited to the code segment where the variable is declared.

22. Explain Java String Pool.

A collection of strings in Java's Heap memory is referred to as Java String Pool. In


case you try to create a new string object, JVM first checks for the presence of the
object in the pool. If available, the same object reference is shared with the variable,
else a new object is created.

23. What is an Exception?

An Exception handling in Java is considered an unexpected event that can disrupt the
program's normal flow. These events can be fixed through the process of Exception
Handling.

24. What is the final keyword in Java?


The term final is a predefined word in Java that is used while declaring values to
variables. When a value is declared using the final keyword, then the variable's value
remains constant throughout the program's execution.

25. What happens when the main() isn't declared as static?

When the main method is not declared as static, then the program may be compiled
correctly but ends up with a severe ambiguity and throws a run time error that reads
"NoSuchMethodError."

26. Why is Java a platform independent language?

One of the most well-known and widely used programming languages is Java. It is a
programming language that is independent of platforms. Java doesn't demand that the
complete programme be rewritten for every possible platform. The Java Virtual
Machine and Java Bytecode are used to support platform independence. Any JVM
operating system can run this platform-neutral byte code. The application is run after
JVM translates the byte code into machine code. Because Java programmes can
operate on numerous systems without having to be individually rewritten for each
platform, the language is referred to as "Write Once, Run Anywhere" (WORA).

27. Why is the main method static in Java?

Java's main() function is static by default, allowing the compiler to call it either before
or after creating a class object. The main () function is where the compiler begins
programme execution in every Java programme. Thus, the main () method needs to be
called by the compiler. If the main () method is permitted to be non-static, the JVM
must instantiate its class when calling the function.

28. What part of memory - Stack or Heap - is cleaned in the


garbage collection process?

On Heap memory, garbage collection is employed to release the memory used by


objects with no references. Every object created in the Heap space has access to the
entire application and may be referred to from anywhere.

29. What is the difference between the program and the


process?

A programme is a non-active entity that includes the collection of codes necessary to


carry out a specific operation. When a programme is run, an active instance of the
programme called a process is launched. A process is begun by a programme once it
has been run. The process carries out the program's specified instructions.

30. What are the differences between constructor and method


of a class in Java?
Initializing the state of the object is done by constructors. A function Object ()
{ [native code] }, like methods, contains a group of statements (or instructions) that
are carried out when an object is created. A method is a group of statements that work
together to complete a certain task and return the outcome to the caller. A method has
the option of working without returning anything.

31. Which among String or String Buffer should be preferred


when there are a lot of updates required to be done in the
data?

Because StringBuilder is quicker than StringBuffer, it is advised to utilize it wherever


possible. However, StringBuffer objects are the best choice if thread safety is required.

32. What happens if the static modifier is not included in


the main method signature in Java?

The main function is called by the JVM even before the objects are created, thus even
if the code correctly compiles, there will still be an error at runtime.

33. Can we make the main() thread a daemon thread?

This technique designates whether the active thread is a user thread or a daemon
thread. For instance, tU.setDaemon(true) would convert a user thread named tU into a
daemon thread. On the other side, executing tD.setDaemon(false) would convert a
Daemon thread, tD, into a user thread.

34. What happens if there are multiple main methods inside


one class in Java?

There is no limit to the number of major approaches you can use. Overloading is the
ability to have main methods with different signatures than main (String []), and the
JVM will disregard those main methods.

35. How does an exception propagate in the code?

In the event that an exception is not caught, it is initially thrown from the top of the
stack and then moves down the call stack to the preceding method. The runtime
system looks for a way to handle an exception that a method throws. The ordered list
of methods that were called to get to the method where the error occurred is the
collection of potential "somethings" that can be used to manage the exception. The
call stack is the list of methods, and exception propagation is the search technique.

36. How do exceptions affect the program if it doesn't handle


them?

If you don't deal with an exception once it occurs, the programme will end abruptly
and the code after the line where the exception occurred won't run.
37. Is it mandatory for a catch block to be followed after a
try block?

Each attempt block does not necessarily have to be followed by a catch block. Either a
catch block or a final block ought to come after it. Additionally, any exceptions that
are expected to be thrown should be mentioned in the method's throws clause.

38. Can you call a constructor of a class inside another


constructor?

Yes, a class may include any number of constructors, and each function Object ()
{[native code] } may call the others using the this() function Object() { [native code] }
call function [please do not mix the this() function Object() { [native code] } call
function with this keyword]. The constructor's first line should be either this () or
this(args). Overloading of constructors is what this is called.

39. Contiguous memory locations are usually used for storing


actual values in an array but not in ArrayList. Explain.

Primitive data types like int, float, and others are typically present in an array. In such
circumstances, the array immediately saves these elements at contiguous memory
regions. While an ArrayList does not contain primitive data types. Instead of the
actual object, an ArrayList includes the references to the objects' many locations in
memory. The objects are not kept in consecutive memory regions because of this.

40. Why does the java array index start with 0?

The distance from the array's beginning is just an offset. There is no distance because
the first element is at the beginning of the array. Consequently, the offset is 0.

41. Why is the remove method faster in the linked list than
in an array?

Because there is no background scaling of an array, insertion, addition, and removal


operations are quicker with a LinkedList. Only references in adjacent items need to
update when a new item is added in the middle of the list.

42. How many overloaded add() and addAll() methods are


available in the List interface? Describe the need and uses.

List is an interface in the Java Collections Framework. The add() and addAll()
methods are the main methods at the List interface. The add() method is used to
add an element to the list, while the addAll() method is used to add a collection of
elements to the list.

The List interface contains two overloaded versions of the add() method:
The first add() method accepts a single argument of type E, the element to be added to
the list.

The second add() method accepts a variable number of arguments of type E, which
are the elements to be added to the list.

The List interface also contains two overloaded versions of the addAll() method:

The first addAll() method accepts a single argument of type Collection<? Extends E>,
which is the collection of elements to be added to the list.

The second addAll() method accepts a variable number of arguments of type E, which
are the elements to be added to the list.

43. How does the size of ArrayList grow dynamically? And also
state how it is implemented internally?

A resizable array implementation in Java is called ArrayList. Dynamically expanding


array lists make it possible to add new elements at any time. The underlying data
structure of the ArrayList is an array of the Object class. The ArrayList class in Java
has three constructors. There are available readObject and writeObject methods
specific to it. The Object Array in an ArrayList is temporary. There are implemented
and Serialization-capable versions of RandomAccess, Cloneable, and java.io (that are
Marker Interface in Java).

44. Although inheritance is a popular OOPs concept, it is


less advantageous than composition. Explain.

A class's testability is improved through composition over inheritance. If a class is


comprised of another class, it is simple to create a mock object to simulate the
combined class for testing purposes. This privilege is not given by inheritance. Even
while Composition and Inheritance both let you reuse code, Inheritance has the
drawback of breaking encapsulation. If the function of the subclass depends on the
superclass's action, it suddenly becomes vulnerable. Sub-class functionality may be
broken without any alteration on the part of the super-class when its behaviour
changes.

45. What are Composition and Aggregation? State the


difference.

Aggregation (HAS-A) and composition are its two forms (Belongs-to). In contrast to
composition, which has a significant correlation, the aggregation has a very modest
association. Aggregation can be thought of as a more confined version of the
composition. Since all compositions are aggregates but not all aggregates are
compositions, aggregate can be thought of as the superset of composition.

46. How is the creation of a String using new() different


from that of a literal?
The new () operator always produces a new object in heap memory when creating a
String object. The String pool may return an existing object if we build an object
using the String literal syntax, such as "Baeldung," on the other hand.

47. How is the ‘new' operator different from the


‘newInstance()' operator in java?

Both the new operator and the newInstance() method are used to create objects in Java.
If we already know the kind of object to create, we can use the new operator; however,
if the type of object to create is supplied to us at runtime, we must use the
newInstance() function.

48. Is exceeding the memory limit possible in a program


despite having a garbage collector?

Yes, even with a garbage collector in place, the programme could still run out of
memory. Garbage collection aids in identifying and removing programme objects that
are no longer needed in order to release the resources they use. When an object in a
programme cannot be reached, trash collection is executed with respect to that object.
If there is not enough memory available to create new objects, a garbage collector is
used to free up memory for things that have been removed from the scope. When the
amount of memory released is insufficient for the creation of new objects, the
program's memory limit is exceeded.

49. Why is synchronization necessary? Explain with the help


of a relevant example.

Multiple threads trying to access the same resources in a multi-threaded software may
frequently result in unexpected and incorrect outcomes. Therefore, it must be ensured
through some form of synchronization that only one thread can access the resource at
any given time. Java offers a method for setting up threads and synchronizing their
operations with the aid of synchronized blocks. The synchronized keyword in Java is
used to identify synchronized blocks. In Java, a synchronized block is one that is tied
to an object. Only one thread can be running at a time inside synchronized blocks
since they are all synchronized on the same object. Until the thread inside the
synchronized block exits the block, all other threads trying to enter the block are
blocked.

50. Define System.out.println().

System.out.println() in Java outputs the argument that was supplied to it. On the
monitor, the println() method displays the findings. An objectname is typically used to
call a method.
What is JDK? Mention the variants of JDK?

JDK is an abbreviation for Java Development Kit. It is a combined Package of JRE


and Developer tools used for designing Java Applications and Applets. Oracle has the
following variants.

 JDK Standard Edition


 JDK Enterprise Edition
 JDK Micro Edition

77. What is the difference between JDK, JRE, and JVM?

JVM has a Just in Time (JIT) compiler tool that converts all the Java source code into
the low-level compatible machine language. Therefore, it runs faster than the regular
application.

JRE has class libraries and other JVM supporting files. But it doesn’t have any tool
for java development such as compiler or debugger.

JDK has tools that are required to write Java Programs and uses JRE to execute them.
It has a compiler, Java application launcher, and an applet viewer.

78. What is a JIT compiler?

JIT compiler refers to Just in Time compiler. It is the simplest way of executing the
computer code that takes in compilation during the execution of a program rather than
before performance. It commonly uses bytecode translation to machine code. It is then
executed directly.

79. What are Brief Access Specifiers and Types of Access


Specifiers?

Access Specifiers are predefined keywords used to help JVM understand the scope of
a variable, method, and class. We have four access specifiers.

 Public Access Specifier


 Private Access Specifier
 Protected Access Specifier
 Default Access Specifier

80. How many types of constructors are used in Java?

There are two types of constructors in Java.

Parameterized Constructors: Parameterized constructor accepts the parameters with


which users can initialize the instance variables. Users can initialize the class
variables dynamically at the time of instantiating the class.
Default constructors: This type doesn’t accept any parameters; rather, it instantiates
the class variables with their default values. It is used mainly for object creation.

81. Can a constructor return a value?

Yes, A constructor can return a value. It replaces the class's current instance implicitly;
you cannot make a constructor return a value explicitly.

82. Explain ‘this’ keyword in Java.

The term "this" is a particular keyword designated as a reference keyword. The "this"
keyword is used to refer to the current class properties like method, instance, variable,
and constructors.

83. Explain ‘super’ keyword in Java.

The term "super" is a particular keyword designated as a reference keyword. The


"super" keyword refers to the immediate parent class object.

84. Explain Method Overloading in Java.

The process of creating multiple method signatures using one method name is called
Method Overloading in Java. Two ways to achieve method overloading are:

1. Varying the number of arguments


2. Changing the return type of the Method

85. Can we overload a static method?

No, Java does not support the Overloading of a static method. The process would
throw an error reading "static method cannot be referenced."

86. Define Late Binding.

Binding is a process of unifying the method call with the method's code segment. Late
binding happens when the method's code segment is unknown until it is called during
the runtime.

87. Define Dynamic Method Dispatch.

The Dynamic method dispatch is a process where the method call is executed during
the runtime. A reference variable is used to call the super-class. This process is also
known as Run-Time Polymorphism.

88. Why is the delete function faster in the linked list than
an array?
Delete Function is faster in linked lists in Java as the user needs to make a minor
update to the pointer value so that the node can point to the next successor in the list

89. Give a briefing on the life cycle of a thread.

The life cycle of a thread includes five stages, as mentioned below.

1. New Born State


2. Runnable State
3. Running State
4. Blocked State
5. Dead State

90. Explain the difference between >> and >>> operators.

Although they look similar, there is a massive difference between both.

 >> operator does the job of right shifting the sign bits
 >>> operator is used in shifting out the zero-filled bits

91. Brief the life cycle of an applet.

The life cycle of an applet involves the following.

1. Initialization
2. Start
3. Stop
4. Destroy
5. Paint

92. Why are generics used in Java Programming?

Compile-time type safety is provided by using generics. Compile-time type safety


allows users to catch unnecessary invalid types at compile time. Generic methods and
classes help programmers specify a single method declaration, a set of related
methods, or related types with an available class declaration.

93. Explain the Externalizable interface.

The Externalizable interface helps with control over the process of serialization. An
"externalisable" interface incorporates readExternal and writeExternal methods.

94. What is the Daemon Thread?

The Daemon thread can be defined as a thread with the least priority. This Daemon
thread is designed to run in the background during the Garbage Collection in Java.

The setDaemon() method creates a Daemon thread in Java.


95. Explain the term enumeration in Java.

Enumeration or enum is an interface in Java. Enum allows the sequential access of the
elements stored in a collection in Java.

96. Why is Java is Dynamic?

Java is designed to adapt to an evolving environment. Java programs include a large


amount of runtime information that is used to resolve access to objects in real-time.

97. Can you run a code before executing the main method?

Yes, we can execute any code, even before the main method. We will be using a static
block of code when creating the objects at the class's load time. Any statements within
this static block of code will get executed at once while loading the class, even before
creating objects in the main method.

98. How many times is the finalize method called?

The finalize method is called the Garbage collector. For every object, the Garbage
Collector calls the finalize() method just for one time.

Java Interview Questions for Experienced


Now, lets move on to our last section of Advanced Core Java Interview Questions
which is primarly useful for experienced and working professionals.

99. Can "this" and "super" keywords be used together?

No, "this" and "super" keywords should be used in the first statement in the class
constructor. The following code gives you a brief idea.

public class baseClass {

baseClass() {

super();

this();

System.out.println(" baseClass object is created");

public static void main(String []args){

baseClass bclass = new baseClass();


}

100. What is a JSP page?

JSP is an abbreviation for Java Servlet Page. The JSP page consists of two types of
text.

 Static Data
 JSP elements

Find Our Java Training in Top Cities

India United States Other Countries


Java Training in
Java Training New York Java Course London
Bangalore
Java Training San Java Course
Java Training in Chennai
Diego Singapore
Java Training in Java Course
Java Training Dallas
Hyderabad Melbourne

101. What is JDBC?

JDBC is an abbreviation for Java Database Connector.

JDBC is an abstraction layer used to establish connectivity between an existing


database and a Java application

102. Explain the various directives in JSP.

Directives are instructions processed by JSP Engine. After the JSP page is compiled
into a Servlet, Directives set page-level instructions, insert external files, and define
customized tag libraries. Directives are defined using the symbols below:

start with "< %@" and then end with "% >"

The various types of directives are shown below:

 Include directive

It includes a file and combines the content of the whole file with the currently active
pages.

 Page directive
Page Directive defines specific attributes in the JSP page, like the buffer and error
page.

 Taglib

Taglib declares a custom tag library, which is used on the page.

103. What are the observer and observable classes?

Objects that inherit the "Observable class" take care of a list of "observers."

When an Observable object gets upgraded, it calls the update() method of each of its
observers.

After that, it notifies all the observers that there is a change of state.

The Observer interface gets implemented by objects that observe Observable objects.

You might also like