Labels
- ArrayList
- Arrays
- BiPredicate
- Consumer
- Deserialization
- Exception Handling
- ForEachLoop
- Function
- Generic
- Google Script
- hash Table
- HashSet
- Inheritence
- Interview Questions
- Java 8 Features
- JAVA I/O
- Java Stream API
- JDBC
- Lambda Expression
- Leap Year
- linked HashSet
- Linkedlist
- Matrix Problems
- Method Reference
- MultiThreading
- Number Problems
- OOPS
- Pattern Problems
- Polymorphism
- Predicate
- Queue
- Serialization
- Series
- Stack
- Supplier
- This Keyword
- Transient
- Tree Map
- Tree Set
- Vector
Predicate
Difference between Interface and Abstract Class.
|
|
Interface |
Abstract Class |
|
1 |
If we don’t know about the
implementation, just we have
requirement specification then we should go for Interface |
If we are talking about
implementation but not completely (partial
implementation) then we should go for Abstract
class. |
|
2 |
Inside interface every
method is always public and abstract whether
we are declaring or not. Hence interface is also considered as 100% pure
Abstract class. |
Every method present in Abstract
class need not be public and Abstract. In addition to abstract methods we can take concrete methods also. |
|
3 |
We can’t declare interface
method with the following modifiers. Publicàprivate, protected Abstract->final, static,
synchronized, native, strictfp |
There are no restrictions on Abstract class method modifiers. |
|
4 |
Every variable present inside interface is
always public, static and final. |
The variable present inside
Abstract class need not be public static and final. |
|
5 |
For interface variable, we must perform initialization at the
time of declaration otherwise we will get
compile time error. |
For Abstract class variables, it
is not required to perform
initialization at the time of declaration. |
|
6 |
Inside interface we can’t
declare instance and static blocks, otherwise we will get compile error. |
Inside Abstract class we can
declare instance and static blocks. |
|
7 |
Insider interface we can’t declare constructors. |
Inside Abstract class we can declare constructor, which will be executed at the time of
child object creation. |
Interface VS Abstract class VS Concrete class?
If we don’t know anything about implementation just we have requirement specification (100% Abstraction) then we should go for Interface.
If we talking about implementation but not completely (partial implementation) then we go for Abstract class.
Example: GenericServlet and HTTPServlet.
Example: MyOwnServlet.
When to use String, StringBuffer and StringBuilder?
Answer:
When the content is fixed and won’t change frequently then we should go for String.
If the content is not fixed and keep on changing but Thread Safety
is required then we should go for StringBuffer.
If the content is not fixed and keep on changing and thread safety
is not required then we should go for StringBuilder.
What is the Difference between String and StringBuffer
Answer:
What is the difference between == operator and .equals() method?
What is the difference between final finally and finalize?
final:
1.Final is a modifier applicable for classes, methods and variables.
If a class declared as final then we can’t extend that class.
i.e. We can’t create child class for that class.
2.If a method is declared as final then we can’t override that method in the
child class.
3.If a variable declared as final then it will become constant and
we can’t perform re-assignment for that variable.
finally:
1.Finally is a block always associated with try catch to maintain
cleanup code
Try {
//risky code
}
Catch(X e) {
//handling code
}
Finally {
//cleanup code
}
finalise():
finalise() is a method which is always invoked by garbage collector
Note:
Finally meant for cleanup activities related to try block,
whereas finalize() meant for cleanup activities related to object just
Calculating Square of a number Using Lambda Expression
Calculating Sum of Two Numbers Using Lambda Expression
Lambda Expression
What is Lambda Expression (λ):
Benefits of Using Lambda Expression are :
Example:1
Example : 2
Example : 3
Note :
6) Similar to method body lambda expression body also can contain
multiple statements. if more than one statements present then we have to
enclose inside within curly braces. if one statement present then curly braces are
optional.
Google Script for Data Entry Form in Google Spreadsheet
// function to validate the entry made by user in user form function validateEntry (){ // declare a variable and referernece of active goog...
-
1. Whenever we are writing try block , compulsory we should write catch or finally . 2.Whenever we are writing catch block compulsory we...
-
import java . util . * ; public class CalculateSpeed { public static void main ( String args[]){ Scanner sc = new S...