Total Pageviews

Friday, 24 August 2018

Core java _ one liners


  1. When one object acquires all the properties and behaviors of a parent object, it is known as inheritance
  2. If one task is performed by different ways, it is known as polymorphism.
  3. Highlighting the set of services while hiding the implementation is known as abstraction.
  4. Binding code and data as single unit is known as encapsulation



Boolean vs boolean in Java

Boolean is a wrpper class in java.lang package while boolean is a primitive data type
Boolean provides more methods which can be failrly useful while in case if you want to save memory then use boolean.


//--

A class is a blueprint from which objects are created while an object is an instance of class

//--

There are 8 primitives in Java i.e. byte,short,int,long,float,double,char,boolean. These are not objects. To represent these 8 primitives datatypes in the form of objects
there are 8 classes used. These classes are called as wrapper classes.Those wrapper classes are Byte,Short,Integer,Long,Float,Double,Character,Boolean .
These wrapper classes are present in java.lang package.

Typecasting is of two types implicit type casting and explicit type casting.
In implicit type casting is smaller to bigger like converting byte to short.
Explicit type casting comes when we are converting from bigger to smaller. short to byte. In this there is loss of information.

//--
Autoboxing:
int a = 10;
Integer b = a;  //here compiler internally understands this line as Integer b = Integer.valueOf(a);

Unboxing:
Integer a = new Integer(10);
int b = a;  // here compiler will internally see it as int b = a.intValue();

Comparable meant for default sorting order , comparator meant for customised sorting order

What is invoked first, instance initializer block or constructor?
-- Firstly constructor is invoked , after execution it may seem that instance initialzer was first invoked but actually compiler copies what is there in
instance initialeser block in constructor and then run.


Since method invocation is determined by the JVM not compiler, it is known as runtime polymorphism.

All catch blocks must be ordered from most specific to most general i.e. catch for ArithmeticException must come before catch for Exception .

Test t = new Test();
Test: Class Name
t: Refrence Variable
=: Assignment Operator

//*[not(contains(.,'Certificate'))]

Alerts are blocking in nature, they will not allow any action on webpage if they are present.
Alerts are generally three types:
1>Simple alert: just displays the msg
2>Conformation alert with ok and cancel button
3>prompt alert: prompts the user and ask for yes and not

> The packages whose names are starting with java like 'import java.util.Collections;' will be java packages and the packages whose name are starting with org.openqa.selenium
like import org.openqa.selenium.Alert; will be selenium package.

> Packages is logically organising your java classes.Jar(Java Archive) is physically orgnising your java classes. One Jar can have many java packages.
A library is a collection of jars and a jar is a collection of classes.

Because constructors are not methods and a subclass’ constructor cannot have same name as a superclass’ one, so there’s nothing relates between constructors and overriding.
        Bold this line constructors are not methods 

Abstract class object creation is not possible

Abstract class may contain abstract methods or may not contain abstract methods but it is not possible to create object of Abstract Class

instanciation is nothing but object creation

Is it possible to declare main methods in abstract class or not:  ---Yes you can have main method , it is just that you wont be able to intanciate the abstract class .

Inside abstract class u can declare constructors

Rules and Regulations for
1>Constructor Name class name must be same
2>Constructor must be able to take parameters
3>Constructors are not allowed to return values
4>If u are not declaring constructors then compiler generates 0 arguments constructor.
ex.
class Test{

void m1(){
  system.out.println("m1 method");
}
/*                                              ---------- commented constructor is generated by compiler internally
Test(){
   // empty implementation, no body
}
*/
main(){
Test t = new Test();
t.m1();
}
}
5> If u are not declaring any constructor then only default constructor will be generated by compiler. If suppose u are creating one multiple argument constructor in your
   class and in main method u are creating object of default constructor then compiler will throw error. e.g.
   Class Test{
Test(int arg){
   // empty implementation
}
    main(){
new Test();      // here compiler will throw error stating constructor new Test() is undefined.
new Test(4);
}
   }
 
Advantages of constructor
 > The benefits of constructors are they get executed during their object creation itself. So suppose u want to perform some tasks and want those tasks to get executed
   immediately at the time of object creation then u are going to write those tasks using constructors.


> Serialization in Java is a mechanism of writing the state of an object into a byte stream.
It is mainly used to travel object's state on the network.
Also one of the way to create object in java is using deserialization.


> An exception is an event which disturbs normal flow of program.

>u can put try without catch but u will have to put finally

> Finally block is expected to be clean up block , return is not expected from it.

>Checked exceptions are not propagated while unchecked exceptions are propagated.

> If a class have an entity reference, it is known as Aggregation.

> Wrapper class in java provides the mechanism to convert primitive into object and object into primitive.


> There is only call by value in java, not call by reference. If we call a method passing a value, it is known as call by value.


>>Variables declared inside a static block will be local to that block just like methods and constructors variables.


 
 
 
   

No comments:

Post a Comment