Showing posts with label java interview. Show all posts
Showing posts with label java interview. Show all posts

Saturday, 8 May 2021

Java Interview Question

What is transient variable?

Transient variable can't be serialize. For example if a variable is declared as transient in a Serializable class and the class is written to an ObjectStream, the value of the variable can't be written to the stream instead when the class is retrieved from the ObjectStream the value of the variable becomes null.

What do you understand by Synchronization?

Synchronization is a process of controlling the access of shared resources by the multiple threads in such a manner that only one thread can access one resource at a time. In non synchronized multithreaded application, it is possible for one thread to modify a shared object while another thread is in the process of using or updating the object's value. Synchronization prevents such type of data corruption.
E.g. Synchronizing a function:

public synchronized void Method1 () {
// Appropriate method-related code.
 
}
E.g. Synchronizing a block of code inside a function:
public myFunction (){
synchronized (this) {
 

// Synchronized code here.
}
}



What is Collection API?

The Collection API is a set of classes and interfaces that support operation on collections of objects. These classes and interfaces are more flexible, more powerful, and more regular than the vectors, arrays, and hashtables if effectively replaces.
 
Example of classes: HashSet, HashMap, ArrayList, LinkedList, TreeSet and TreeMap.
Example of interfaces: Collection, Set, List and Map.

Explain the Encapsulation principle.

Encapsulation is a process of binding or wrapping the data and the codes that operates on the data into a single entity. This keeps the data safe from outside interface and misuse. One way to think about encapsulation is as a protective wrapper that prevents code and data from being arbitrarily accessed by other code defined outside the wrapper.
 


Explain the different forms of Polymorphism.
From a practical programming viewpoint, polymorphism exists in three distinct forms in Java:
 
  • Method overloading 
  • Method overriding through inheritance 
  • Method overriding through the Java interface 
 
 
 
Happy Learning .. Wait for more I will added soon..... :)

Saturday, 2 September 2017

what are Java features ?

Java 5 Features:


    > For-each loop
    > Autoboxing and Unboxing
    > Covariant Return Type
    > Annotation
    > Generics
    > Enum
    > Static Import
    > Varargs
    

Friday, 1 September 2017

Difference between ear jar and war files ?

These files are simply zipped files using java jar tool. These files are created for different purposes. 


.jar files: The .jar files contain the group of .class files and libraries. 


.war files: The war file contains static resources i.e., html, js, css...etc and dynamic resources jsp, servlets etc and other files (web.xml) for necessary for the development of web applications. Combination of these files zipped in to one module called .War file. 


.ear files: The .ear file contains anything Java/J2EE (Enterprise) related files zipped in to one module called .ear file. It is deployed in Application server.

How to Encode/Decode URL Online

What is URL Encoding/Decoding?

URL encoding stands for encoding certain characters in a URL by replacing them with one or more character that consist of the percent character % followed by 2 hexadecimal digits. So URL encoding and decoding is used that a string conform to the the Uniform Resource Locators Specification – RFC 1738.

Online Websites for Encoding / Decoding URL:


Thursday, 31 August 2017

What is Class Loader ? What are the Types (Hierarchy) of Java Class Loaders

Class Loader is used to load classes and interfaces.


Types of class loader


  • Bootstrap class loader : This class loader is responsible for loading core java API classes like rt.jar Bootstrap class loader is native implementation and so they may differ across different JVMs. Location :- jdk/jre/lib/rt.jar 

Wednesday, 30 August 2017

Search String in Sorted String Array Using Binary search

Binary Search: Search a sorted array by repeatedly dividing the search interval in half. Begin with an interval covering the whole array. If the value of the search key is less than the item in the middle of the interval, narrow the interval to the lower half. Otherwise narrow it to the upper half. Repeatedly check until the value is found or the interval is empty.


We basically ignore half of the elements just after one comparison.