Difference between Java Application and Applets

Slno. Java Application  Applets
01. Java Applications are stand-alone programs i.e. this program can run on a single system at a time normally.
Applets programs are designed and embedded in a HTML web document. i.e. this program can be run on a multiple connected system at a time normally. 
02. It can be run/executed independently on a system.They are executed at command line by Java.exe, without use of web browser. It can’t be run/executed independently.They can only be executed inside a Java compatible container, such as a web browser or appletviewer i.e. it uses another application program for its execution.
03.  It is comparatively large program. It is comparatively small program.
04. They require Java compiler and Java Interpreter (or JRE) for execution of java program. They require a Java-enabled browser(such as google chrome/Firefox)/applet viewer API for execution of java program.
05. It requires a main method() for its program execution i.e. It has a single point for entry to execution
It does not require a main method() for its program execution i.e. does not have a single point of entry for execution.
06. Can access any data or file available on the system. Applets cannot access files residing on the local computer.
07. It doesn’t require any Graphical User Interface (GUI). It must run within a GUI.
08 Java applications have full access to local file system/disk and network i.e. Applications are capable of performing required operations to the files on the local computer.
Applets have no local disk and network access i.e. The files cannot be read and write on the local computer through applet.
09. It can access all kinds of related resources required for the system.
It can only access the web browser related services.
10.  Communication with other servers, if required is  possible.
Cannot communicate with other servers.
11. It is a trusted and more secure application because it runs on a stand alone system and doesn’t require much security. It requires high-security constraints as applets are untrusted and run in network environments.
12. It is explicitly/directly run and installed on a local system.  It doesn’t require any explicit installation on a local system.
13.  Main method is required to create it. Applets class is required to create it.
14.  Program is initiated from main method. Program is initiated from init()method.
15. Applications have no inherent security restrictions, and can perform read/write to files in local System. Applets cannot perform read/write to files in local system This is to provide security.
16. Applications have no special support
in HTML for embedding or downloading
Applets can be embedded in HTML pages
and downloaded over the Internet

Difference between Java and Java Script

  Both share almost the same syntax which is mostly based on C.
  Both have a strong web development community built around them.
Slno. Java Java Script
01. Java is an OOP programming language Java Script is an OOP scripting language.
02. Java is class-based. JavaScript is prototype-based.
03.  Java runs in a virtual machine or browser. JavaScript runs solely in a browser.
04. Java code needs to be compiled.  JavaScript code are all in text. They require different plug-ins.
05. Java constructors are special functions that can only be called at object creation. JavaScript “constructors” are just standard functions.
06. Java uses block-based scoping. JavaScript uses function-based scoping.
07. Java has an implicit “this” scope for non-static methods, and implicit class scope; JavaScript has implicit global scope.


Difference between Final, Finally & Finalize

Slno. Final  Finally Finalize 
Final is a keyword.
Finally is a block.
Finalize is a method.
It is associated with classes, variables and methods.
It is always associated with try and catch block i.e. in exception handling code.
It is associated/applied to objects.
Final class can’t be inherited, final method can’t be overridden and final variable value can’t be changed during the execution of program.
It releases the used resources in ‘try’ block ultimately.
 It is used in garbage collection work.
Final method is executed upon its call.
‘Finally’ block executes just after the execution of’try-catch’ block.
finalize() method executes just before the destruction of the object.


Difference between Method Overloading and Method Overriding

Slno. Similarities
01. Both are types of Polymorphism.
Slno. Method Overloading Method Overriding
01. It occurs at compile time . It occurs at run time.
02. It shows early binding/static polymorphism. It shows late binding/dynamic polymorphism.
03. It occurs inside a class.  It occurs with two classes having inheritance relationship.
04. It may or may not require inheritance. It always require inheritance.
05. Method Overloading parameters must be different. Method Overriding parameters must be same.
06. Method Overloading gives better performance comparatively. Method Overriding gives comparatively less performance.
07. It can be performed with static methods. It cannot be performed with static methods.
08. Return type in method overloading may or may not same.  Method overriding process must have same/covariant return type . 
09. Private and final methods can be overloaded. Private and final methods can not be overridden.
10. It  is used to increase the readability of the program. It is used to provide specific implementation of the methods.

Difference between Vector and ArrayList

Slno. Similarities
01. Both are java classes.
02. Both can grow and shrink dynamically to maintain the optimal use of storage when overflow and deletion happens i.e. both provide re-sizable array. (however the way they resized is different as mentioned in slno 4).
Both also allow null and duplicates.
Both use generic array internally as data structure.
Slno. Vector ArrayList
01. Available from JDK 1.0 (Older) . Available from JDK 1.2 (New) .
02. They are Synchronized mode of working in multi-threading environment(This means  that if one thread is working on Vector, no other thread can get a hold of it. Unlike ArrayList, only one thread can perform an operation on vector at a time). They are non-synchronized (which means that multiple threads can work on ArrayList at the same time. For example – if one thread is performing an add operation on ArrayList, there can be an another thread performing remove operation on ArrayList at the same time in a multithreaded environment).
03. They are slower in operation/performance because of synchronization. They are comparatively faster in operation/performance(about 20 – 30%) because of non-synchronization.
04. The default initial capacity of an vector is comparatively  large. Vector each time doubles (100%) its array size during expansion. The default initial capacity of an ArrayList is pretty small. ArrayList grow 50% of its size each time during expansion.
05. Vector is preferred if we need synchronization. ArrayList is preferred if we do not need synchronization.
06. They are better choice if the program is thread-safe i.e. the thread which works on Vector gets a lock on it which makes other thread wait till the lock is released.. ArrayList is not a better choice if our program is thread-safe. 
07. They use import java.util.Vector; . They use import java.util.ArrayList; .
08. Vector is a legacy class as It was introduced in JDK 1.0.. ArrayList is not a legacy class as It was introduced in JDK 1.2.
09. A vector can use the Iterator/ Enumeration interface to traverse the elements. ArrayList uses the Iterator interface to traverse the elements.
10. Vector’s methods are synchronized. ArrayList’s methods are not synchronized.


Difference between String and String Buffer

Slno. String String Buffer
01. The length of the String object is static. The length of the String Buffer is dynamic.
02. String object is not editable/immutable.
String Buffer object is editable/mutable.
03. It Consumes more memory (due to static) during storage. It Consumes less memory (due to dynamic) during storage.
04. String is internally created in memory as constant pool. String Buffer is internally created in memory as Heap Memory.
05. String concatenation is slower. String Buffer Concatenation is faster.


Difference between Transient and Volatile

Slno. Transient Volatile
01. Transient keyword is used with instance variable to avoid serialization process for object in java.if a field  is transient its value will not be persisted.

Volatile variables are used in Concurrent programming in Java

02. It can be used along with static keyword. It cannot be used along with static keyword.
03. Transient variables are initialized with default value during de-serialization and there assignment or restoration of value has to be handled by application code.

When we declare a variable volatile, every thread reads its value from main memory and don’t used cached value available in every thread stack.volatile variable also prevents compiler from doing reordering which can compromise synchronization.

04. Transient is a variables modifier used in serialization. At the time of serialization, if we don’t want to save value of a particular variable in a file, then we use transient keyword. When JVM comes across transient keyword, it ignores original value of the variable and save default value of that variable data type. Volatile keyword is used to modify the value of a variable by different threads. It is also used to make classes thread safe. It means that multiple threads can use a method and instance of the classes at the same time without any problem. The volatile keyword can be used either with primitive type or objects.


Difference between Swing and AWT

Slno. Swing AWT
01. Swing is also called as JFC (Java Foundation classes). AWT stands for Abstract windows toolkit.
02. Swings components are also called light weight  because they do not require a native OS object to implement their functionality.. AWT components are also called Heavy weight components.
03. Swing components require javax.swing package. AWT components require java.awt package.
04. Swing components are made in purely java and hence they are platform independent. AWT components are platform dependent.
05. Swing has many advanced features like JTabel, Jtabbed pane which is not available in AWT AWT has no JTabel, Jtabbed pane etc.
06.  Swing UI are built on top of AWT with a richer set of lightweight components. Basically AWT came first and is a set of heavyweight UI components 
 07. An older JVM or java platform doesn’t support Swing . All versions of JVM or platform support AWT in java.
08.  Swing code is much larger. AWT is a thin layer of code on top of the OS
09.  It has more advanced GUI components. It has less advanced GUI components.
10.  Its execution is faster. Its execution is slower.
 11. It supports MVC concept.  It does not support MVC concept.
12.  Its component requires less memory space to execute it. Its component requires more memory space to execute it.


Difference between JSP and Servlets

Slno. JSP Servlets
01.  JSP is server side web page scripting language that is used to create dynamic web pages using Java. Servlets are Java programs that are already complied and are also used to create dynamic web pages in Java.
02. Actually JSP is an interface on top of Servlets. A servlet is a server-side program and written purely on Java.
03.  Extension name = .jsp Extension name = .java
04.  Java Server Pages (JSP) is a technology for developing web pages that support dynamic content which helps developers to insert java code in HTML pages by making use of special JSP tags and most of which start with <% and end with %> symbol. Java Servlets are java programs that run on a Web or Application server and act as a middle layer between a request coming from a Web browser or other HTTP client and databases or applications on the HTTP server. Using Servlets, we can collect input from users through web page forms, from a database or another source, and finally create web pages dynamically.
 05. They are Flexible and easy but slow. JSP runs slower because it has the transition phase and it takes compilation time to convert JSP page into Java Servlets/Servlet file. Once it is converted to a Servlet then it will start the compilation. They are less flexible but run faster than JSP and strict code guidelines.
06.  In JSP, Java code is written inside HTML code. In Servlet, HTML code is written inside Java code.
 07. The advantage of JSP programming over servlets is that we can build custom tags which can directly call Java beans program. JSPs can make use of the Java beans inside the web pages separately.
Servlet do not provide facility to create custom tags.Since it is written in Java, it follows all the Object Oriented programming techniques.
08.  In JSP, if we do any modifications in code then just we need to click on refresh button. Here recompilation, reloading and restarting the server is not required. In Servlet, if we modify the code then we need recompilation, reloading, restarting the server again. Thus, it is time consuming process.
09. A JSP program is compiled into a Java servlet before final execution. Once it is compiled into a servlet file, then it’s life cycle will be same as of servlet. But, JSP uses it’s own API for the life cycle. Executes inside a Web server, such as Apache Tomcat/IIS.
10. we can build custom tags using jsp API (a separate package available for writing the custom tags) which can be available as the re-usable components with lot of flexibility. We can not build any custom tags.
11. It is easier to write code in jsp than servlets . It is comparatively difficult to write code in servlets .
12.  JSP has its own life cycle methods to complete the jobs such as jspInit(), jspService() and jspDestroy() Servlet has the life cycle methods init(), service() and destroy() to complete the job.
 13. In MVC architecture, JSP acts as view. In MVC architecture, Servlet acts as controller.
14.  In JSP, no need to override service() method. In Servlet, service() method need to override.
15.  In JSP, session management is by default enabled. In Servlet, session management is not by default enabled rather we need to enable it explicitly.
 16. In JSP, we have implicit object support. In Servlet, we do not have implicit object. i.e. to use an object in servlet program then we need to get object explicitly form the servlet.
 17. In JSP, we can separate the business logic from the presentation logic to uses java Bean technology. In Servlet, we implement business logic & presentation logic combinely.
18.  In JSP, related packages can be imported anywhere in the program i.e. at the top, middle and bottom. In Servlet, all the related packages must be imported on top of the servlet program.
19.  JSP run slower as compared to Servlet because JSP is first converted into Servlet and then executed. Servlet run faster than JSP.
20.  JSP is preferred when less data processing is required. Servlet is preferred when more data processing and manipulation is required.
 21. JSP accepts only http/https requests. Servlets accept all types of protocol requests.
 22. We can achieve functionality of JSP at client side by running Java Script at client side i.e. client-side validations can be used in JSP  program using Java Script method. In Servlet, there is no such methods exist for running Java Script on the client side page i.e. there are no such methods for servlets.


Difference between Throw and Throws


Slno Throw Throws

The throw keyword is used to throw an exception directly/explicitly. Generally,  throw keyword is used to throw user defined custom exceptions.

The throws keyword is used to declare that a method may throw one or more exceptions, which means that it works similar to the try-catch block.The caller must catch the thrown exceptions.
02. The throw is followed by an instance of exception class. The throws keyword is followed by exception class names.
03. The throw keyword is used to throw an exception from within a method. When a throw statement is encountered and executed, execution of the current method is stopped and control returned to the caller. The throws keyword is used with the method signature.
04. The checked category of exceptions cannot be propagated with throw only. The checked category of exception can be propagated with throws
05. We cannot throw multiple exceptions using throw keyword rather only one instance of exception is thrown using it. We can declare & throw multiple instance of exceptions ,separated each by comma, at a time.

Difference between Process & Thread


Slno Process Thread
01. A Program’s segment in the execution is called the process. A thread is a subset of the process.
02. Processes are independent to each other. Threads are dependent to each other. 
03. Process have different address space in memory. Threads contain a shared address space.
04. Context switching between process is faster in inter process communication. Context switching among threads are slower in inter thread communication.
05. Inter-process communication occurs among processes to complete operation and is slower and expensive. Inter-thread communication occurs among threads to complete operation and is faster and less expensive.
06. Any change in Parent process doesn’t affect the child process.  Changes made in parent thread can affect the child thread.
07. Process is large piece. Thread is small piece.

Difference between JDBC & ODBC


Both are API.
01. Stands for ‘Java Database Connectivity’.
Stands for ‘Open Database Connectivity’.
02. Developed by Sun MicroSystem in 1996 with JDK 1.1. Developed by Microsoft Incorporation in 1992.
03. JDBC is language and platform dependent (Java Specific). ODBC is language and platform independent I.e. An application written in any language can use ODBC to access different types of databases and hence, it is language and platform independent.
04. Code is easy to understand. Code is complex.
05. Mainly used with Java. Widely used API with C, C++,Java etc.
06. We can use JDBC API in any platform. We can use ODBC API in windows platform mainly.
07. It is for object oriented language. It is for procedural language.
08. JDBC drivers are slower. ODBC drivers are faster.
09. It is comparatively more secured. It is comparatively less secured.
10.  It is written in java.  It is written in C language.

 518 total views,  1 views today

Categories: Java

1 Comment

Shabistan tashneem · June 18, 2019 at 9:21 PM

Very helpful for tommorow Java exam
Thanks you 😌

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.