1. Differences between SYSTEM.OUT.PRINTandSYSTEM.OUT.
PRINTLN
System.out.ptintln(); System.out.print();
In System.out.println, In System.out.print
statement the cursor will statement the cursor will
move to the initial position move to the next position
of nextline. of sameline.
EX:
System.out.println(“HELLO EX:
System.out.print(“HELLO
");
");
H E L L O
H E L L O
System.out.println(); // CTS
i.e., Without passing any System.out.print(); //CTE
dataCTS…. i.e., Without passing any
dataCTE….
1| P a g e
Akash V Qspiders Basavanagudi [Insta_id : qspiders_basavanagudi]
2. Diffrences between ELSE IF LADDER andSWITCH
ELSE IF LADDER SWITCH
Else if ladder statement Switch case statement
works on the basis of true works on the basis of
orfalse. equality operator.
Switch case is used when
Else if ladder is used when there is only one condition
there is multiple conditions and multiple values of the
are to betested. same are to betested.
In Switch case, we can
In else if ladder, we use break statement for
cannotuse breakstatement. all the cases present in
thatswitch.
In else if ladder, it will In switch case statement, if
check the condition from any one one of the case is
top to bottom order, if any validating, it executes all the
one the condition is true , remaining statement
itexecutes that including default.
statements and the
control will comes out of
the ladder.
2| P a g e
Akash V Qspiders Basavanagudi [Insta_id : qspiders_basavanagudi]
3. Difference Between WHILE LOOP AND DO WHILELOOP
WHILE LOOP DO WHILE LOOP
while(condition) Do
{ {
//statements; //statements;
} }while(condition
It is an entry controlledloop. );
If the condition is false, no
It is an exit controlledloop.
statements will If the condition is false, the
getexecuted. statements will gets
executed at leastonce.
If there is a single If there is a single
statement, the brackets are statements, the brackets
notrequired. arerequired.
No Semicolon at the end Semicolon at the end
ofthe whilecondition. ofthe whilecondition.
3| P a g e
Akash V Qspiders Basavanagudi [Insta_id : qspiders_basavanagudi]
4. Difference between STATIC BLOCK and STATICMETHOD
STATIC BLOCK STATIC METHODS
Static block doesn’t Static Methods have
have returntype, returntype,
modifiersand name. modifiersand name.
Static blocks gets Static methods
executed during the getsexecuted only when it
loading process of iscalled.
theclass.
They get executed only They get executed
once when the class eachtime only when it
isloaded. iscalled.
5. Difference Between THIS keyword and SUPERkeyword
THIS KEYWORD SUPER KEYWORD
It is used to refercurrent It is used to refer super
class’s instance as well as class’s instance as well as
static members. static members.
It is used to refer the It is used to refer the
instance variable of instance variable of
currentclass. immediate parent class.
Super can be used to
This can be used to invoke parent
invoke current class classmethod.
method (implicitly).
Used to achieve constructor Used to achieve
chaining within the constructor chaining
sameclass. within the parent class.
To invoke or initiate
To invoke or initiate super classconstructor
current classconstructor.
4| P a g e
Akash V Qspiders Basavanagudi [Insta_id : qspiders_basavanagudi]
6. Difference between STATIC method and NON STATICmethod
STATIC METHODS NON STATIC METHODS
A method which is A method which is not
prefixed with prefixed with staticmodifier.
staticmodifier.
Static methods will get
Static methods will get loaded during the loading
loaded during the loading process of object.
process of class.
The memory allocation of
The memory allocation of static methods is inside
static methods is class object (Heaparea).
static area.
More memory is used for
Less memory is used for the execution.
the execution.
7. Difference between THIS() and SUPER()statement.
THIS() SUPER()
this() statement is used to super() statement is used
achieve constructor to achieve constructor
chainingin the sameclass. chaining with the
superclass.
Used to call constructor
within the sameclass. Used to call constructor of
the superclass.
We can use only
inside constructor. Here also, we can use
only insideconstructor.
It must be the first
instruction of Here also, it must be the
theconstructor. first instruction of
theconstructor.
5| P a g e
Akash V Qspiders Basavanagudi [Insta_id : qspiders_basavanagudi]
8. Difference between CONSTRUCTOR andMETHOD
CONSTRUCTOR METHOD
Constructor is a special Method is block
non- static member used ofinstruction.
in the creation ofobject.
The name of the
The name of the
constructor should be as
methodcan beanything.
same as the class name.
Constructors work is to
load all the non-static
members into theobject.
Method is used to
perform specifictask.
A constructor doesn’t
have returntype.
A method can have
a returntype.
A constructor is used
to initialise the states
of an object during the
A method is a collection
of statement which
loading process of
returns a value upon
theobject.
itsexecution.
A constructor cannot be
inherited from
thesubclass.
A method can be
inherited from
thesuperclass.
6| P a g e
Akash V Qspiders Basavanagudi [Insta_id : qspiders_basavanagudi]
9. Differences between METHOD OVERLOADING and METHODOVERRIDING.
METHOD OVERLOADING METHOD OVERRIDING
Creating more than one Providing implementation
methods with the to the superclass non-
samename. static method with the
help of sub class non-
staticmethod.
IS- A relation is notrequired. IS-A relation isrequired.
Return type can beanything. Return type should besame.
Here the access modifier Here the subclass
can beanything. access modifier should
have either equal or
greatervisibility.
Here the method names
must besame. Here the method
signature should
besame.
Formal arguments must
differ either in length or in
type or order ofdeclaration. Formal arguments
i.e.,method signature
should besame.
10. Difference between ABSTRACT method and CONCRETEmethod.
7| P a g e
Akash V Qspiders Basavanagudi [Insta_id : qspiders_basavanagudi]
ABSTRACT METHOD CONCRETE METHOD
It is a method which It is a method which
doesn’t have have methodbody.
methodbody.
Method declaration
Method declaration mustnot end
mustend withsemicolon. withsemicolon.
It is prefixed with It is not prefixed with
abstract modifier. abstract modifier.
It must not have It must have methodbody.
methodbody.
11. Difference between ABSTRACT CLASS and CONCRETECLASS
ABSTRACT CLASS CONCRETE CLASS
Abstract class is declared Concrete is not declared
using abstractmodifier. using abstractmodifier.
An abstract class cannot be A concrete class can be
directly instantiated using directly instantiated using
new keyword. new keyword.
An abstract class may or A concrete class can
may not contain not contain
abstractmethods. abstractmethods.
An abstract class cannot A concrete class can
be declared asfinal. be declared asfinal.
12. Difference between ABSTRACT CLASS andINTERFACE
8| P a g e
Akash V Qspiders Basavanagudi [Insta_id : qspiders_basavanagudi]
ABSTRACT CLASS INTERFACE
In abstract class, we can In interface, we can have
have abstract and non- only abstract methods and
abstract methods. it can have static
methodsalso.
It doesn’t support
multiple inheritance. It
supportsmultiple
It can have final and non-
inheritance.
final static and non-
staticvariables. It can have only
staticfinal variables.
An abstract can be
extended using An interface can be
extendskeyword. inherited using
implementskeyword.
It can have class members
like private, protectedetc…. Members of interface
are public bydefault.
In abstract class we
canhave constructors. In interface we cannot
have constructors.
13. Difference between CLASS andINTERFACE.
9| P a g e
Akash V Qspiders Basavanagudi [Insta_id : qspiders_basavanagudi]
CLASS INTERFACE
The keyword used to The keyword used to
create class isclass. create interface
isinterface.
A class can be instantiated
i.e., object of a An interface cannot
classiscreated. be instantiated i.e.,
objects cannot
becreated.
Classes doesn’t
support Interfaces supports
multipleinheritance. multiple inheritance.
It can inherit aninterface. It cannot inherit aclass.
It can haveconstructors. It cannot haveconstructors.
Variables in a class All variables are static
canbe static, final and final.
orboth.
It can be inherited by
It can be inherited from class with the help
another class with the ofkeyword
helpof implements.
keyword extends.
14. Difference between THROWS and THROWkeywords..
THROWS THROW
10| P a g e
Akash V Qspiders Basavanagudi [Insta_id : qspiders_basavanagudi]
Java throws keyword is Java throw keyword is
used to declare usedto explicitly throw
anexception. anexception.
Checked exception can Checked exception cannot
be propagated be propagated using
usingthrows. throwonly.
Throws is followed by aclass. Throw is followed by
an instance.
Throws is used within Throw is used withinmethod.
method signature.
You cannot throw
You can declaremultiple multiple exceptions.
exceptions.
15. Difference between STATIC and NON STATICVariables.
11| P a g e
Akash V Qspiders Basavanagudi [Insta_id : qspiders_basavanagudi]
STATIC VARIABLES NON- STATIC VARIABLES
Any global which is Any global variable
prefixed with whichis not prefixed with
staticmodifier. static modifier.
Non-static variables get
Static variables get their their memory allocation
memory allocation inside inside object (heaparea).
class staticarea.
Non-static members can
Static members can be be used only with help of
used with help of class object reference.
name as well as
objectreference.
Non-static members will
have more than one copy
Static members will have basedon the
only one copy throughout objectcreation.
the execution.
Non-static members will
Static members are not be shared, it has a
sharedby all theobjects. separate memory for
eachobject.
Static variables are also Non-static members are
known as classvariables. also known as
objectmembers
(instance variables).
16. Diffrences between STRING and STRINGBUILDER
12| P a g e
Akash V Qspiders Basavanagudi [Insta_id : qspiders_basavanagudi]
STRING STRING BUILDER
Strings areimmutable. String Builders aremutable.
In String class ,equals() In String Builder class,
is overrided to equals() is not overridden
compare the to compare the
Stringobjects. StringBuilderobjects.
String class In String Builder
implements class, it doesn’t
comparableinterface. implementsthe
comparableinterface.
We can create a We cannot create a string
Stringobject without using builder object without
newoperator. using newoperator.
It consumes lessmemory.
It consumes more memory
as compared to
Stringbuilder.
String builder has the
setlength()
Since strings are method,whichcan change
immutable, the length the string builder object to
isfixed. specifieslength.
17. Differences between COMPARABLE andCOMPARATOR.
13| P a g e
Akash V Qspiders Basavanagudi [Insta_id : qspiders_basavanagudi]
COMPARABLE COMPARATOR
Comparable provides a Comparator
single sortingsequence. providesmultiple
sortingsequences.
Comparable affects
the originalclass. Comparator doesn’t affect
the originalclass.
Comparable provides
compareTo() method to Comparator provides
sort elements. compare() to sort
theelements.
Comparable is present
in java.langpackage. Comparator is present
in java.utilpackage.
We can sort the list
elements of comparable We can sort the list elements
type by of comparable type by
Collections.sort(List)meth Collections.sort(List,Comparat
od. or) method.
18. Differences between LIST andSET
14| P a g e
Akash V Qspiders Basavanagudi [Insta_id : qspiders_basavanagudi]
LIST SET
List is an ordered collection Set is an un ordered
of objects. collection ofobjects.
It maintains the It doesn’t maintain the
orderof insertion. order ofinsertion.
List allowsduplicates. Sets doesn’t allowduplicates.
List hasindexing. Sets doesn’t haveindex.
we can insert or remove We cannot insert or
the elements with the remove the elements with
help of indexing. the helpof indexing.
19. Differences between FINAL, FINALLY andFINALISE.
FINAL FINALLY FINALISE
Final is akeyword. Finally is akeyword. Finalise is a
method name.
Final is a non- Finally is a block used It is a non-static
access modifier. with try and catch method present
block during in objectclass.
exception handling.
Once declared, Finally block runs This methods
final variables even if exception perform the
becomes constant occurs or not. cleaning activities
andcannot with respect to the
bemodified. object before its
destruction.
Finally block
Final method is execution is not Finalise method is
executed only dependent onthe executed just
whenit iscalled. exceptionhandling. before the object
is destroyed.
15| P a g e
Akash V Qspiders Basavanagudi [Insta_id : qspiders_basavanagudi]
16| P a g e
Akash V Qspiders Basavanagudi [Insta_id : qspiders_basavanagudi]