Day 1 Viva
Day 1 Viva
Day 1 Viva
1) Simple
Simple syntax. No pointers, no multiple
inheritance with the classes which causes
ambiguity error. For almost every task API
(Application Programming Interface) is
available; Programmer just need to know how
to use that API.
2) Object Oriented
Java is strong object oriented as it does not
allow features like global data, friend function
which are against OOP principles.
3) Robust
Robust means strong. Java puts a lot of
emphasis on early checking for possible errors,
as Java compilers are able to detect many
problems that would first show up during
execution time in other languages.
It provides the powerful exception handling and
type checking mechanism as compare to other
programming languages.
4) Platform Independent
Unlike other programming languages such as
C, C++ etc which are compiled into platform
specific machines. Java is guaranteed to be
compile-once, run-anywhere language.
On compilation Java program is compiled into
bytecode. This bytecode is platform
independent and can be run on any machine.
Any machine with Java Runtime Environment
can run Java Programs.
5)
Secure
If a bytecode contains any virus or malicious
code, JVM will not execute it. This features
saves your system especially when u download
java code and try to execute.
6) Multi Threading
Java multithreading feature makes it possible to
write program that can do many tasks
simultaneously.
7) Portable
Java Byte code can be carried to any platform.
8) Architectural Neutral
No implementation dependent features.
Everything related to storage is predefined,
example: size of primitive data types is same on
all the platforms.
8) High Performance
Java enables high performance with the use of
Just-In-Time (JIT) compiler.
4)How java is platform independent ?
Ans:- Java program, once compiled , can be run on
any platform without recompiling.
5) is Java Pure-Object oriented Language ?
Ans:- No. Java is not because it supports Primitive
datatype[^] such as int, byte, long... etc, to be used,
which are not objects.
lambda expressions
java fx
method reference
stream api
Nashorn engine
It is:
1.A specification where working of Java
Virtual Machine is specified. But
implementation provider is independent to
choose the algorithm. Its implementation
has been provided by Sun and other
companies.
Verifies code
Executes code
Several parts
Loading
Linking
Initializing
a) Loading
BootStrap class loader
Load classes from “rt.jar” ie. All core
java API classes are loaded.
Extension class loader
Loads classes from “ext” folder.
Application class loader
Loads classes from application level class
path – set inside environment
b)Linking
Verify
BytecodeVerifier is going to check whether
ur generated bytecode is proper or not. Ie.
Whether it contains any virus or malicious code
and whether class file format is compatible with
JVM class specification. If verification fails then
we will get “Verify Error”. Java program is always
secure. You can execute on any machine happily
because Bytecode Verifier is going to take care
,is it valid or not.
Prepare
For static variables memory will be
allocated and assigned with the default values.
( not the values u have initialized with)
Resolve
All symbolic references are replaced with
original references from “Method Area”.
Suppose u have references to other classes,
these are changed from symbolic to the actual
reference
c) Initialization
Static variables are assigned with the values u have
initialized. Static blocks are executed in the textual
order.
After Initialization only “class loading” completed
successfully by “Class Loader SubSystem”.
ClassNotFoundException :- happens when class
loader fails to find the bytecodes correspond to a
class we mention.
ClassDefNotFoundException:- happens during a
“Resolve” phase. E.g if we say
Java X
Now X will be loaded, verified , prepared. Next
step is resolve. Suppose class X contains reference of
class Y, resolve phase will try to find out Y.class. if
class Y can not be found exception will be thrown
“ClassDefNotFoundException” for X which wraps
“ClassNotFoundException” for Y.
public class X
{
Y ref;
public static void main(String args[])
{
X ob=new X();
ob.ref=new Y();
}
}
class Y
{
}
when u say
java Sample.class, Sample.class is an input to
“ClassLoaderSubsytem”.
In short, ClassLoaderSubsytem is responsible to load our
classes. In order to load the classes, some memory is
required.
There are various Runtime DataAreas present inside
JVM.
a) Method area:- will consists of following things:
class bytecode
class loader who loads the class information
reference to class Class
static variables
various literals (String,Integer,float etc)
Type Information
For each type it loads, a Java virtual machine must
store the following kinds of information in the
method area:
• The fully qualified name of the type
• The fully qualified name of the type's direct
superclass (unless the type is an interface or class
java.lang.Object, neither of which have a superclass)
• Whether or not the type is a class or an
interface
• The type's modifiers ( some subset of` public,
abstract, final)
• An ordered list of the fully qualified names of
any direct super-interfaces
Method Information
For each method declared in the type, the following
information must be stored in the method area. As
with fields, the order in which the methods are
declared by the class or interface must be recorded
as well as the data. Here's the list:
• The method's name
• The method's return type (or void)
• The number and types (in order) of the
method's parameters
• The method's modifiers (some subset of public,
private, protected, static, final, synchronized, native,
abstract)
method tables
Execution engine:-
execution area will communicate with “Memory
areas”.
i.e. once a data area is loaded which is an instruction
to be executed, i.e. current instruction to be
executed is ready ( using PC register) what happens
is that “Java Interpreter” interprets the current
instruction that is there in the bytecode and
executes it.
Execution Engine has 4 components
(i) Interpreter (ii) JIT Compiler (iii) HotSpot
profiler (iv) GC
Interpreter takes bytecode instruction, looks at it
finds out what native operation to be done and
executes that native operation. That is done by using
“native interface” which interfaces the native
libraries which are present in the JVM. If u look at
the JRE bin folder, and if u r on windows u will see lot
of dll files. So those are the platform specific native
libraries used by the Execution Engine. If u r on unix
system or linux system u will see “.so” files inside JRE
bin folder which is the native library.
They allow lot of optimizations in Execution Engine
so java is fast today. E.g JIT Just in time compiler is,
what it does if we have certain instructions which are
executed all the time again and again those will not
be interpreted again and again. Instead what
happens is the JIT compiler will on the fly compiles
these set of instructions and keeps the target
machine code ready for execution. So there is no
more interpretation involved here. Its only machine
code execution when u know there are so called
“HotSpots” that are repeating in the application so,
that what the HotSpot profiler does it keeps an eye
on bytecodes which are running and grabs lot of
different statistics that are useful in various formats.
So that is the role of HotSpot profiler. e.g. it helps JIT
Compiler to compile frequently used bytecode
instructions.
Inside Execution engine two main imp. Parts are
there:
a) Interpreter
Read , interpret and execute java bytecode line by
line.
b)JIT compiler
For example:
java Test
Invoke Test.main
Finally, after completion of the initialization for class Test
(during which other consequential loading, linking, and
initializing may have occurred), the method main of Test
is invoked.