Top 49 Java Hadoop Developer Interview Questions You Must Prepare 24.May.2024

String objects in java can be created either by using the new keyword or by using a string literal.

String Creation using a Literal

String str= “DeZyre”;

String Object Creation using the “new” operator -

String str=new String ("DeZyre"); //creates two objects and one reference variable

The package statement should always be the very first line of a java program code.

Java.lang.math and java.lang.string are some examples of final classes in Java API.

Throw clause is used when a user wants to throw a customized explicit exception. Throw clause is used if there is a need for a specific exception to be thrown to the calling method.

try {

if (age>=100) {throw new AgeBarException (); //This is a customized exception

} else {

....}

}

} catch (AgeBarException ex) {

...code to handle Exception.....

}

Throws Clause lists all the exceptions that piece of code might throw. Throws clause provides a warning to the invoking method that these are the list of exceptions it might throw and all these need to be handled.

  • Throws is used to declare an exception whereas throw clause is used to explicitly throw an exception.
  • throws clause is specified in the method signature whereas throw clause is used within a method.
  • Throws clause is often followed by a class whilst throw clause is often followed by an instance.

Class Variables only have a single copy of the variable and are declared with static modifiers. Every object of the class shares a single copy of the class variable, so if any changes are made to a class variable they will be seen by all the objects of a class. A class variable is allocated memory when the class is loaded first time.

Example of a Class Variable Declaration in Java

Public class Product {

    public static int Barcode;

}

Instance variables belong to an object and are specified without a static modifier. Every object of the class will have its own personal copy of the instance variable unlike class variables where single copy of the variable is shared by different objects of the class.

Example of an Instance Variable Declaration in Java

public class Product {

   public int Barcode;

}

Big Data and Hadoop Certification Training

If you would like more information about Big Data careers, please click the orange "Request Info" button on top of this page.

Any protected method can be accessed by all the classes of the same package and also by the subclass of the class in any other package.

Only methods can be declared as protected in Java and not classes.

It is not necessary to declare a main () method inside all java classes unless the source class is a java application.

Using a string literal to create strings makes java memory more efficient as no new objects are created if they already exist in the string constant pool.

Multithreading in Java can be achieved in two ways :-

  • By defining a new class which implements the runnable interface. An object of that class is then passed to constructor method of Thread.
  • By defining a new class that extends the thread class.

Executing the “javac *.java “command from the directory location will compile all the files present in the folder with .java extension.

These are the operating system environment variables wherein PATH variable defines the system where executable files are present while CLASSPATH is used to specify the location of .class files.

Yes, it is possible for an anonymous class to implement an interface and extend a super class but it cannot be used to do both at the same time in the same declaration.

A deep copy of the entire java object can be created by having the class implement the cloneable interface and make a call to its clone () method.

Java does directly support multiple inheritance unlike C++ but multiple inheritance can be implemented in Java through interfaces.

When no package declaration is specified, java.lang package gets imported by default.

Yes it is important to follow a particular order for the catch block statement for the two exceptions. The subclasses exception i.e. FileNotFoundException has to be caught first.

Java manages memory automatically by removing the unused variable or objects from the memory. This process is referred to as garbage collection. User java programs cannot free the object memory , so the garbage collector (gc) in java free’s the objects or variables that are no longer being used by a program. JVM considers an object or variable as alive as long as it is being referenced by a program. Once it finds that the object cannot be reached by the program code, it is removed and so that the unused memory can be reclaimed.

Map interface in Java maps unique keys to values, given a key and value pair- the value is stored in the Map object which can be retrieved using the key.

The recommended java version to with Apache Hadoop is 1.6 or higher, preferred from Sun. Windows and Linux are the supported operating systems to work with Hadoop but Mac OS is famous for working with hadoop.

String str1=”DeZyre”;

String str2=”DeZyre”;

String str3=”DeZyre”;

Only one object will be created because every time when we create a string literal, the JVM checks for the presence of the string in the string constant pool. Only if the string is not present in the pool then a new string instance will be created, otherwise a reference to the pooled instance is returned.

Use java – d .java. This command will place the compiled class files in a directory known as Java.

Abstraction me revealing only the required implementation details and hiding the internal details. Interfaces and abstract classes in java help achieve abstraction in Java.

Interface is different from an abstract class because interface is just a type that can be satisfied by a class which implements the interface. Interfaces in java help implement multiple inheritance because a class can extend only one other class.

Interface do not have any implementation and just are limited to constants and public methods whereas abstract class in java can have partial implementation along with static methods and protected access blocks. A class can extend only one abstract class but it can implement several interfaces.

The process of monitoring the access to shared resources by multiple threads so that only one thread can access one resource at time is known as synchronization. Synchronization is used to avoid data consistency and corruption problems and also to prevent any kind of thread interference.

Java provides a special keyword known as “synchronized” which can be used either for synchronizing a block of code or for synchronizing a method.

  1. The keyword “synchronized” can be used a part of the method declaration.
  2. Or a block of code can be placed in synchronized keyword using ‘this’ java operator.

Changing the order of the keywords ‘public’ and ‘static’ in the main () method declaration of a Java program does not matter but one must always ensure that the return type of the main () method i.e. void should always appear before main ().

It is not necessary to write Hadoop jobs in Java language, there are many other ways to write hadoop jobs using non-java codes. Hadoop Streaming allows hadoop map and reduce tasks to be written in the form of any executable script.

If the program terminates due to a fatal error or it exits by calling the system.exit () method then finally block is not executed.

“Object” class is the root class of all classes in java. Any class written in a java program extends the object class present in the default java.lang package.

Objects cannot be created for an abstract class.

for (;;) { }

Or

while (true)

{ }

Yes but by default the class is static.

Java has 4 levels of access specifiers:-

  • Private -Variables, methods classes and constructors are visible only to the class.
  • Protected – Variables, methods classes and constructors are visible to the package and also within all the subclasses.
  • Public - Variables, methods classes and constructors are visible anywhere.
  • Default- Visible to the package and there is no specific keyword to specify this access specifier, it is declared by default.

Java has a special keyword known as trient which indicates that a variable should not be serialized when it is stored to streams of bytes. Whenever an object is trferred through a network it should be serialized to convert the object state into serial bytes.

Trient variables are initialized by their default value during de-serialization. For instance, for object trient variable, the value would be NULL.

A single java program can have any number of class declarations but only one class can be declared as Public.

In simple terms, threads are a part of a process i.e. a single process in java can spawn multiple threads.  Threads and processes in Java are independent paths of execution .A process gets its own memory address space whereas a thread shares the heap space belonging to the parent process. Every process in java has a unique process identifier, executable code and memory space whereas a thread has its own stack in Java but makes use of the process memory and shares it with other threads.

Java programs might use up the memory resources at a much faster pace than they are actually garbage collected and also the program might create objects which cannot be garbage collected.

JAVA_HOME is the only variable that needs to be set and should point to the java installation directory.

It is not necessary to have a catch block after every try block in the program code. All exceptions that are likely to be thrown should be mentioned in the throws clause of the method followed by either a catch block or a finally block.

Method overloading happens during compile time within a class whereas Method Overriding happens between two classes that have IS-A i.e. inheritance relationship. For method overriding we require parent and child classes whereas for method overloading a single class is enough.

  • Static binding is used for method overloading as the call to the overloaded method is made during the compile time whereas dynamic binding is used for method overriding as the call to the overridden method is made at run time.
  • Method overloading requires different argument list to the method whereas in method overriding the argument list has to be same.
  • Method overloading gives better performance over method overriding since the binding of the overloaded methods is done at compile time and not run time.

main () method in java does not return anything and hence is always declared as void.

In Shallow copy a new object is created that has the same values like the original object. If any of the fields in the object reference other objects in that case only the memory address is copied.

In deep copy all fields are copied and copies are created for dynamically allocated memory that points to by the fields. In deep copy, an object is copied along with the other objects it refers to.

The default version of the clone () method will create a shallow copy of the object.

Java does not support pointers due to reliability and memory leak issues.

If the value of the object can be changed then it is referred to as a Mutable object. If after the creation of an objects, it value cannot be changed then it is an immutable object. String, Integer, Float in java are examples of immutable object whereas StringBuffer object is an example of mutable object in java.

Two strings in Java can be compared using the equals () method and not ==. Using == to compare strings will compare if the two string variables point to the same instance of a string object and not the actual value of the strings.

Queue follows the first in first out (FIFO) rule whereas stack follows the last in first out rule (LIFO)