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

Java Guide1

The document outlines various differences in Java concepts, including JDK vs JRE vs JVM, length vs length(), and == vs .equals() method. It also compares Java with C++, discusses typecasting, class vs object, abstraction vs encapsulation, and various data structures like ArrayList vs LinkedList and HashMap vs Hashtable. Additionally, it explains exceptions, interfaces, and keywords such as this and super, providing a comprehensive guide for Java developers.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Java Guide1

The document outlines various differences in Java concepts, including JDK vs JRE vs JVM, length vs length(), and == vs .equals() method. It also compares Java with C++, discusses typecasting, class vs object, abstraction vs encapsulation, and various data structures like ArrayList vs LinkedList and HashMap vs Hashtable. Additionally, it explains exceptions, interfaces, and keywords such as this and super, providing a comprehensive guide for Java developers.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Java – Differences Questions

1. What is difference between JDK, JRE, JVM?

JDK:
JDK stands for Java Development Kit.
It is installable software used for developing java applications. It includes Java Runtime
Environment (JRE), an interpreter/loader (Java), a compiler (javac), an achiever (jar), a
Document generator (javadoc), and other tools needed for java development.
JRE:
It provides very good environment to run java applications only.
JVM:
It is an interpreter which is used to execute our program line by line procedure.

2. What is difference length and length()?

length length()
It is a final variable applicable for arrays. It is a final method applicable for String
objects.
It will return size of an array. It will return number of characters present
in a string.

3. What is difference between == and .equals() method?

== .equals()
It is used for reference or address It is used for content comparison.
comparison.
We can compare objects and primitives. We can’t compare primitives.

4. What is the difference between C++ and Java?

C++ Java
It was developed by Bjarne Stroustrup. It was developed by James Gosling.
It is a partial object oriented programming. It is purely object oriented programming.
It is platform dependent. It is platform independent.
It supports multiple inheritance. It does not support multiple inheritance.
It supports pointers. It does not support pointers.
It supports goto statement. It does not support goto statement.
It supports operator overloading. It does not support operator overloading.
Memory allocation and deallocation will Memory allocation and deallocation will
take care by a programmer. take care by a JVM.
It supports three access specifiers i.e public, It supports four access modifiers i.e default,
private and protected. public, private and protected.
It supports three loops i.e do while loop, It supports four loops i.e do while loop,
while loop and for loop. while, for loop and for each loop.

It supports preprocessor directory (#). It doesn’t support preprocessor directory.

IHUB TALENT MANAGEMENT NIYAZ UL HASAN


5. What is the difference between implicit and explicit typecasting?

Implicit typecasting Explicit typecasting


If we want to store smaller value into a If we want to store bigger value into a
bigger variable then we need to use implicit smaller variable then we need to use
typecasting. explicit typecasting.
A compiler is responsible to perform A programmer is responsible to perform
implicit typecasting. explicit typecasting.
There is no possibility to loss the There is a possibility to loss the
information. information.
It is also known as Widening or Up-casting. It is also known as Narrowing or Down-
casting.

6. What is the difference between class and object?

class object
It is a blueprint or template for an object. It is an instance of a class.
It is a logically entity. It is a physical entity.
It does not allocate the memory. It allocates the memory.
It can’t manipulate. It can manipulate.
It is declared once. It is declared many times.
To declare a class we will use class To declare object we will use new keyword.
keyword.

7. What is the difference between Abstraction and Encapsulation?

Abstraction Encapsulation
Hiding internal implementation and The process of encapsulating or grouping
highlighting the set of services is called variables and its associate methods in a
abstraction. single entity is called encapsulation.
It is used to hide the data. It is used to protect the data.
Using abstract classes and interfaces we Using access modifiers we can implements
can implements abstraction. encapsulation.
It is a process of gaining the information. It is a process of containing the
information.
It solves an issue at design level. It solves an issue at implementation level.

IHUB TALENT MANAGEMENT NIYAZ UL HASAN


8. What is the difference between POJO class and Java Bean class?

POJO Java Bean


It can’t be serialized. It can be serialized.
Fields can have any visibility. Fields can have only private visibility.
There may or may not have 0-arg It must have 0-argument constructor.
constructor.
It does not extend any other class. It can extends.
It does not implement any other interface. It can implements.
It does not use any outside annotation. It uses outside annotation.

9. What is the difference between Composition and Aggregation?

Composition Aggregation
Without existing container object there is a Without existing container object there is a
no chance of having contained object is chance of having contained object is called
called composition and aggregation. aggregation.
It is strongly association. It is weakly association.

10. What is the difference between default class and public class?

default class public class


To declare default class we should not use To declare public class we should use public
any access modifier. access modifier.
It we declare any class as default then we It we declare any class as public then we
can access that class within the package. can access that class within the package
and outside the package.

11. What is the difference between final class and abstract class?

final class abstract class


To declare final class we will use final To declare abstract class we will use
keyword. abstract keyword.
We can’t create child class (Not inherited). We can create child class (inherited).
Object creation is possible (instantiate). Object creation is not possible.

IHUB TALENT MANAGEMENT NIYAZ UL HASAN


12. What is the difference between Method overloading and Method overriding?

Method overloading Method overriding


Having same method names with Having same method name with same
difference signatures in a single class is signatures in two different classes is called
called method overloading. method overriding.
It is a compile time polymorphism. It is runtime polymorphism.
Method resolution taken care by compiler Method resolution taken care by JVM
based on reference type. based on runtime object.
Private and final methods can be Private and final methods can’t be
overloaded. overridden.

13. What is the difference between Mutable and Immutable object?

Mutable Immutable
After object creation if we perform any After object creation if we perform any
changes then all changes will reflect in a changes then for every change a new
same object. object will be created.
Fields can be change after object creation. Fields can’t be change after object creation.
It contains setter and getter methods. It contains only setter method.
StringBuffer, StringBuilder, Date are String, Wrapper classes are immutable.
mutable.

14. What is the difference between StringBuffer and StringBuilder?

StringBuffer StringBuilder
Every method present in StringBuffer is No method present in StringBuilder is
synchronized. synchronized.
At a time only one thread is allow to Multiple Threads are allowed to operate
operate on the StringBuffer object hence simultaneously on the StringBuilder object
StringBuffer object is Thread safe. hence StringBuilder is not Thread safe.
It increases waiting time of the Thread and Threads are not required to wait and hence
hence relatively performance is low. relatively performance is high.
Introduced in 1.0 version. Introduced in 1.5 version.

15. What is the difference between final, finally and finalize method?

Final:
Final is the modifier applicable for class, methods and variables.
If a class declared as the final then child class creation is not possible.
If a method declared as the final then overriding of that method is not possible.
If a variable declared as the final then reassignment is not possible.

Finally:
It is the block always associated with try catch to maintain clean up code which should be
executed always irrespective of whether exception raised or not raised.

IHUB TALENT MANAGEMENT NIYAZ UL HASAN


Finalize:
It is a method which should be called by garbage collector always just before destroying an
object to perform cleanup activities.

16. What is the difference between Interface and Abstract class?

Interface Abstract class


To declare interface we will use interface To declare abstract class we will use
keyword. abstract keyword.
It is a collection of abstract methods, It is a collection of abstract methods and
default methods and static methods. concrete methods.
We can achieve multiple inheritance. We can’t achieve multiple inheritance.
We can’t declare blocks. We can declare blocks.
We can’t declare constructor. We can declare constructor.
To write the implementation of abstract To write the implementation of abstract
methods we will use implementation class. methods we will use sub class.
If we know only specification (not If we know partial implementation then we
implementation) then we need to use need to use abstract class.
interface.

17. What is the difference between checked and unchecked exceptions?

Checked exceptions Unchecked exceptions


Exceptions which are checked by the Exceptions which are checked by the JVM at
compiler at the time of compilation are the time of runtime are called unchecked
called checked exceptions. exceptions.
We can handle checked exceptions using Not required to handle explicitly.
try and catch block.
Program flow will interrupt and control Program execution will halt with an error
transfer to catch block. message.
InterruptedException, IOException, ArithmeticException, ClassCastException,
FileNotFoundException are checked IllegalArgumentException are unchecked
exceptions. exceptions.

18. What is the difference between List and Set interface?

List Set
It is an indexed sequence. It is a non-indexed sequence.
List allows duplicate objects. Set does not allow duplicate objects.
Insertion order is preserved. Insertion order is not preserved.
Multiple null insertion is possible. Null insertion is possible only once.
List implementations are ArrayList, Set implementations are HashSet,
LinkedList, Vector and Stack. LinkedHashSet and TreeSet.

IHUB TALENT MANAGEMENT NIYAZ UL HASAN


19. What is the difference between Arrays and Collections?

Arrays Collections
It is a collection of homogeneous data It is a collection of homogeneous and
elements. heterogeneous data elements.
Arrays are fixed in size. Collections are growable in nature.
Performance point of view arrays are Memory point of view collections are
recommended to use. recommended to use.
Arrays are type safe. Collections are not type safe.
Arrays are not implemented based on data Collections are implemented based on data
structure concept so we can’t expect any structure concept so we can expect
readymade (utility) methods. readymade (utility) methods.
It holds primitive and object types. It holds only object types but not primitive
types.

20. What is the difference between ArrayList and Vector?

ArrayList Vector
No method is synchronized Every method is synchronized
At a time multiple Threads are allow to At a time only one Thread is allow to operate
operate on ArrayList object and hence on Vector object and hence Vector object is
ArrayList object is not Thread safe. Thread safe.
Relatively performance is high because Relatively performance is low because
Threads are not required to wait. Threads are required to wait.
It is non legacy and introduced in 1.2v. It is legacy and introduced in 1.0v.

21. What is the difference between ArrayList and LinkedList?

ArrayList LinkedList
The underlying data structure is resizable The underlying data structure is doubly
array or growable array. linked list.
ArrayList is better for storing and accessing LinkedList is better for manipulating data.
data.
The memory location for the elements of The location for the elements of a linked list
an ArrayList is contiguous. is not contagious.
When an ArrayList is initialized, a default There is no case of default capacity in a
capacity of 10 is assigned to the ArrayList. LinkedList.

IHUB TALENT MANAGEMENT NIYAZ UL HASAN


22. What is the difference between HashSet and LinkedHashSet?

HashSet LinkedHashSet
The underlying data structure is Hashtable. The underlying data structure is Hastable
and LinkedList.
Insertion order is not preserved. Insertion order is preserved.
Introduced in 1.2 version. Introduced in 1.4 version.

23. What is the difference between HashSet and TreeSet?

HashSet TreeSet
The underlying data structure is Hashtable. The underlying data structure is Balanced
Tree.
Null insertion is possible. Null insertion is not possible.
Heterogeneous objects are allowed. Heterogeneous objects are not allowed.
Insertion order is not preserved. Insertion order is sorting order of an object.

24. What is the difference between Comparable and Comparator interface?

Comparable Comparator
It is present in java.lang package It is present in java.util package
It contains only one method i.e It contains two methods i.e compare() and
compareTo() equals()
If we depend upon natural sorting order If we depend upon customized sorting order
then we need to use Comparable interface. then we need to use Comparator interface.

25. What is the difference between HashMap and LinkedHashMap?

HashMap LinkedHashMap
The underlying data structure is Hashtable. The underlying data structure is Hastable
and LinkedList.
Insertion order is not preserved. Insertion order is preserved.
Introduced in 1.2 version. Introduced in 1.4 version.

26. What is the difference between HashMap and TreeMap?

HashMap TreeMap
The underlying data structure is Hashtable. The underlying data structure is Red Black
Tree.
Insertion order is not preserved. Insertion order is sorting order of an object.
Both key and value can be null. Key can’t be null but value can be null.

IHUB TALENT MANAGEMENT NIYAZ UL HASAN


27. What is the difference between HashMap and Hashtable?

HashMap Hashtable
The underlying data structure is The underlying data structure is
Hashtable. Hashtable.
Both key and value can be null Both key and value can’t be null.
It is a non-legacy class. It is a legacy class
It is introduced in 1.2 version. It is introduced in 1.0 version
Methods are not synchronized. All methods are synchronized.

28. What is the difference between Enumeration, Iterator and ListIterator?

Enumeration Iterator ListIterator


It is used to read objects one It is used to read objects It is used to read objects one
by one from legacy one by one from any by one from List Collection
Collection objects. Collection objects. objects.
It contains 2 methods i.e It contains 3 methods It contains 9 methods i.e
hasMoreElements() and i.e hasNext(), next() and hasNext(), next(),
nextElement(). remove() hasPrevious(), previous(),
remove(), set(), add(),
previousIndex() and
nextIndex().
It performs read operation. It performs read and It perform read, remove,
remove operation. adding and replacement of
new objects.
We can create object by We can create object by We can create object by
using elements() method. using iterator() method. using listIterator() method.
It is not a universal cursor. It is a universal cursor. It is a bi-directional cursor.

29. What is the difference between Collection and Collections?

Collection Collections
It is a root interface for entire collection It is a utility class.
framework.
It is used to represent a group of individual It defines several utility methods that are
objects in a single unit. used to operate on collection.
It contains abstract methods, static It contains only static methods.
methods and default methods.

IHUB TALENT MANAGEMENT NIYAZ UL HASAN


30. What is the difference between this key and super keyword in java?

this keyword super keyword


It is used to refer current class object It is used to refer super class object
reference. reference.
It is used to refer current class variables. It is used to refer super class variables.
It is used to refer current class methods. It is used to refer super class methods.
It is used to refer current class constructors. It is used to refer super class constructors.

31. What is the difference between RDBMS and RDBMS database?

DBMS RDBMS
DBMS stands Database Management RDBMS stands for Relational Database
System Management System
It stores the data in the form of files It stores the data in the form of tables
It is designed to handle small amount of It is designed to handle large amount of
data data
It provides support for a single user at a It provides support for multiple users at a
time time
Normalization is not possible for DBMS Normalization is possible for RDBMS
No security of data High security of data

32. What is the difference between RDBMS and MongoDB database?

RDBMS MongoDB
It is a relational database. It is a non-relational or document based
database.
It can’t stores the data in key and value pair. It stores the data in key and value pair.
Not suitable for hierarchical data storage. Suitable for hierarchical data storage.
It has a predefined(static) schema. It has a dynamic schema.
It contains tables. It contains Collections.
It is a row based. It is a document based.
It is a column based. It is a field based.
It is slower. It is faster.
It supports SQL query language. It supports JSON query language.

33. What is the difference between Normalization and De-normalization?

Normalization Denormalization
It increases the complexity due to multiple It reduces the complexity due to single table
tables
No redundant data Redundant data
No waste of memory Waste of memory
Slower reads Slower writes
Low data availability High data availability
Need of joins No need of joins

IHUB TALENT MANAGEMENT NIYAZ UL HASAN


34. What is the difference between delete and truncate command?

Delete truncate
It is a DML command. It is DDL
It deletes the data temporary. It deletes the data permanently.
We can rollback the data. We can’t rollback the data.
Where clause can be used. Where clause can’t be used.

35. What is the difference between ROWID and ROWNUM?

ROWID ROWNUM
It is physical address of row. It is a sequential number for row.
It is permanent. It is temporary.
It returns address of row. It returns numeric value.
It is automatically generated at the time of It is automatically generated at the time of
insert. select.

36. What is the difference between simple view and complex view?

Simple view Complex view


If a view is created by using one base table If a view is created by using more than one
is called simple view. table is called complex view.
DML operations are allowed. DML operations are not allowed.
We can’t use group functions. We can use group functions.
It does not include NOT NULL columns from It includes NOT NULL columns from base
base table. table.

37. What is the difference between inner join and outer join?

Inner Join Outer Join


It is similar to equi join. It is extension of equi join.
It will return matching record. It will return matching as well as not
matching records.
To create inner join we will use INNER JOIN To create outer join we will use LEFT OUTER
or JOIN clause. JOIN, RIGHT OUTER JOIN , FULL OUTER JOIN
clause.

IHUB TALENT MANAGEMENT NIYAZ UL HASAN


38. What is the difference between SQL and PL/SQL?

SQL PL/SQL
It is Structured Query Language. It is Procedural Language extension to the
Structured Query Language.
It is data-oriented language. It is application-oriented language.
It directly interacts with database server. It does not interact with database server.
It does not provide errors and exceptions. It provides errors and exceptions.
It does not give programming features like It gives programming features like control
control statements, loops, variables and statements, loops, variables and etc.
etc.
It is used to write queries in DML, DDL, DRL, It is used to write procedures, functions,
TCL and DCL. packages, cursors and triggers.

39. What is the difference between stored procedures and functions?

Procedures Functions
It may or may not returns a value. It always returns a value.
DML operations are allowed. DML operations are not allowed.
Can’t be invoke by using select command. Can be invoke by using select command.
It is compiled once. It is compiled every time.

40. What is the difference between DatabaseMetaData and ResultSetMetaData?

DatabaseMetaData ResultSetMetaData
It provides metadata of a database. It provides metadata of a table.
It gives information about database It gives information about number of
product name, database product version, columns, type of columns, size of columns,
database driver name, database driver column counts and etc.
version, username and etc.
We can create object by using We can create object by using
getMetaData() method of Connection getMetaData() method of ResultSet object.
object.

41. What is the difference between Scrollable and Non-Scrollable ResultSet object?

Scrollable ResultSet Non-Scrollable ResultSet


It is not default ResultSet object. It is default ResultSet object.
Cursor can move in both forward and Cursor can move only in forward direction.
backward direction.
We can read random records. We can’t read random records.
Performance is high. Performance is low.

IHUB TALENT MANAGEMENT NIYAZ UL HASAN


42. What is the difference between ServletConfig and ServletContext object?

ServletConfig ServletContext
It is created by web container for every It is created by web container for every web
servlet. application.
It is created during the initialization process It is created during the deployment of web
of servlet. application.
As long as servlet is executing, Servletconfig As long as web application is executing,
object will be available. ServletContext object will be available.
It reads configuration information from It reads configuration information from
web.xml file which is local to one servlet. web.xml file which is global to all servlets.
Using getServletConfig() method we will Using getServletContext() method we will
create ServletConfig object. create ServletContext object.

43. What is the difference between Servlets and JSP?

Servlets JSP
To work with servlets strong java To work with JSP strong java knowledge is
knowledge is required. not required.
It is not suitable for non-java programmers. It is suitable for non-java programmers.
It does not support tags. It supports tags.
It does not give any implicit object. It gives 9 implicit objects.
Configuration of servlet program in Configuration of jsp program in web.xml
web.xml file is mandatory. file is optional.
Handling exceptions are mandatory. Handing exceptions is optional.
We can’t maintain HTML code and Java We can maintain HTML code and Java code
code separately. separately.
It runs faster than JSP. It runs slower than servlet because it takes
time to compile the program and convert
into Servlets.

44. What is the difference between GET and POST methodology?

GET POST
It is a default methodology. It is not a default methodology.
It sends the request fastly. It sends the request bit slow.
It carries limited amount of data. It carries unlimited amount of data.
It is not suitable for secure data. It is suitable for secure data.
Not suitable for encryption and file Suitable for encryption and file uploading.
uploading.
To process GET methodology we will use To process POST methodology we will use
doGet(-,-) method. doPost(-,-) method.

IHUB TALENT MANAGEMENT NIYAZ UL HASAN


45. What is the difference between GenericServlet and HttpServlet?

GenericServlet HttpServlet
It is present in javax.servlet package. It is present in javax.servlet.http package.
It is protocol independent. It is protocol dependent.
Session management is not possible. Session management is possible.
Redirection is not possible. Redirection is possible.
We can define service() method. We can define doGet(), doPost(), doPut(),
doOption(), doTrace(), doHead() and
doDelete() method.

46. What is the difference between forward() and sendRedirect() method?

forward() sendRedirect()
It sends the request to resource that is It sends the request to resource that is
present in same server. present in same sever or different server.
It passes same request to next resource. It passes new request to next resource.
To forward the request we will use To forward the request we will use
RequestDispatcher object of sendRedrect() method of
HttpServletRequest. HttpServletResponse.
It works within the server. It works within the server and outside the
server.

47. What is the difference between spring framework and spring boot?

Spring framework Spring boot


Spring is an open-source lightweight Spring Boot is built on top of spring
framework widely used to develop framework and it is widely used to develop
enterprise applications. REST APIs.
The most important feature of the Spring The most important feature of the Spring
Framework is dependency injection. Boot is Autoconfiguration.
It helps to create a loosely coupled It helps to create a stand-alone application.
application.
To run the Spring application we need to Spring Boot provides embedded servers
set the server explicitly. such as Tomcat, Jetty and undertow.
It doesn’t provide support for the in- It provides support for the in-memory
memory database. database such as H2, HSQL, Derby.
Dependencies will be added by the Dependencies will be added by the spring
programmer in pom.xml file. boot component called starters.

IHUB TALENT MANAGEMENT NIYAZ UL HASAN


48. What is the difference between @Controller and @RestController?

@Controller @RestController
It is used to develop spring MVC based It is used to develop RESTful Web Services.
applications.
It is a specialized version of @Component It is a specialized version of @Controller
annotation. annotation.
We need to use @ResponseBody in every It is a combination of @Controller and
handler method. @ResponseBody annotation.
It returns view in spring MVC. It does not return view.
It is added to Spring 2.5 version. It is added to Spring 4.0 version.

49. What is the difference between @RequestMapping and @GetMapping?

@RequestMapping @GetMapping
It is used to map request to controller It is used for mapping the request onto
methods. specific handler method.
It is a class level and method level It is a method level annotation.
annotation.
It is used for all kind of HTTP methods. It is used only for HTTP GET method.

50. What is the Difference between @RequestBody and @ResponseBody?

@RequestBody @ResponseBody
This annotation indicates that Spring This annotation indicates that Spring should
should deserialize HttpRequest body(JSON) serialize java object into JSON or XML or
into Java object. simple text.
It is used with POST, PUT & PATCH It is used with GET method.
methods.
Application for incoming request data. Application for outgoing response data.

51. What is the difference between CrudRepository and JpaRepository?

CrudRepository JpaRepository
It extends Repository interface. It extends CrudRepository and
PagingAndSortingRepository.
It contains methods like save(), findAll(), It contains extra methods related to JPA
delete(), count() And etc. such as delete records in batch and flushing
the data directly to the database.
It does not provide methods for It provides all the methods for implementing
implementing pagination and sorting. pagination and sorting.

IHUB TALENT MANAGEMENT NIYAZ UL HASAN


52. What is the difference between application.properties and application.yml?

application.properties application.yml
It follows non-hierarchical structure. It follows hierarchical structure.
We can configure only one spring profile. We can configure multiple spring profiles.
It is primarily used in java. It is used in many languages like Java,
python, Ruby and etc.
Supports key/val, but doesn’t support Supports key/val, basically map, List and
values beyond the string. scalar types (int, string etc.)

53. What is the difference between Spring Bean and POJO class?

Spring Bean POJO


An object that is managed by the spring IoC An object that is managed by the user is
container is called spring bean. called pojo. Any java object is a pojo.
Spring beans can be inject to other beans POJOs are not managed by the spring so
using dependency injection mechanism. they are not eligible for automatic
dependency injection mechanism.
Spring beans have restrictions. POJOs don't have restrictions.

IHUB TALENT MANAGEMENT NIYAZ UL HASAN

You might also like