RTU Advanced Java: Top 50+ Interview Questions in 2020

RTU Advanced Java Interview Questions And Answer

In this RTU Advanced Java Interview Questions ans Answer blog, I have compiled some best question and prepared the list which is the most important RTU Advanced Java Interview Questions and Answers which will set you apart in the interview process.

RTU Advanced Java Lab Viva Questions

Part -1


1.) Explain JDK, JRE and JVM?


It stands for Java Development Kit. It stands for Java Runtime Environment. It stands for Java Virtual Machine.
It is the tool necessary to compile, document and package Java programs. JRE refers to a runtime environment in which Java bytecode can be executed. It is an abstract machine. It is a specification that provides a run-time environment in which Java bytecode can be executed.
It contains JRE + development tools. It’s an implementation of the JVM which physically exists. JVM follows three notations: Specification, Implementation, and Runtime Instance.


Q2. Explain public static void main(String args[]) in Java.

main() in Java is the entry point for any Java program. It is always written as public static void main(String[] args).

  • public: Public is an access modifier, which is used to specify who can access this method. Public means that this Method will be accessible by any Class.
  • static: It is a keyword in java which identifies it is class-based. main() is made static in Java so that it can be accessed without creating the instance of a Class. In case, main is not made static then the compiler will throw an error as main() is called by the JVM before any objects are made and only static methods can be directly invoked via the class.
  • void: It is the return type of the method. Void defines the method which will not return any value.
  • main: It is the name of the method which is searched by JVM as a starting point for an application with a particular signature only. It is the method where the main execution occurs.
  • String args[]: It is the parameter passed to the main method.


Q3. Why Java is platform independent?

Java is called platform independent because of its byte codes which can run on any system irrespective of its underlying operating system.

Q4. Why Java is not 100% Object-oriented?

Java is not 100% Object-oriented because it makes use of eight primitive data types such as boolean, byte, char, int, float, double, long, short which are not objects.


Q5. What are wrapper classes in Java?

Wrapper classes convert the Java primitives into the reference types (objects). Every primitive data type has a class dedicated to it. These are known as wrapper classes because they “wrap” the primitive data type into an object of that class. Refer to the below image which displays different primitive type, wrapper class and constructor argument.

Q6. What are constructors in Java?
In Java, constructor refers to a block of code which is used to initialize an object. It must have the same name as that of the class. Also, it has no return type and it is automatically called when an object is created.

There are two types of constructors:

  • Default Constructor: In Java, a default constructor is the one which does not take any inputs. In other words, default constructors are the no argument constructors which will be created by default in case you no other constructor is defined by the user. Its main purpose is to initialize the instance variables with the default values. Also, it is majorly used for object creation.
  • Parameterized Constructor: The parameterized constructor in Java, is the constructor which is capable of initializing the instance variables with the provided values. In other words, the constructors which take the arguments are called parameterized constructors.


Q7. What is singleton class in Java and how can we make a class singleton?
Singleton class is a class whose only one instance can be created at any given time, in one JVM. A class can be made singleton by making its constructor private.


Q8. What is the difference between equals() and == in Java?
Equals() method is defined in Object class in Java and used for checking equality of two objects defined by business logic.

“==” or equality operator in Java is a binary operator provided by Java programming language and used to compare primitives and objects. public boolean equals(Object o) is the method provided by the Object class. The default implementation uses == operator to compare two objects. For example: method can be overridden like String class. equals() method is used to compare the values of two objects.


Q9. What are the differences between Heap and Stack Memory in Java?
The major difference between Heap and Stack memory are:

Features Stack Heap
Memory Stack memory is used only by one thread of execution. Heap memory is used by all the parts of the application.
Access Stack memory can’t be accessed by other threads. Objects stored in the heap are globally accessible.
Memory Management Follows LIFO manner to free memory. Memory management is based on the generation associated with each object.
Lifetime Exists until the end of execution of the thread. Heap memory lives from the start till the end of application execution.
Usage Stack memory only contains local primitive and reference variables to objects in heap space. Whenever an object is created, it’s always stored in the Heap space.


Q10. What is a package in Java? List down various advantages of packages.
Packages in Java, are the collection of related classes and interfaces which are bundled together. By using packages, developers can easily modularization the code and optimize its reuse. Also, the code within the packages can be imported by other classes and reused. Below I have listed down a few of its advantages:

  • Packages help in avoiding name clashes
  • They provide easier access control on the code
  • Packages can also contain hidden classes which are not
  • visible to the outer classes and only used within the package
  • Creates a proper hierarchical structure which makes it easier to locate the related classes



Part - 2

Q11. What do you think Java is platform independent?

Essentially, the core concept of Java lies in the fact that once written it can be run anywhere. More specifically, the bytecodes of Java can run on any platform, the underlying operations notwithstanding. So it is platform independent.


Q12. What do you mean by dynamic method dispatch?

Also known as runtime polymorphism, the name itself hints at the possible meaning. Specifically, it is a method in which the overridden method is resolved at runtime, not at compile time. More specifically, the concerned method is essentially called through a reference variable of a superclass.


Q13. Do you think it is feasible to override a static method in Java?

No, it is essentially impossible to override a static method in Java. Also, you cannot override a private method. At most, the programmer may create another private method with the same name as the child class.


Q14. What do you understand by the term multiple inheritance?

As the name itself hints, multiple inheritance is defined as the process in which a child class inherits the properties of multiple parent classes. Essentially, multiple inheritance, also known as the diamond problem, is not supported by Java.


Q15. What do you mean by the term Java Servlet?

A Java Servlet is defined as the server side technology which is meant to induce extension of web servers by corroboration of dynamic response and data persistence.


Q16. Tell us something about the prospects of session management in servlets.

A session is essentially defined as the dynamic state of random conversation between the client and the server. The essential communication channel includes a string of responses and requests from both sides. There are many ways of session management. For instance, some of the most common ones include the likes of cookie application, session management API, user authentication, HTML hidden field and URL rewriting. Typically, the most popular way of implementing session management is the employment of a session ID in the communicative discourse of the client and the server.

Q17. What do you think is the essential purpose of the JDBC ResultSet Interface?

The core purpose of the JDBC ResultSet Interface is the representation of a row in a table. Apart from that, it can also be used to alter the cursor pointer and churn info from the database.


Q18. Does java support global variable?
- No, java does not support global variable because of the following reasons:

  • Globally accessible : Global variables are globally accessible.
  • Referential transparency : Global variable breaks the referential transparency and also a global variable generate problem in the namespace.
  • Object oriented : As java is object oriented language so where each variable is declared inside the class. To use this variable, object should be initialized.


Q19. Why bytecode is important to Java?

The compiled Java source code is known as byte code. We need bytecode due to following reasons:

  • Is independent of the input language.
  • Plays an important role in the execution speed of the application.
  • Can run on any platform irrespective of system architecture.
  • Can be used for internet applications where security is important
  • Enable us to load classes which are required for the execution of the application.
  • Allows the web applications to run on various platforms, on various browsers on different infrastructures.


Q20. What is difference between Java and JavaScript?

The difference between java and java scripts are:

  • Java is an Object Oriented Programming Language and capable of running on multiple operating systems with the help of interpreter whereas Java Script is the object oriented scripting language and it is embedded in HTML and runs directly on the browser.
  • JVM is used to executed java program on different program whereas Java Script code is not compiled they are directly run on the browser.
  • Java language is used to develop the software whereas java script is used providing interactivity to the simple HTML pages.


RTU Advanced Java Part - 3

Q21. What is a java object and java application?

Java object is an object that is provided by the execution of an application. When an application is compiled an object of that application is being made. Java application on the other hand is a program that is being written in Java and being read by the Java virtual machine.


Q22. What is the purpose of garbage collection in Java, and when is it used?

The purpose of garbage collection is to identify and discard objects that are no longer needed by a program so that their resources can be reclaimed and reused. A Java object is subject to garbage collection when it becomes unreachable to the program in which it is used.


Q23. Advantages and disadvantages of Java Sockets.

Advantages of Java Sockets :

  • Sockets are flexible and easy to implemented for general communications.
  • Sockets cause low network traffic unlike HTML forms and CGI scripts that generate and transfer whole web pages for each new request.

Disadvantages of Java Sockets :

  • Socket based communications allows only to send packets of raw data between applications.
  • Both the client-side and server-side have to provide mechanisms to make the data useful in any way.


Q24. Describe synchronization in respect to multithreading.

With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources. Without synchronization, it is possible for one thread to modify a shared variable while another thread is in the process of using or updating same shared variable. This usually leads to significant errors.


Q25. Explain different way of using thread?

The thread could be implemented by using runnable interface or by inheriting from the Thread class. The former is more advantageous, 'cause when you are going for multiple inheritance.the only interface can help.


Q26. What is an immutable class? How to create an immutable class?

  • Immutable class is a class which once created, it’s contents can not be changed.
  • Immutable objects are the objects whose state can not be changed once constructed.
  • Since the state of the immutable objects can not be changed once they are created they are automatically synchronized/thread-safe.
  • Immutable objects are automatically thread-safe since the state of the immutable objects can not be changed once they are created
  • All wrapper classes in java.lang are immutable, i.e. String, Integer, Boolean, Character, Byte, Short, Long, Float, Double, BigDecimal, BigInteger


Q27. What are pass by reference and passby value?

Pass By Reference means the passing the address itself rather than passing the value. Passby Value means passing a copy of the value to be passed.


Q28. What are the difference between ArrayList and vector.

  • ArrayList is not thread-safe whereas Vector is thread-safe.
  • In Vector class each method is surrounded with a synchronized block and thus making Vector class thread-safe.
  • Both the ArrayList and Vector hold onto their contents using an Array.
  • When an element is inserted into an ArrayList or a Vector, the object will need to expand its internal array if it runs out of room.
  • A Vector defaults to doubling the size of its array, while the ArrayList increases its array size by 50 percent.


Q29. What is the difference between a constructor and a method?

A constructor is a member function of a class that is used to create objects of that class. It has the same name as the class itself, has no return type, and is invoked using the new operator. A method is an ordinary member function of a class. It has its own name, a return type (which may be void), and is invoked using the dot operator.


Q30. What is the difference between multitasking and multithreading?

Multitasking includes two ways for representation :

  • Preemptive multitasking: where the system terminates the idle process without asking the user. For example: Unix/Linux, Windows NT
  • Non-preemptive multitasking: where the system ask the process to give the control to other process for execution. For example: Windows 3.1 and Mac OS 9.

Multithreading :

  • Multithreaded programs are the program that extend the functionality of the multitasking by dividing the program in thread and then execute the task as individual threads.
  • Threads run in a different area and each thread utilizes some amount of CPU and memory for execution.


Q31. What is the difference between an Interface and an Abstract class?

An abstract class can have instance methods that implement a default behavior. An Interface can only declare constants and instance methods, but cannot implement default behavior and all methods are implicitly abstract. An interface has all public members and no implementation. An abstract class is a class which may have the usual flavors of class members (private, protected, etc.), but has some abstract methods.


Q32. What is the purpose of garbage collection in Java, and when is it used?

The purpose of garbage collection is to identify and discard objects that are no longer needed by a program so that their resources can be reclaimed and reused. A Java object is subject to garbage collection when it becomes unreachable to the program in which it is used.


Q33. What is an abstract class?

Abstract class must be extended/subclassed (to be useful). It serves as a template. A class that is abstract may not be instantiated (ie, you may not call its constructor), abstract class may contain static data. Any class with an abstract method is automatically abstract itself, and must be declared as such. A class may be declared abstract even if it has no abstract methods. This prevents it from being instantiated.


Q34. What is static in java?

Static means one per class, not one for each object no matter how many instance of a class might exist. This means that you can use them without creating an instance of a class. Static methods are implicitly final, because overriding is done based on the type of the object, and static methods are attached to a class, not an object. A static method in a superclass can be shadowed by another static method in a subclass, as long as the original method was not declared final. However, you can't override a static method with a nonstatic method. In other words, you can't change a static method into an instance method in a subclass.


Q35. What is final?

A final class can't be extended ie., final class may not be subclassed. A final method can't be overridden when its class is inherited. You can't change value of a final variable (is a constant).


Q36. What if the main method is declared as private?

The program compiles properly but at runtime it will give "Main method not public." message.


Q37. What if the static modifier is removed from the signature of the main method?

Program compiles. But at runtime throws an error "NoSuchMethodError".


Q38. What if I write static public void instead of public static void?

Program compiles and runs properly.


Q39. What if I do not provide the String array as the argument to the method?

Program compiles but throws a runtime error "NoSuchMethodError".


Q40. What is the first argument of the String array in main method?

The String array is empty. It does not have any element. This is unlike C/C++ where the first element by default is the program name.


Q41. If I do not provide any arguments on the command line, then the String array of Main method will be empty or null?

It is empty. But not null.


Q42. How can one prove that the array is not null but empty using one line of code?

Print args.length. It will print 0. That means it is empty. But if it would have been null then it would have thrown a NullPointerException on attempting to print args.length.


Q43. Can an application have multiple classes having main method?

Yes it is possible. While starting the application we mention the class name to be run. The JVM will look for the Main method only in the class whose name you have mentioned. Hence there is not conflict amongst the multiple classes having main method.


Q44. Can I have multiple main methods in the same class?

No the program fails to compile. The compiler says that the main method is already defined in the class.


Q45. Do I need to import java.lang package any time? Why ?

No. It is by default loaded internally by the JVM.


Q46. Can I import same package/class twice? Will the JVM load the package twice at runtime?

One can import the same package or same class multiple times. Neither compiler nor JVM complains abt it. And the JVM will internally load the class only once no matter how many times you import the same class.


Q47. What are Checked and UnChecked Exception?

A checked exception is some subclass of Exception (or Exception itself), excluding class RuntimeException and its subclasses. Making an exception checked forces client programmers to deal with the possibility that the exception will be thrown. eg, IOException thrown by java.io.FileInputStream's read() method Unchecked exceptions are RuntimeException and any of its subclasses. Class Error and its subclasses also are unchecked. With an unchecked exception, however, the compiler doesn't force client programmers either to catch the exception or declare it in a throws clause. In fact, client programmers may not even know that the exception could be thrown. eg, StringIndexOutOfBoundsException thrown by String's charAt() methodChecked exceptions must be caught at compile time. Runtime exceptions do not need to be. Errors often cannot be.


Q48. What is Overriding?

When a class defines a method using the same name, return type, and arguments as a method in its superclass, the method in the class overrides the method in the superclass. When the method is invoked for an object of the class, it is the new definition of the method that is called, and not the method definition from superclass. Methods may be overridden to be more public, not more private.


Q49. Are the imports checked for validity at compile time? e.g. will the code containing an import such as java.lang.ABCD compile?

Yes the imports are checked for the semantic validity at compile time. The code containing above line of import will not compile. It will throw an error saying,can not resolve symbol symbol : class ABCD location: package io import java.io.ABCD;


Q50. Does importing a package imports the subpackages as well? e.g. Does importing com.MyTest.* also import com.MyTest.UnitTests.*?

No you will have to import the subpackages explicitly. Importing com.MyTest.* will import classes in the package MyTest only. It will not import any class in any of it's subpackage.


Q51. What is the difference between declaring a variable and defining a variable?

In declaration we just mention the type of the variable and it's name. We do not initialize it. But defining means declaration + initialization.

e.g String s; is just a declaration while String s = new String ("abcd"); Or String s = "abcd"; are both definitions.


Q52. What type of parameter passing does Java support?

In Java the arguments are always passed by value .


Q53. Primitive data types are passed by reference or pass by value?

Primitive data types are passed by value.


Q54. Objects are passed by value or by reference?

Java only supports pass by value. With objects, the object reference itself is passed by value and so both the original reference and parameter copy both refer to the same object .


Q56. What are the different ways to handle exceptions?

There are two ways to handle exceptions, 1. By wrapping the desired code in a try block followed by a catch block to catch the exceptions. and 2. List the desired exceptions in the throws clause of the method and let the caller of the method hadle those exceptions.


Q57. What is the basic difference between the 2 approaches to exception handling.

1> try catch block and 2> specifying the candidate exceptions in the throws clause?


Q58. Is it necessary that each try block must be followed by a catch block?

It is not necessary that each try block must be followed by a catch block. It should be followed by either a catch block OR a finally block. And whatever exceptions are likely to be thrown should be declared in the throws clause of the method.


Q59. If I write return at the end of the try block, will the finally block still execute?

Yes even if you write return as the last statement in the try block and no exception occurs, the finally block will execute. The finally block will execute and then the control return.


Q60. If I write System.exit (0); at the end of the try block, will the finally block still execute?

No in this case the finally block will not execute because when you say System.exit (0); the control immediately goes out of the program, and thus finally never executes.


Q61. How are Observer and Observable used?

Objects that subclass the Observable class maintain a list of observers. When an Observable object is updated it invokes the update() method of each of its observers to notify the observers that it has changed state. The Observer interface is implemented by objects that observe Observable objects.




RTU Software Testing Lab Interview Question and Answer


RTU MAD Lab: Mobile Application Development Lab List

RTU MAD Lab: Mobile Application Development Lab List

RTU MAD Lab: Mobile Application Development Lab is a course offered in the 6th semester of B.Tech (Bachelor of Technology) program at Rajasthan Technical University, Kota, Rajasthan



Here we need to study about What is Android Studio? And about his Virtual Machine & .apk file extension, Android API levels (versions & version names)

Android Java Basics:

We will Study About Basic of Java to getting started with Android development, project folder structure, simple programming, running project, generating build/APK of the app from Android Studio. In RTU MAD Lab there are some basic concept which we have to learn first.

First application:

In order to learn android studio we will learn to create Android Studio Project, Android Virtual Device Creation, Set up debugging environment, Workspace set up for development, How to Launching emulator and debugging on mobile devices instead of virtual mobile device.

Basic UI design:

How mobile interface can be build so we learn Basics about Views, Layouts, Drawable Resources, Input controls, Input Events, Toasts.

More UI Components:

Some other components which we needs to learn to successfully build app are: Layouts - GridView and ListView, Action bar, Adapters, Menus: Option menu, context menu, sub menu, Pickers - Date and Time, Spinners.

Activity and Fragment:

In android studio activity basically used to represents a single screen with a user interface just like window or frame of Java.  Activity, Fragment, Activity Lifecycle and Fragment Lifecycle.


Implicit Intents, Explicit intents, communicating data among Activities.

Navigation Drawer:

How data navigates from one activity to other activity so we use a Panel that displays the app’s main navigation screens on the left edge of the screen


List of Experiments of RTU MAD Lab:


Experiment - 1:

To study Android Studio and Android Studio installation "Create Hello World Application".

File Name: activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:text="Hello World!"
app:layout_constraintTop_toTopOf="parent" />


File Name: MainActivity.java

package com.hemantsingh.helloworld;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

protected void onCreate(Bundle savedInstanceState) {

Experiment - 2

To understand Activity, Create sample application with login module.(Check username and password).


Read Analysis Report about Future Scope in Computer Science and Engineering

Follow Us: FacebookInstagramTwitter