You are on page 1of 8

Short questions

Support the statement “java byte code


gives high performance”
• When considering byte code Vs native, consider which trade-offs you want
to make between portability, security, size, and execution speed.
• If speed is the only important factor, go native.
• If any of the others are more important, go with byte code.
• Byte code can be transferred across a network and executed by Java
Virtual Machine (JVM) , which resides on any type of platform.
• But byte code allows you to execute a distributed application, which is
available on different machines, connected on network.
• Byte code does not allow malicious instructions (virus), because JVM
checks the byte code before execution.
• The size of instruction is small ( one byte), so any small processer can
execute it very fast.
• A group of Just-In-Time compilers are used to convert the byte code of
different parts of the program, into native machine code, in parallel.
• So, performance is not only measured with execution speed, we can
consider with other capabilities.
Inheritance Vs polymorphism
• Inheritance and polymorphism are two sides of a coin, in
object oriented programming.
• Inheritance in object oriented programming, allowed to
extend features from the existing super class to different
new subclasses. So inheritance is also considered as sub
type polymorphism.
• The same method in super class is overridden in difference
sub classes, known as method overriding is also called as
runtime polymorphism.
• Inheritance concentrates on reusability. Polymorphism
concentrates on flexibility or versatility.
• Up casting with interface reference variables is also known
as polymorphism with non related classes.
Abstraction Vs information hiding
• Abstraction is the act of defining the interface of
something.
• Information hiding means, hides the design details behind
a standard interface.
• Abstraction is a process of including features, attributes and
methods that are of interest to your application and ignore
the rest.
• Information hiding is restricting access to data attributes
and some methods, to make your application maintainable.
• Information hiding is one type of mechanism to protect the
data, using different access specifiers.
• Abstraction is a goal, achieved by different mechanisms
like encapsulation, inheritance and polymorphism.
Memory allocation for an object
• Heap is a section of memory which contains Objects and may also
contain reference variables.
• Instance variables are created in the heap.
• A unique no. is assigned to every created object which is called as
HashCode.
• Memory is allocated from heap to hold all instance variables.
• Static variables of an object will be stored in class area/method area.
• Super class object is created before sub class object, So, constructors
are called from base class to current class as per the class hierarchy.
• Later the implementation-specific data of the object and its super
classes are added.
• Implementation-specific data means it includes pointers to class and
method data.
• The new operator does the whole memory allocation task for you.
Characteristics of the static methods
• Static method(s) are associated to the class in which they reside in
the class.
• They can be called even without creating an instance of the class :
• i.e ClassName.methodName(args).
• They are designed with aim to be shared among all Objects created
from the same class.
• Static methods can not be overridden in the sub class.
• But static methods can be overloaded since they are resolved
using static binding by compiler at compile time.
• Static methods can access the static variables and static methods
directly.
• Static methods can’t access instance methods and instance
variables directly.
Array Vs Vector
• Arrays and Vectors in Java are different kinds of data structures for storing
information in a random-access fashion.
• Both are objects in java.
• Arrays in Java are static lists declared to store a certain number of a
certain kind of variables. It stores these values at specific, numbered
locations in a list that starts at zero and goes to N-1:
The key difference between Arrays and Vectors in Java is that Vectors are
dynamically-allocated.
• They aren't declared to contain a type of variable; instead, each Vector
contains a dynamic list of references to other objects.
• The Vector class is found in the java.util package, and extends
java.util.Abstractlist.
• Once an array object is created, the size of the array is fixed.
• The size of the vector can change as needed. Vectors handle these
changes through the "capacity" and "capacityIncrement" fields.
Garbage Collection
• In Java many objects are created as required, they should be deleted from memory
after their usage.
• The Java runtime environment deletes objects when it determines that they are no
longer required( identified as out of scope )
• Garbage Collection is process, which is a way to destroy the unused objects.
• To remove unused objects, we were using free() function in C language and
delete() in C++.
• But in java, garbage Collection is performed automatically. so the programmer
don't need to make extra efforts.
• It makes java memory efficient because garbage collector removes the
unreferenced objects from heap memory.
• An object can be unreferenced, because
• – a) By nulling the reference, b) By assigning a reference to another c) By
anonymous object etc
• finalize() method is called by garbage collection thread before collecting object..
• System.gc() method is used to call garbage collector explicitly.

You might also like