Top Java Architecture Interview Questions (2021) | CodeUsingJava
















Most frequently asked Java Architecture Interview Questions


  1. Explain the architecture of Java J2EE.
  2. What are the different types of Java Platform Editions.
  3. What is Synchronization in Java?
  4. What are the main components of JDK?
  5. Why java is not fully platform independent?
  6. What are some of the necessary conditions for creating a POJO class in java?
  7. How to create our own exception in Java?
  8. How to delete a specific package in java?
  9. How to convert an Input Stream to the byte array?
  10. Can we define multiple main methods in java?


Explain the architecture of Java J2EE.

j2ee
It is a three tier architecture.
The Client tier is used for interaction with the end-user. It includes JSP, servlets or some dynamic interfaces.
The Middle tier is also known as the server tier. It consist of the configurations, the web services and the service class which consist business logic.
The Enterprise data tier consists of the data storage in the database.

What is Synchronization in Java?

Synchronization can be defined as the capability so that only one thread can access the shared resources at a time. It plays a key role in maintaining communication between the threads.

What are the main components of the JDK?

The main components of the JDK can be understood by the following diagram- A JDK is a combination of JRE and Developer tools. Java Virtual Machine and the Library classes are the components of JRE.
jdk


Why java is not fully platform independent?

Java is platform independent. Java compiler converts the java file to the bytecode(.class) file which is compiled by the JVM. It follows the approach of Write Once, Run Everywhere i.e on any platform where the environment is provided. The word environment refers to the Java Virtual Machine. Every operating system has its own jvm which executes the java code. So in reality, nothing can be 100% platform independent.

What are some of the necessary conditions for creating a POJO class in java?

  • It must have a default constructor.
  • It must have public getters and setter method.
The example of POJO class can be as follows-
        package com.codeusingjava.model;
    
    
        import com.fasterxml.jackson.annotation.JsonIdentityInfo;
        import com.fasterxml.jackson.annotation.ObjectIdGenerators;
        
        import lombok.Getter;
        import lombok.Setter;
        
        @Setter
        @Getter
        @JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class, property = "@id", scope = Student.class)
        public class Student {
        
            private String name;
            private String hobby;
            private int age;
        
            }
    


How to create our own exception in Java?

Though there are a lot of predefined Exception class in Java, but if we want to create our own custom exception class, then We need to extend the class with the Exception class or one of its sub class. Let us take an example-
    package com.codeusingjava.exception;
     public class NegativeAgeException extends Exception
     {
         public NegativeAgeException()
         {
             super();
         }
         public NegativeAgeException(int age)
         {
             System.out.println(age+"is negative");
         }
     }

    

How to delete a specific package in java?

We can delete the specific package in java and all the content from the package gets deleted. If we want to keep our subpackages, we can transfer them to another parent package of the delete one.

How to convert an Input Stream to the byte array?

Firstly we need to create a ByteArrayOutputStreamand then we copy al the content from the Input Stream into it. Finally the toByteArray method gets called.
 
 public static byte[] readFully(InputStream input) throws IOException
{
    byte[] buffer = new byte[8192];
    int bytesRead;
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    while ((bytesRead = input.read(buffer)) != -1)
    {
        output.write(buffer, 0, bytesRead);
    }
    return output.toByteArray();
}


Can we define multiple main methods in java?

It is not possible.The compiler gives the message "Method has been already defined inside the class".
 
    package javabeginner.programs;

    import java.util.Scanner;
    
    /**
     *
     * @author A to Z
     */
    public class Amount {
        
        public static void main(String[] args)
        {
            
        }
        public static void main(String[] args) {
        }    
java.lang.ExceptionInInitializerError Caused by: java.lang.RuntimeException: Uncompilable source code - method main(java.lang.String[]) is already defined in class javabeginner.programs.Amount at javabeginner.programs.Amount.(Amount.java:20) Exception in thread "main" C:\Users\A to Z\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1 BUILD FAILED (total time: 0 seconds)