Top 30 Java Entry Level Interview Questions and Answers

In this post, I will be sharing the top 30 java entry level interview questions and answers. If you are looking for placement in one of the top services companies like TCS, Wipro, Accenture, Infosys, Cognizant, etc. then you have landed in the right place. Let's dive deep into the interview questions.

Read Also: Java Interview Questions for Experienced

Q1 What are the main features of Java?

a.  Java is an Object-Oriented programming language
b.  Simple
c.  Distributed
d.  Java support Multithread
e.  Java is a Platform independent programming language
f.  Java is more secured than other languages
g.  Portable
h.  Robust

Q2 What is an Array?

The collection of similar data types is known as Array. You can find it in detail here.

Q3 Is it possible to declare an Array without Array size?

Top 10 Java 8 Coding and Programming Interview Questions and Answers

It has been 6 years since Java 8 was released. I have already shared the Java 8 Interview questions and answers. In this tutorial, I will be sharing the top 10 Java 8 coding and programming interview questions and answers. I have only used Stream API functions to solve the below questions. Please bookmark this page as I will keep adding more questions to it.

Read Also: Java 8 Interview Questions and Answers

Q1 Given a list of integers, find out all the even numbers exist in the list using Stream functions?

import java.util.*;
import java.util.stream.*;
public class JavaHungry {
    public static void main(String args[]) {
            List<Integer> myList = Arrays.asList(10,15,8,49,25,98,32);
            myList.stream()
                  .filter(n -> n%2 == 0)
                  .forEach(System.out::println);
    }
}

Output:
10, 8, 98, 32


Q2 Given a list of integers, find out all the numbers starting with 1 using Stream functions?

import java.util.*;
import java.util.stream.*;
public class JavaHungry {
    public static void main(String args[]) {
            List<Integer> myList = Arrays.asList(10,15,8,49,25,98,32);
            myList.stream()
                  .map(s -> s + "") // Convert integer to String
                  .filter(s -> s.startsWith("1"))
                  .forEach(System.out::println);
    }
}

Output:
10, 15

Top 20 Serialization Interview Questions and Answers

Serialization is the important topic of java interview. Java developers should know the answer to serialization interview questions.  In this article, we will look at 20 most important questions and answers of serialization. We have covered questions for both beginners and experienced professionals level.

Read Also: What is serialVersionUID in Java

1. What is Serialization in java?

A very common question asked during the java serialization interview. Every Java developer should know the answer to this question.  Serialization needed to write an object into a binary format that can be transferred over the network or stored in the database. Serialization prepares a stream of bytes of an object and the byte array consists of versionUID, class of the object, and the internal state of the object.

2. Describe the De-serialization process.

This is also a common interview question during the java interview. To build a java object from a stream of bytes is called deserialization. When a stream of bytes transferred over the network so another side of the network needs to revert back to java object. This process is called deserialization.

3. Why do we need to use Serialization in java?

[Solved] java.lang.NumberFormatException: For input string

java.lang.NumberFormatException for input string is one of the most common exceptions java programmers face while doing the coding. This exception occurs when someone tries to convert a String into primitive data types such as int, float, double, long, byte, short, etc. It happens only when the String is not valid to be converted into primitive datatype.

Read Also: Exception Handling Interview Questions

The methods like Integer.parseInt(), Float.parseFloat(), Double.parseDouble() etc. throw java.lang.NumberFormatException when someone tries to convert an invalid String into number.

public class JavaHungry
{
    public static void main(String args[])
    {
        String s = "1";
        int i = Integer.parseInt(s);
        System.out.println(i);
    }
}

Output:
1

The above code is perfect and will not throw any error or exception. The String “1” was successfully converted into Integer 1 because the String was legal to be converted into numerical data.

Now, change the above code a little bit and let see what happens:

[Solved] Initial heap size set to a larger value than the maximum heap size

In this short tutorial, I will be sharing how to solve the error "initial heap size set to a larger value than the maximum heap size". I have divided the post into two parts. In the first part, we will produce the error by passing VM/JVM parameters through the command line. In the second part, we will fix the error.

Read Also: Could not reserve enough space for object heap

What is -Xms and -Xmx

-Xms: In java, Xms is the minimum heap size that is allocated at initialization of JVM.
-Xmx: Xmx represents the maximum heap size JVM can use.

1. Producing the Error

Suppose we have below HelloWorld java program:

  public class HelloWorld
       public static void main( String args[] ) {
            System.out.println("Simple Java Program");       
       }
  }

Compile the above HelloWorld java program in command line/terminal: