0% found this document useful (0 votes)
7 views

Java Differences

The document outlines various differences in Java programming concepts, including methods, loops, constructors, and data structures. Key comparisons include System.out.print() vs. System.out.println(), else-if ladder vs. switch case, and ArrayList vs. LinkedList. Each section provides specific characteristics and use cases for the concepts discussed.

Uploaded by

jupakapraveen88
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Java Differences

The document outlines various differences in Java programming concepts, including methods, loops, constructors, and data structures. Key comparisons include System.out.print() vs. System.out.println(), else-if ladder vs. switch case, and ArrayList vs. LinkedList. Each section provides specific characteristics and use cases for the concepts discussed.

Uploaded by

jupakapraveen88
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Java Differences

Difference b/w System.out.print() and System.out.println()?


System.out.print(); System.out.println();
1.It is used to print the data and moves 1.it is used to print the data and moves
the cursor to the next position of same the cursor to the next line.
line.
2.providing data is mandatory to print() 2.providing data is optional.
statement.
Ex: Ex:
System.out.print(“hello”); System.out.println(“hello”);
h e l l o _ h e l l O
_

Difference b/w else-if ladder and switch case?


else-if ladder switch case
1.else-if ladder statement works on the 1.switch case statement works on the
basis of true or false. basis of equality operator.
2.else-if ladder is used when there are 2.switch case is used when only one
multiple conditions in that one of the condition to checked and multiple
condition is output. values to can be accessed.
3. in else-if ladder , we cannot use break 3.in switch case , we can use break
statement. statement for all the cases present in
that switch.
4.in else-if ladder, it will check the 4.in switch case statement, if any one of
condition from top to bottom order, if the case is validating, it executes all the
any one condition is true ,it executes remaining statement including default.
the statements and the control will
come out of the ladder.

Difference b/w while loop and do-while loop?


while loop do-while loop
1.while(condition) 1.do
{ {
//statements; //statements;
} }while(condition);
2.It is an entry controlled loop 2.It is an exit controlled loop
3.if the condition is false, no statements 3. if the condition false, the statements
will get executed. will gets executes at least once.
4.if there is a single statements , the 4.if there is a single statements, the
brackets are not required. brackets are required.
5.no semicolon at the end of the while 5.semicolon at the end of the while
condition. condition.
Difference b/w this() and super() statement?
this() super()
1.Developer explicitly adds this() 1.When Developer forgets to add this()
statement in a constructor. statement compiler automatically adds
super() statement in the constructor.
2.this() statement used to call 2.super() used to call constructor of
constructor within the same class. super class from the sub class.
3.this() statement is the first statement 3.super() statement is first statement of
of the constructor the constructor.

Difference b/w Method and Constructor ?


Method Constructor
1. It is a block of instructions which is in 1. It is a Special member function which
the form of statements. which is used to is used to initialize non-static members
perform some specific task. during object creation.
2. Method name can be anything. 2. Constructor has Same name as class
name.
3. It does not have return type. 3. It have return type.
4.We can inherit methods. 4.we cannot inherit constructor.

Difference b/w Method overloading and Method overriding?


Method overloading Method overriding
1.create any number of method with 1.super class non-static method
same name but different formal implementation is overriden by sub
arguments. class non-static method
implementation.
2.inheritance is not required. 2.inheritance is required.
3.access modifier can be anything. 3.scope or visibility of sub class access
modifier should be greater than or
equals to super class method.
4.return type can be anything. 4.return type should be same
5.here only method name same but not 5.here entire method signature is same.
formal argument of method signature.
Difference b/w abstract method and concrete method?
abstract method concrete method
1. It is a method which doesn’t have method 1. It is a method which have method
body body.
2. Method declaration must end with 2. Method declaration should not end
semicolon. with semicolon.
3. It is prefixed with abstract modifier 3. It is not prefixed with abstract
modifier
4. It must not have method body. 4. It must have method body.

Difference b/w abstract class and concrete class?


abstract class concrete class
1. Abstract class is declared using 1. Concrete is not declared using abstract
abstract modifier. modifier.
2. An abstract class cannot be directly 2. A concrete class can be directly instantiated
instantiated using new keyword. using new keyword.
3. An abstract class may or may not 3. A concrete class cannot contain abstract
contain abstract methods. methods.
4. An abstract class cannot be declared 4. A concrete class can be declared asfinal.
as final.

Difference b/w abstract class and interface?


abstract class Interface
1. In abstract class, we can have 1.In interface, we can have only abstract
abstract and non- abstract methods. methods and it can have static methods also.
2. It doesn’t support multiple 2.It supports multiple inheritance.
inheritance.
3. It can have final and non- final static 3. It can have only public static final
and non- static variables
4. An abstract can be extended using 4. An interface can be inherited using
extends keyword. implements keyword.
5. It can have class members like 5. Members of interface are public by default.
private, protected etc….
6. In abstract class we can have 6. In interface we cannot have constructors.
constructors
Difference b/w String, StringBuffer and StringBuilder ?
String StringBuffer StringBuilder
1.It is Immutable in 1. It is mutable in nature 1. It is mutable in nature
nature
2.It is Single 2. It is Single Threaded 2. It is MultiThreaded
Threaded
3.Thread Safe 3. Thread safe 3. Not Thread Safe
4.It is Synchronized 4. It is Synchronized 4.It is not synchronized

Difference b/w throw and throws ?


throw throws
1. Java throw keyword is used to 1. Java throws keyword is used to
explicitly throw an exception. declare an exception.
2. Checked exception cannot be 2. Checked exception can be
propagated using throw only. propagated using throws.
3. Throw is used with in a method. 3. Throws is used within method
signature.
4. It is used to raise an Exception 4.It used to declare an Exception

Difference b/w Collection and Collections ?


Collection Collections
1. Collection is a interface. 1. Collections is a Utility Class
2. It used to work based on group of 2. It holds all static methods.
individual Objects.

Difference b/w List and Set ?


List Set
1. It has Indexing 1. It does not have Indexing
2. It Maintain Insertion order 2. It does not Maintain Insertion Order
3. It allows duplicates 3. It does not allow duplicates
4.It allows multiple null values 4. It allow only null value
Difference b/w ArrayList and LinkedList ?
ArrayList LinkedList
1.It work based on Indexing. 1.It work based on adress.
2.It is a best choice to choose retriving 2. It is a best choice to choose Inserting
or fetching the object . and deleting the Object.
3.It follows continuous memory block 3. It does not follow continuous
memory block

Difference b/w ArrayList and Vector?


ArrayList Vector
1.ArrayList is not synchronized object. 1.Vector is synchronized object.
2.multiple threads can access at a time. 2.only one thread is accessed at a time.
3.ArrayList is not thread safe. 3.Vector is thread safe.
4.ArrayList is introduced in jdk 1.2 Vector is introduced in 1.0 version. So, it
version. So, it is not a legacy class. is a legacy class.

Difference b/w Iterator and ListIterator ?


Iterator ListIterator
1.It is an interface. 1. It is an interface.
2.It is present in java.util package 2. It is present in java.util.package.
3. It is a universal cursor ,which works only 3. It is a universal cursor, which works both
forward direction forward and backword direction.

Difference b/w Hashtable and HashMap?


Hashtable HashMap
1.hashtable is introduced in jdk 1.0 1.hashmap is introduced in jdk 1.2
version. version . so, it is not a legacy class.
So, it is called legacy class
2.hashtable is synchronized. 2.hashmap is not synchronized.
3.only one thread can access it at a time 3.multiple threads can access at a time.
4. hashtable thread safe. 4.hashmap is not thread safe.
5. hashtable dosen’t allow one null 5.hashmap allow only one null key and
object also. multiple null values.

You might also like