Our new report is live! State of AI for Software Developers Report 2024 Read it now→

Our new report is live! State of AI for Software Developers Report 2024 Read it now→

Advanced Java Interview Questions For Senior Developers

March 7, 2022

What are the most frequently asked Java interview questions? How do I prepare for a Java developer interview?

Java is one of the most widely used and favourite programming languages today. It is a general-purpose, concurrent, simple, efficient class-based object-oriented language. Some areas where developers use Java are mobile applications (especially Android), desktop applications, web applications, database connections, and much more!

According to InfoWorld, 90% of Fortune 500 companies use Java, and the base of many Android applications is Java Programming, with 9 million Java developers worldwide.

Generally, the interviewers ask ‘advanced Java questions’ to check your programming knowledge and skills.

In this blog post, we’ll talk about typical Java interview questions and share some valuable tips on how to prepare for your interview.

Let’s start by taking a look at some of the most frequently asked Java interview questions

java interview questions - signup

10+ Advanced Java Interview Questions and Answers

1. Why isn’t Java considered a purely object-oriented language? What prevents Java from being completely object-oriented?

To be fully object-oriented, a programming language must have the following qualities: encapsulation, inheritance, polymorphism, abstraction, all predefined types are objects, all user defined types are objects, all operations on objects must be done only with methods shown in objects.

Pure object-oriented languages have features that treat or support everything within the program as objects. They don’t support primitive data types (int, char, float, bool, etc.).

Though java follows all the four object-oriented concepts,

  • It has predefined primitive data types (which are not objects),
  • And it also allows you to access the members of a static class without creating an object of it.

Therefore, Java is not a fully object-oriented language.

2. What do constructors do in Java? What are the differences between constructors and methods?

Constructors in Java initializes objects. They set initial values for object attributes.

Whereas methods execute certain statements.
Let’s look at the important differences between Constructors and Methods.

Sr.No. Key Constructors Methods
1 Purpose Constructors compose and initialize an object. Methods execute definite statements.
2 Invocation Constructors are invoked indirectly by the system. Methods are to be invoked during software code.
3 Invocation Constructors are invoked when new keyword composes an object. Methods are invoked when they are called.
4 Return type Constructors can not have any return type. Methods can have a return type.
5 Object Constructors initialize an object which is not available. Methods can be invoked only on existing object.
6 Name Constructors must have the similar name as that of the class. A method name can not be same as class name.
7 Inheritance Constructors cannot be inherited by a subclass. Methods are inherited by a subclass.

3. What do you understand by thread in Java?

Threads make a program run more efficiently by doing multiple things simultaneously. They perform complex tasks in the background without interrupting the main program.
In Java, a thread is the path a program takes as it executes. As a set of nested statements or methods calls, it allows multiple activities to occur within a single operation.

java interview questions

4. Why do developers use BufferedReader to read any file in Java?

Java provides several mechanisms for reading from a file. An important class that helps accomplish this is the BufferedReader.

A BufferedReader reads the text in the input stream and buffers the characters into a string of characters.

BufferReader is fluent and fast, allowing you to also specify the size of the buffer. The default value is 8k, which is sufficient for most purposes.

5. What are the advantages and disadvantages of sockets?

Advantages:

  • Java applications can send only updated information.
  • Sockets cause low network traffic if efficiently used.
  • Sockets are flexible, sufficient and powerful.

Disadvantages:

  •  Java applications can establish communication only with the machine requested and not with any other machine on the network.
  • Sockets allow you only to send packets of raw data between applications. This means that both client-side and server-side have mechanisms to interpret the data.

6. What is the use of JSTL tags? Explain with the help of an example.

The JSP Standard Tag Library (JSTL) provides a set of tags to simplify JSP development; a useful collection of JSP tags that encompasses core functionality common to many JSP implementations.

JSTL supports common, structured tasks such as iteration and conditionals, tags for manipulating XML documents, internationalization tags, and SQL tags. It also provides a framework for integrating existing custom tags with JSTL tags.

JSTL <c:foreach> is an iteration tag used to loop or iterate through the nested body content a fixed number of times.
This tag is an alternative for Java loops like while, do-while or for.

JSTL includes five types of tags: Core Tags, Function Tags, Formatting Tags, XML Tags, SQL Tags.

7. What is JavaMail API? Which protocol does JavaMail API use?

The JavaMail API provides a platform- and protocol-independent framework for building mail and messaging applications.

The supported protocols in the JavaMail API are:

SMTP (Simple Mail Transfer Protocol): Provides a mechanism for transmitting e-mail.

POP (Post Office Protocol): POP is a mechanism used to retrieve mail from most people on the Internet. It means support for a single mailbox per user. RFC 1939 defines this protocol.

IMAP (Internet Message Access Protocol): Provides multiple mailbox support for each user, also mailbox can be shared by multiple users. It is defined in RFC 2060.

MIME (Multipurpose Internet Mail Extensions): It is not a mail transfer protocol. It only defines the content transmitted: messages, attachments, etc. There are many different documents that come into play here: RFC 822, RFC 2045, RFC 2046, and RFC 2047.

NNTP and Others: Third-party providers provide many protocols. Network News Transfer Protocol (NNTP), Secure Multipurpose Internet Mail Extensions (S/MIME), etc. are some of them.

8. What is ‘Session Tracking’ in Java?

Session Monitoring, session management in server application, monitors and protects a user’s state (data). It is a mechanism for storing user information and recognizing their requests.

Common methods used:
HTTP Session: HTTP is a protocol where every request made to the server is a new request.

Cookie: Cookies may contain a unique ID assigned to customers when they first visit a website.

Hidden Form Field: Hidden form fields add information such as a unique ID when sending a request to the server.

URL Rewrite: URL rewrite adds a unique session ID to the URL itself when it sends a request to the server.

9. How do I forward request to another page in JSP?

We can use the <jsp:forward> action to forward a request from one page to another JSP page.
It has a page property where we can specify the target page of the forward action.

If we want to pass the parameter to another page, we can add <jsp:param>. But you need to make sure that the redirect page is a JSP page to get the parameters to be processed.

10.What is the use of Java Transaction API (JTA)? What are the attributes of a transaction?

The Java Transaction API (JTA) allows applications to run distributed transactions that can access and update data in the computing resource.

A transaction is a logical unit of work that either succeeds or fails.
A distributed transaction can access and update data from multiple computing networked resources.

The different transaction attributes are as follows:
Necessary, Requires new, Compulsory, Supports, Not supported, Never.

java interview questions
java interview questions - signup

If you feel ready for your Java interview, now it’s time to find a great job opportunity that’s right for you!

TalentGrid is a platform for software developers who are actively looking for a job, allowing them to share their preferences and salary expectations with employers around the world.

By creating your TalentGrid developer profile, you’ll have an opportunity to be matched with global positions!

Ready to complete your free profile and find your next role in tech? Sign up today!

Recent Posts

Go to Top