Java Iq
Java Iq
---------*********---------
TEJAS PATIL
JAVA DEVELOPER
1
JavaITan’s
Contents
What is Java ? ............................................................................................................................................... 4
b) Heap:.............................................................................................................................................. 10
c) Stack:.............................................................................................................................................. 10
What is the difference between Java compiler ( javac ) and JIT ? ............................................................. 11
1) When does an Object becomes eligible for Garbage collection in Java ?........................................... 12
2
JavaITan’s
Can we define more than one public class in a java source code ? what is the rule of public class and
file name . ? ................................................................................................................................................. 13
U have reference type as a member of class. What is the default value it gets ? ........................................ 15
In a java source code there are 3 classes define e.g class A{} class B{} and class C{}. When u
compile the source code how many .class files u get and what are their names ? ...................................... 15
What are the technologies come under “Distributed Object System “ ? ..................................................... 16
What do u mean by Java Enabled Browser, Web Server and Application Server ? .................................. 16
3
JavaITan’s
What is Java ?
Answer:- Java technology is both a programming language and a platform from
Oracle Corporation.
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.
b) Object Oriented
Java is strong object oriented as it does not allow features like global data, friend function
which are against OOP principles.
4
JavaITan’s
d) Robust
Robust means reliable and no programming language can really assure reliability. 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.
e) 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.
f) Secure
When it comes to security, Java is always the first choice. With java secure features it enable
us to develop virus free, temper free system.
g) Multi Threading
Java multithreading feature makes it possible to write program that can do many tasks
simultaneously. Benefit of multithreading is that it utilizes same memory and other resources
to execute multiple threads at the same time, like While typing, grammatical errors are
checked along.
5
JavaITan’s
h) Portable
i) Architectural Neutral
j) High Performance
Java enables high performance with the use of Just-In-Time (JIT) compiler.
There are seven qualities to be satisfied for a programming language to be pure Object
Oriented. They are:
➢ Encapsulation/Data Hiding
➢ Inheritance
➢ Polymorphism
➢ Abstraction
➢ All predefined types are objects
➢ All operations are performed by sending messages to objects
➢ All user defined types are objects.
6
JavaITan’s
What is JVM ?
Answer:- A Java virtual machine (JVM), an implementation of the Java Virtual
Machine Specification, interprets compiled Java binary code (called bytecode) for a
computer's processor (or "hardware platform") so that it can perform a Java program's
instructions.
in other words,The Java Virtual machine (JVM) is the virtual machine that run the
Java bytecodes.
7
JavaITan’s
BootStrap class loader loads those classes which are essential for JVM to function
properly. BootStrap class loader is responsible for loading all core java classes for instance
java.lang.* ,java.io.* etc. BootStrap class loader finds these necessary classes from
“jdk/jre/lib/rt.jar” .
8
JavaITan’s
9
JavaITan’s
a) Class(Method) Area:
Class(Method) Area stores per-class structures such as the runtime constant pool, field and
method data, the code for methods.
b) Heap:
c) Stack:
Java Stack stores frames.It holds local variables and partial results, and plays a part in
method invocation and return.
Each thread has a private JVM stack, created at the same time as thread.
A new frame is created each time a method is invoked. A frame is destroyed when its
method invocation completes.
PC (program counter) register. It contains the address of the Java virtual machine instruction
currently being executed.
• Answer:- Interpreter: Reads, interprets and executes the bytecode instructions one
by one. As it interprets and executes instructions one by one, it can quickly interpret
one bytecode, but slowly executes the interpreted result. This is the disadvantage of
the interpreter.
• JIT (Just-In-Time) compiler: The JIT compiler has been introduced to compensate
for the disadvantages of the interpreter. The JIT compiler compiles the entire
bytecode to change it to native code. Execution in native code is much faster than
10
JavaITan’s
interpreting instructions one by one. The compiled code can be executed quickly since
the native code is stored in the cache.
However, it takes more time for JIT compiler to compile the code than for the interpreter to
interpret the code one by one. Therefore, if the code is to be executed just once, it is better to
interpret it instead of compiling. Therefore, the JVMs that use the JIT compiler internally
check how frequently the method is executed and compile the method only when the
frequency is higher than a certain level.
11
JavaITan’s
12
JavaITan’s
Can we define more than one public class in a java source code ? what is
the rule of public class and file name . ?
Answer:- no we can’t define more than one public class in one source file. Name of the
public class and the file name must match.
13
JavaITan’s
There are mainly 5 type of applications that can be created using java:
a) Standalone Application
b) Applet
14
JavaITan’s
c) Web Application
An application that runs on the server side and creates dynamic page, is called web
application. Currently, servlet, jsp, struts, jsf etc. technologies are used for creating
web applications in java.
d) Enterprise Application
An application that is distributed in nature, such as banking applications etc. It has the
advantage of high level security, load balancing and clustering. In java, EJB is used
for creating enterprise applications.
e) Mobile Application
An application that is created for mobile devices. Currently Android and Java ME are
used for creating mobile applications.
In a java source code there are 3 classes define e.g class A{} class B{} and
class C{}. When u compile the source code how many .class files u get and
what are their names ?
Ans:- A.class, B.classs, C.class
15
JavaITan’s
java.lang.UnsupportedClassVersionError occurs.
A Java virtual machine starts execution by invoking the method main of some specified class,
passing it a single argument, which is an array of strings if provided else an empty array.
For example:
java Test
will typically start a Java virtual machine by invoking method main of class Test .
16
JavaITan’s
Verification checks that the loaded representation of Test is well-formed, with a proper
symbol table. Verification also checks that the code that implements Test obeys the semantic
requirements of the Java programming language and the Java virtual machine. If a problem is
detected during verification, then an error is thrown.
Preparation involves allocation of static storage and any data structures that are used
internally by the virtual machine, such as method tables.
Resolution is the process of checking symbolic references from Test to other classes and
interfaces, by loading the other classes and interfaces that are mentioned and checking that
the references are correct.
Resolution can be either “lazy (in case of non-static references)” or “early (in case of static
references)”.
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.
The method main must be declared public, static, and void. It must accept a single argument
that is an array of strings. This method can be declared as either public static void
main(String[] args)
Or public static void main(String... args)
Loading of Classes and Interfaces which are referenced from main() function………
17
JavaITan’s
THANK YOU
18