RMI Java Interview Questions – Set 01

Why Software Developers Choose Java

Java has been tested, refined, extended, and proven by a dedicated community. And numbering more than 6.5 million developers, it’s the largest and most active on the planet. With its versatility, efficiency, and portability, Java has become invaluable to developers by enabling them to:

  • Write software on one platform and run it on virtually any other platform
  • Create programs to run within a Web browser and Web services
  • Develop server-side applications for online forums, stores, polls, HTML forms processing, and more
  • Combine applications or services using the Java language to create highly customized applications or services
  • Write powerful and efficient applications for mobile phones, remote processors, low-cost consumer products, and practically any other device with a digital heartbeat

What is stub?

Stubs are classes that provide replacement implementations for the actual classes client side component to send request to the server in RMI.

What is RMI and how it is useful?

Remote method invocation is called RMI.

One can work with remote object using RMI.

It gives a impression that you are working with a object that resides within your own JVM though it is somewhere.

The protocol used by RMI is RMI-IIOP

Define a Collection API.

The set of classes and interfaces supporting the operation on collections of objects is the Collection API.

Than the vectors, arrays, and hashtables if effectively replaces,these classes and interfaces are more flexible, more powerful, and more regular

class examples: HashSet, TreeMap, ArrayList, LinkedList,HashMap and TreeMap.

interface examples: Set,List ,Collection and Map.

How many forms of Polymorphism are there?

polymorphism exists in three different forms in Java:

  • Method overloading
  • Method overriding through inheritance
  • Method overriding through the Java interface

Define the wrapper classes in Java and name a few.

Wrapper class is wraps around the primitive data type. List of the primitive types and the corresponding wrapper classes:

Primitive Wrapper

boolean java.lang.Boolean

byte java.lang.Byte

char java.lang.Character

double java.lang.Double

float java.lang.Float

int java.lang.Integer

long java.lang.Long

short java.lang.Short

void java.lang.Void

Differentiate between JDK ,JRE & JVM

JDK stands for Java Development Kit. It is the most widely used Java Software Development Kit.

JRE stands for Java Runtime Environment. It is an implementation of the Java Virtual Machine which executes Java programs

JVM stands for Java Virtual Machine. It is an interpreter.

What is RMI architecture

RMI architecture consists of four layers and each layer performs specific functions: a) Application layer – contains the actual object definition. b) Proxy layer – consists of stub and skeleton. c) Remote Reference layer – gets the stream of bytes from the transport layer and sends it to the proxy layer.

Transportation layer – responsible for handlng the actual machine-to-machine communication.

Is it possible to communicate from an applet to servlet and how many ways and how

Yes, there are three ways to communicate from an applet to servlet and they are: a) HTTP Communication(Text-based and object-based) b) Socket Communication c) RMI Communication

what is UnicastRemoteObject

All remote objects must extend UnicastRemoteObject, which provides functionality that is needed to make objects available from remote machines.

Explain the methods, rebind() and lookup() in Naming class?-

rebind() of the Naming class(found in java. rmi) is used to update the RMI registry on the server machine. Naming. rebind(”AddSever”, AddServerImpl); lookup() of the Naming class accepts one argument, the rmi URL and returns a reference to an object of type AddServerImpl.

What is Marker interface? How is it used in Java?

The marker interface is a design pattern, used with languages that provide run-time type information about objects. It provides a way to associate metadata with a class where the language does not have explicit support for such metadata. To use this pattern, a class implements a marker interface, and code that interact with instances of that class test for the existence of the interface. Whereas a typical interface specifies methods that an implementing class must support, a marker interface does not do so. The mere presence of such an interface indicates specific behavior on the part of the implementing class. There can be some hybrid interfaces, which both act as markers and specify required methods, are possible but may prove confusing if improperly used. Java utilizes this pattern very well and the example interfaces are:

  • io.Serializable – Serializability of a class is enabled by the class implementing the java.io.Serializable interface. The Java Classes that do not implement Serializable interface will not be able to serialize or deserializ their state. All subtypes of a serializable class are themselves serializable. The serialization interface has no methods or fields and serves only to identify the semantics of being serializable.
  • rmi.Remote – The Remote interface serves to identify interfaces whose methods may be invoked from a non-local virtual machine. Any object that is a remote object must directly or indirectly implement this interface. Only those methods specified in a “remote interface”, an interface that extends java.rmi.Remote are available remotely.
  • lang.Cloneable – A class implements the Cloneable interface to indicate to the Object.clone() method that it is legal for that method to make a field-for-field copy of instances of that class. Invoking Object’s clone method on an instance that does not implement the Cloneable interface results in the exception CloneNotSupportedException being thrown.
  • servlet.SingleThreadModel – Ensures that servlets handle only one request at a time. This interface has no methods.
  • util.EvenListener – A tagging interface that all event listener interfaces must extend.
  • The “instanceof” keyword in java can be used to test if an object is of a specified type. So this keyword in combination with Marker interface can be used to take different actions based on type of interface an object implements.

What is RMI and steps involved in developing an RMI object

Remote Method Invocation (RMI) allows java object that executes on one machine and to invoke the method of a Java object to execute on another machine. The steps involved in developing an RMI object are: a) Define the interfaces b) Implementing these interfaces c) Compile the interfaces and their implementations with the java compiler d) Compile the server implementation with RMI compiler e) Run the RMI registry f) Run the application

What information is needed to create a TCP Socket

The Local Systems IP Address and Port Number. And the Remote System’s IPAddress and Port Number.