Professional Documents
Culture Documents
Polymorphism
Ability to take more than one form, In java we achieve this using Method
Overloading (compile time polymorphism), Method overriding (runtime
polymorphism)
Inheritance
Is the process by which one object acquires the properties of another object.
Encapsulation
Wrapping of data and function into a single unit called encapsulation. Ex:- all java
programs.
Abstraction
Nothing but representing the essential futures without including background
details.
Dynamic binding
Code associated with a given procedural call is not known until the time of the
call at runtime. Dynamic binding is nothing but late binding.
Q) System.out.println()
println() is a methd of◊ java.io.printWriter.
“out” is an instance variable of java.lang.System◊ class.
Q) Default Values
0L◊ -2^63 to 2^63 –1 ◊long
◊ -2^31 to 2^31 –1 ◊Int 0
0◊ -2^15 to 2^15 –1 ◊Short
0◊ -2^7 to 2^7 –1 ◊Byte
0 to◊char null character (or) ‘\u 0000’◊2^7 –1
0.0d◊double
◊float 0.0f
false◊Boolean
‘\u0000’◊Character
JIT is a part of JVM, it compiles byte code into executable code in real time, will
increase the performance of the interpretations.
Access Specifier
Access Modifiers
Q) Wrapper classes
Primitive data types can be converted into objects by using wrapper classes.
These are java.lang.package.
What if the static modifier is removed from the signature of the main◊ method?
Program compiles. But at runtime throws an error “NoSuchMethodError”.
We can write “static public void” instead of “public static void” but not◊ “public
void static”.
If no arguments on the command line, String array of Main method will be◊
empty of null?
It is empty. But not null.
Variables can have the same◊ name as a method or a class
Q) Constructor
Constructor can use the access specifiers public, protected or private or◊ have
no access modifier (package access)
Constructor can not use the◊ modifiers abstract, static, final, native,
synchronized or strictfp
◊ Constructor can be overloaded, we cannot override.
You cannot use this()◊ and Super() in the same constructor.
Class A(
A(){
System.out.println(“hello”);
}}
Class B extends A {
B(){
System.out.println(“friend”);
}}
Class print {
Public static void main (String args []){
B b = new B();
}
o/p:- Hello
friend
Constructor Method
Use to instance of a class Grouping java statement
No return type Void (or) valid return type
Same name as class name As a name except the class method name, begin
with lower case.
“This” refer to another constructor in the same class Refers to instance of class
“Super” to invoke the super class constructor Execute an overridden method in
the super class
“Inheritance” cannot be inherited Can be inherited
We can overload but we cannot overridden Can be inherited
Will automatically invoke when an object is created Method has called explicitly
Q) Garbage collection
Final: – When we declare a sub class a final the compiler will give error as
“cannot subclass final class” Final to prevent inheritance and method overriding.
Once to declare a variable as final it cannot occupy memory per instance basis.
Final class cannot have static methods◊
Final class cannot have◊ abstract methods
Final class can have only a final method.◊
Finally: – Finally create a block of code that will be executed after try catch block
has completed. Finally block will execute whether or not an exception is thrown.
If an exception is thrown, the finally block will execute even if no catch statement
match the exception. Any time a method is about to return to the caller from
inside try/catch block, via an uncaught exception or an explicit return statement,
the finally clause is also execute.
Using System.exit (); in try block will not allow finally code to execute
Finalize: – some times an object need to perform some actions when it is going
to destroy, if an object holding some non-java resource such as file handle (or)
window character font, these resources are freed before the object is going to
destroy any cleanup processing before the object is garbage collected.