April 21, 2016
April 15, 2016
April 13, 2016
All About jQuery..
What is jQuery?
Its a'lightweight' javascript library. With jQuery we, 'write less, and do more'. jQuery also simplifies a lot of the complicated things from JavaScript, like AJAX calls and DOM manipulation. jQuery run exactly the same in all major browsers, including Internet Explorer 6.
Its a'lightweight' javascript library. With jQuery we, 'write less, and do more'. jQuery also simplifies a lot of the complicated things from JavaScript, like AJAX calls and DOM manipulation. jQuery run exactly the same in all major browsers, including Internet Explorer 6.
April 07, 2016
Java Reflection API Interview Questions and Answers..
What is Reflection?
Java Reflection makes it possible to inspect classes, interfaces, fields and methods at runtime, without knowing the names of the classes, methods etc. at compile time. It is also possible to instantiate new objects, invoke methods and get/set field values using reflection. That means with reflection, we can examine or modify the runtime behavior of applications running in the Java virtual machine.
Reflection API usage can break the design pattern such as Singleton pattern by invoking the private constructor i.e violating the rules of access modifiers.
Java Reflection makes it possible to inspect classes, interfaces, fields and methods at runtime, without knowing the names of the classes, methods etc. at compile time. It is also possible to instantiate new objects, invoke methods and get/set field values using reflection. That means with reflection, we can examine or modify the runtime behavior of applications running in the Java virtual machine.
Reflection API usage can break the design pattern such as Singleton pattern by invoking the private constructor i.e violating the rules of access modifiers.
April 06, 2016
#Java: Part 12 Java Serialization Interview Questions and Answers for Experienced Developers(Serializable and Externalizable)
> > Part 11-Core Java Interview Questions and Answers: Comparator vs Comparable
What are Serialization and De-serialization in Java?
Serialization is a process by which you can save or transfer the state of an object by converting it to a byte stream.
During Serialization, the Object is converted into a binary format, which can be persisted into a disk or sent over the network to any other running Java virtual machine. During deserialization, the reverse process is performed by creating an object from a binary stream.
FYI, the serialization process is platform-independent, which means an object serialized on one platform can be deserialized on a different platform.
#Java: Part 11-Core Java Interview Questions and Answers: Comparator vs Comparable
> > #Java: Part 10-Core Java Interview Questions and Answers
Difference between Comparator and Comparable in Java
Comparable and Comparator both are interfaces and can be used to sort collection elements.
Difference between Comparator and Comparable in Java
Comparable and Comparator both are interfaces and can be used to sort collection elements.
#Java: Part 10-Core Java Interview Questions and Answers
> > Part 9-Core Java Interview Questions and Answers(Java Memory Model, Garbage Collectors in Java)
How do you prevent SQL Injection in Java Code?
In SQL Injection attack, malicious user pass SQL meta-data combined with input which allowed them to execute sql query of there choice.
ALSO READ: JDBC Interview Questions And Answers
PreparedStatement can be used to avoid SQL injection in Java code. Use of the PreparedStatement for executing SQL queries not only provides better performance but also shield your Java and J2EE application from SQL Injection attack. All the parameters passed as part of place-holder will be escaped automatically by JDBC Driver.
In SQL Injection attack, malicious user pass SQL meta-data combined with input which allowed them to execute sql query of there choice.
ALSO READ: JDBC Interview Questions And Answers
PreparedStatement can be used to avoid SQL injection in Java code. Use of the PreparedStatement for executing SQL queries not only provides better performance but also shield your Java and J2EE application from SQL Injection attack. All the parameters passed as part of place-holder will be escaped automatically by JDBC Driver.
#Java: Part 9-Core Java Interview Questions and Answers(Java Memory Model, Garbage Collectors in Java)
> > Part 7-Core Java Interview Questions and Answers
What is JIT compiler in Java?
What is JIT compiler in Java?
- JIT stands for Just-In-Time compiler.
- It is a program that helps in converting the Java bytecode into instructions that are sent directly to the processor.
- The JIT compiler is by default enabled and is activated whenever a Java method is invoked. The JIT compiler then compiles the bytecode of the invoked method into native machine code, compiling it 'just in time' to execute.
- Once the method has been compiled, the JVM summons the compiled code of that method directly rather than interpreting it. This is why it is often responsible for the performance optimization of Java applications at the run time.
- Stack Segment : contains local variables and Reference variables(variables that hold the address of an object in the heap)
- Heap Segment : contains all created objects in runtime, objects only plus their object attributes (instance variables)
- Code Segment : The segment where the actual compiled Java bytecodes resides when loaded.
#Java: Part 8-Core Java Interview Questions and Answers (Interface, final, finalize, finally)
> > Part 7-Core Java Interview Questions and Answers (Generics)
What is an interface and what are the advantages and disadvantage of using interfaces in Java?
What is an interface and what are the advantages and disadvantage of using interfaces in Java?
- With interfaces, we can achieve abstraction in Java along with abstract class.
- Interface in java is declared using keyword interface and it represent a Type like any Class in Java. A reference variable of type interface can point to any implementation of that interface in Java.
- All variables declared inside interface is implicitly public final variable or constants. which brings a useful case of using Interface for declaring Constants.
- All methods declared inside Java Interfaces are implicitly public and abstract, even if you don't use public or abstract keyword. You can not define any concrete method in interface (till java 7). That's why interface is used to define contracts in terms of variables and methods and you can rely on its implementation for performing job.
#Java: Part 7-Core Java Interview Questions and Answers (Generics)
> > Part 6-Core Java Interview Questions and Answers (Wrapper classes, Static variables, methods and imports)
What is Generics in Java ?
Generics is introduced in J2SE 5 to deal with type-safe objects. Before generics, we can store any type of objects in collection i.e. non-generic. Now generics, provides compile time type-safety and ensures that you only insert correct Type in collection and avoids ClassCastException in runtime.
What is Generics in Java ?
Generics is introduced in J2SE 5 to deal with type-safe objects. Before generics, we can store any type of objects in collection i.e. non-generic. Now generics, provides compile time type-safety and ensures that you only insert correct Type in collection and avoids ClassCastException in runtime.
#Java: Part 6-Core Java Interview Questions and Answers (Wrapper classes, Static variables, methods and imports)
> > Part 5-Core Java Interview Questions and Answers (Clone and Immutability)
What are Wrapper classes?
A wrapper class wraps (encloses) around a data type and gives it an object appearance. They include methods to unwrap the object and give back the data type. e.g
int intCount = 100;
Integer wrapperIntCount = new Integer(intCount); //this is called Boxing
int intCountBack = wrapperIntCount.intValue(); //thats unBoxing
There are mainly two uses with wrapper classes:
1) To convert simple data types into objects, i.e to give object form to a data type.
2) To convert strings into data types (known as parsing operations), here methods of type parseXXX() are used.
What are Wrapper classes?
A wrapper class wraps (encloses) around a data type and gives it an object appearance. They include methods to unwrap the object and give back the data type. e.g
int intCount = 100;
Integer wrapperIntCount = new Integer(intCount); //this is called Boxing
int intCountBack = wrapperIntCount.intValue(); //thats unBoxing
There are mainly two uses with wrapper classes:
1) To convert simple data types into objects, i.e to give object form to a data type.
2) To convert strings into data types (known as parsing operations), here methods of type parseXXX() are used.
#Java: Part 5-Core Java Interview Questions and Answers (Clone and Immutability)
> > Part 4-Core Java Interview Questions and Answers (HashCode & equals())
What is a Cloneable interface and what all methods does it contain?
Cloneable is a declaration that the class implementing it allows cloning or bitwise copy of it's object state. It is not having any method because it is a Marker interface.
How clone method works in Java?
The clone() method from java.lang.Object class is used to create a copy of an Object in Java. This copy is known as a clone of original instance. Constructor is not called during cloning of Object in Java.
clone() method is declared as protected and native in Object class. Since its convention to return clone() of an object by calling super.clone() method, any cloning process eventually reaches to java.lang.Object clone() method.
Cloneable is a declaration that the class implementing it allows cloning or bitwise copy of it's object state. It is not having any method because it is a Marker interface.
How clone method works in Java?
The clone() method from java.lang.Object class is used to create a copy of an Object in Java. This copy is known as a clone of original instance. Constructor is not called during cloning of Object in Java.
clone() method is declared as protected and native in Object class. Since its convention to return clone() of an object by calling super.clone() method, any cloning process eventually reaches to java.lang.Object clone() method.
#Java: Part 4-Core Java Interview Questions and Answers (HashCode & equals())
> > Part 3-Core Java Interview Questions and Answers
When you are writing equals() method, which other method or methods you need to override?
The right answer is hashCode(). Since equals and hashCode has there contract, so overriding one and not other, will break contract between them. Interviewer may ask about what are those contracts, what happens if those contracts breaks etc.
The right answer is hashCode(). Since equals and hashCode has there contract, so overriding one and not other, will break contract between them. Interviewer may ask about what are those contracts, what happens if those contracts breaks etc.
#Java: Part 3-Core Java Interview Questions and Answers
> > Part 2-Core Java Interview Questions and Answers (Polymorphism, Overloading and Overriding)
What is Encapsulation?
It means binding the data with the code that manipulates it, it keeps the data and the code safe from external interference
By Encapsulation we can keep all the related members (variables and methods) together in an object.
The whole idea behind encapsulation is to hide the implementation details from users. If a data member is private it means it can only be accessed within the same class. No outside class can access private data member (variable) of other class. However if we setup public getter and setter methods to update (for e.g. void setUserName(String userName))and read (for e.g. int getUserName()) the private data fields then the outside class can access those private data fields via public methods.
This way data can only be accessed by public methods thus making the private fields and their implementation hidden for outside classes. That’s why encapsulation is also known as 'Data Hiding' or 'Information Hiding'.
The idea of encapsulation is to keep classes separated and prevent them from having tightly coupled with each other.
Encapsulated code should have following characteristics:
Encapsulation is a process of binding or wrapping the data and the codes that operates on the data into a single entity. This keeps the data safe from outside interface and misuse. Abstraction is the concept of hiding irrelevant details.In other words make complex system simple by hiding the unnecessary detail from the user.
Abstraction is implemented in Java using interface and abstract class while Encapsulation is implemented using private, package-private and protected access modifier.
What's the difference between "==" and "equals()"?
Both equals() and "==" operator in Java is used to compare two objects to check whether they are equal or not. The main difference between equals method and the == operator is that former is a method and later is an operator.
Since operator overloading is not supported by Java, that's why== behaves identical for every object, but user override equals() method and write their own logic to compare the objects based on the business rules.
Also Read: HashCode & equals() Interview Questions in Java
== is used to compare both primitive and objects, however equals() is only used for objects comparison.
A == B does object reference matching if both A and B are an object and only return true if both are pointing to the same object in the heap space, on the other hand, A.equals(B) is used for logical mapping and its expected from an object to override this method to provide logical equality.
What are three types of loops in Java?
Looping is used in programming to execute a statement or a block of statement repeatedly. There are three types of loops in Java:
An infinite loop runs without any condition and runs infinitely. An infinite loop can be broken by defining any breaking logic in the body of the statement blocks. e.g:
for (;;)
{
//perform operations
..
..
//Add the loop breaking logic
if(loopBreaker)
{
break;
}
}
What is the difference between continue and break statement?
When a break keyword is used in a loop, loop is broken instantly while when continue keyword is used, current iteration is broken and loop continues with next iteration.
What is the difference between double and float variables in Java?
float takes 4 bytes in memory while Double takes 8 bytes in memory in Java. Float is single precision floating point decimal number while Double is double precision decimal number.
What is ternary operator?
Ternary operator , also called conditional operator is used to decide which value to assign to a variable based on a Boolean value evaluation. It’s denoted as ?
e.g, in the below example isAdult will be set to true if the age is greater than or equal to 18, else it will be set as false.
boolean isAdult=(age>=18) ? true : false;
Does Importing a package imports its sub-packages as well in Java?
In java, when a package is imported, its sub-packages aren’t imported and if required we need to import them separately.
Can you call a abstract method from a non abstract method ?
Yes, we can call a abstract method from a Non abstract method in a Java abstract class
What is an Inner class?
Inner class are defined inside the body of another class (known as outer class). These classes can have access modifier or even can be marked as abstract and final.
All the Inner classes have special relationship with outer class instances. This relationship allows them to have access to outer class members including private members too.
There are four types of Inner classes:
1) Inner class
2) Method-local inner class
3) Anonymous inner class
4) Static nested class
What is the difference between an Inner Class and a Sub-Class?
An Inner class is a class which is nested within another class. An Inner class has access rights for the class which is nesting it and it can access all variables and methods defined in the outer class.
A sub-class is a class which inherits from another class called super class. Sub-class can access all public and protected methods and fields of its super class.
How can we copy Date object into another date Object without using a reference?
e.g:
Date mydate = new Date();
Date copiedmydate = new Date(mydate.getTime());
With Java 8 you can use the following null-safe code.
Optional.ofNullable(mydate)
.map(Date::getTime)
.map(Date::new)
.orElse(null);
ALSO CHECK: Core Java Interview Questions And Answers
-K Himaanshu Shuklaa..
What is Encapsulation?
It means binding the data with the code that manipulates it, it keeps the data and the code safe from external interference
By Encapsulation we can keep all the related members (variables and methods) together in an object.
The whole idea behind encapsulation is to hide the implementation details from users. If a data member is private it means it can only be accessed within the same class. No outside class can access private data member (variable) of other class. However if we setup public getter and setter methods to update (for e.g. void setUserName(String userName))and read (for e.g. int getUserName()) the private data fields then the outside class can access those private data fields via public methods.
This way data can only be accessed by public methods thus making the private fields and their implementation hidden for outside classes. That’s why encapsulation is also known as 'Data Hiding' or 'Information Hiding'.
The idea of encapsulation is to keep classes separated and prevent them from having tightly coupled with each other.
Encapsulated code should have following characteristics:
- Everyone knows how to access it.
- Can be easily used regardless of implementation details.
- There shouldn’t any side effects of the code, to the rest of the application.
Encapsulation is a process of binding or wrapping the data and the codes that operates on the data into a single entity. This keeps the data safe from outside interface and misuse. Abstraction is the concept of hiding irrelevant details.In other words make complex system simple by hiding the unnecessary detail from the user.
Abstraction is implemented in Java using interface and abstract class while Encapsulation is implemented using private, package-private and protected access modifier.
What's the difference between "==" and "equals()"?
Both equals() and "==" operator in Java is used to compare two objects to check whether they are equal or not. The main difference between equals method and the == operator is that former is a method and later is an operator.
Since operator overloading is not supported by Java, that's why== behaves identical for every object, but user override equals() method and write their own logic to compare the objects based on the business rules.
Also Read: HashCode & equals() Interview Questions in Java
== is used to compare both primitive and objects, however equals() is only used for objects comparison.
A == B does object reference matching if both A and B are an object and only return true if both are pointing to the same object in the heap space, on the other hand, A.equals(B) is used for logical mapping and its expected from an object to override this method to provide logical equality.
What are three types of loops in Java?
Looping is used in programming to execute a statement or a block of statement repeatedly. There are three types of loops in Java:
- For loops are used in java to execute statements repeatedly for a given number of times. For loops are used when number of times to execute the statements is known to programmer.
- While loop is used when certain statements need to be executed repeatedly until a condition is fulfilled. In while loops, condition is checked first before execution of statements.
- Do While loop is same as While loop with only difference that condition is checked after execution of block of statements. Hence in case of do while loop, statements are executed at least once.
An infinite loop runs without any condition and runs infinitely. An infinite loop can be broken by defining any breaking logic in the body of the statement blocks. e.g:
for (;;)
{
//perform operations
..
..
//Add the loop breaking logic
if(loopBreaker)
{
break;
}
}
What is the difference between continue and break statement?
When a break keyword is used in a loop, loop is broken instantly while when continue keyword is used, current iteration is broken and loop continues with next iteration.
What is the difference between double and float variables in Java?
float takes 4 bytes in memory while Double takes 8 bytes in memory in Java. Float is single precision floating point decimal number while Double is double precision decimal number.
What is ternary operator?
Ternary operator , also called conditional operator is used to decide which value to assign to a variable based on a Boolean value evaluation. It’s denoted as ?
e.g, in the below example isAdult will be set to true if the age is greater than or equal to 18, else it will be set as false.
boolean isAdult=(age>=18) ? true : false;
Does Importing a package imports its sub-packages as well in Java?
In java, when a package is imported, its sub-packages aren’t imported and if required we need to import them separately.
Can you call a abstract method from a non abstract method ?
Yes, we can call a abstract method from a Non abstract method in a Java abstract class
What is an Inner class?
Inner class are defined inside the body of another class (known as outer class). These classes can have access modifier or even can be marked as abstract and final.
All the Inner classes have special relationship with outer class instances. This relationship allows them to have access to outer class members including private members too.
There are four types of Inner classes:
1) Inner class
2) Method-local inner class
3) Anonymous inner class
4) Static nested class
What is the difference between an Inner Class and a Sub-Class?
An Inner class is a class which is nested within another class. An Inner class has access rights for the class which is nesting it and it can access all variables and methods defined in the outer class.
A sub-class is a class which inherits from another class called super class. Sub-class can access all public and protected methods and fields of its super class.
How can we copy Date object into another date Object without using a reference?
e.g:
Date mydate = new Date();
Date copiedmydate = new Date(mydate.getTime());
With Java 8 you can use the following null-safe code.
Optional.ofNullable(mydate)
.map(Date::getTime)
.map(Date::new)
.orElse(null);
ALSO CHECK: Core Java Interview Questions And Answers
-K Himaanshu Shuklaa..
#Java: Part 2-Core Java Interview Questions and Answers (Polymorphism, Overloading and Overriding)
>> Check the Part 1-Core Java Interview Questions and Answers
What is Inheritance?
It is the mechanism by which an object acquires some/all properties of another object. Inheritance provides the idea of reusability of code and each sub class defines only those features that are unique to it.
The existing (or original) class is called the base class or super class or parent class. The new class which inherits from the base class is called the derived class or sub class or child class. Inheritance implements the “Is-A” or “Kind Of/ Has-A” relationship.
What is Inheritance?
It is the mechanism by which an object acquires some/all properties of another object. Inheritance provides the idea of reusability of code and each sub class defines only those features that are unique to it.
The existing (or original) class is called the base class or super class or parent class. The new class which inherits from the base class is called the derived class or sub class or child class. Inheritance implements the “Is-A” or “Kind Of/ Has-A” relationship.
#Java: Part 1-Core Java Interview Questions and Answers
< < Part 2-Core Java Interview Questions and Answers (Polymorphism, Overloading and Overriding)
What is Association, Aggregation and Composition?
Association is a relationship between two separate classes which can be of any type say one to one, one to may etc. It joins two entirely separate entities.
Aggregation is a special form of association which is a unidirectional one way relationship between classes (or entities), for e.g. Wallet and Money classes. Wallet has Money but money doesn’t need to have Wallet necessarily so its a one directional relationship. In this relationship both the entries can survive if other one ends. In our example if Wallet class is not present, it does not mean that the Money class cannot exist.
Composition is a restricted form of Aggregation in which two entities (or you can say classes) are highly dependent on each other. For e.g. Human and Heart. A human needs heart to live and a heart needs a Human body to survive. In other words when the classes (entities) are dependent on each other and their life span are same (if one dies then another one too) then its a composition. Heart class has no sense if Human class is not present.
What is Association, Aggregation and Composition?
Association is a relationship between two separate classes which can be of any type say one to one, one to may etc. It joins two entirely separate entities.
Aggregation is a special form of association which is a unidirectional one way relationship between classes (or entities), for e.g. Wallet and Money classes. Wallet has Money but money doesn’t need to have Wallet necessarily so its a one directional relationship. In this relationship both the entries can survive if other one ends. In our example if Wallet class is not present, it does not mean that the Money class cannot exist.
Composition is a restricted form of Aggregation in which two entities (or you can say classes) are highly dependent on each other. For e.g. Human and Heart. A human needs heart to live and a heart needs a Human body to survive. In other words when the classes (entities) are dependent on each other and their life span are same (if one dies then another one too) then its a composition. Heart class has no sense if Human class is not present.
Subscribe to:
Posts (Atom)

