300+ [LATEST] Java Hadoop Developer Interview Questions and Answers

Q1. What Are The Different Ways Of Creating A String Object In Java?

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

Q2. Where Should The Package Statement Appear Within A Java Source Code File?

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

Q3. As We Know That Abstract Class In Java Cannot Be Instantiated, How Will You Use The Non-static Methods Of An Abstract Class?

By extending the abstract class it is possible to use the non-static methods.

Q4. Can You Name Any Final Classes Defined In The Java Api?

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

Q5. Differentiate Between Throw And Throws In Exception Handling.

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.

Q6. What Is The Difference Between A Class Variable And An Instance Variable In Java?

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.

Q7. Where Can A Protected Method Be Accessed?

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.

Q8. Write A Java Line Of Code To Declare A Class As Protected?

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

Q9. Is It Necessary To Declare A Main () Method Inside All Java Classes?

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

Q10. What Is The Advantage Of Using A String Literal In Java?

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.

Q11. How Will You Achieve Multi-threading In Java?

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.

Q12. I Have 10 .java Files In A Folder. What Is The Process To Compile All The Files Using A Single Command Line Execution Instead Of Compiling Each .java File Separately?

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

Q13. Can You Explain The Difference Between Path And Classpath?

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.

Q14. Can You Use An Anonymous Class To Implement An Interface And Extend Another Class?

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.

Q15. How Can You Create A Deep Copy Of The Complete Java Object Along With Its State?

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.

Q16. How Will You Implement Multiple Inheritance In Java?

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

Q17. What Happens If You Do Not Provide Any Package Declaration In Your Java Programming Code?

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

Q18. Filenotfoundexception Is Inherited From The Base Class Ioexception. When Trying To Catch Blocks For These Exceptions, Is It Necessary To Follow A Particular Order For The Catch Block Statements?

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.

Q19. Explain About Garbage Collection In Java?

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.

Q20. Which Collection Interface In Java Is Used To Maintain Unique Elements?

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.

Q21. What Platform And Version Of Java Is Required To Work With Apache Hadoop?

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.

Q22. How Many Objects Will Be Created On Executing The Following Code For Creation Of A String Using The String Literal?

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.

Q23. I Want To Place The Compiled Java Class Files In A Directory Named Desire. How Will You Do That?

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

Q24. How Do You Achieve Abstraction In 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.

Q25. What Is The Difference Between An Abstract Class And Interface?

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.

Q26. What Is Synchronization In Java?

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.

Q27. In A Java Program, We Usually Follow The Main Method Declaration As Public Static Void Main (). What Will Happen If I Alter The Order Of Public And Static Declaration For The Main () Method In A Java

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 ().

Q28. Is Java The Only Language For Hadoop Jobs To Be Written?

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.

Q29. What Will Be The Initial Value Of An Object Reference That Is Declared As An Instance Variables?

All object reference variables in Java are assigned a NULL value.

Q30. Under What Circumstances Is The Finally Block Not Executed?

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

Q31. Is There Any Root Class For All Classes Declared In A Java Program?

“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.

Q32. How Will You Create The Object Of An Abstract Class?

Objects cannot be created for an abstract class.

Q33. Write An Indefinite Loop In Java?

for (;;) { }

Or

while (true)

{ }

Q34. Can You Define A Class Inside An Interface?

Yes but by default the class is static.

Q35. What Are The Access Specifiers Available In Java?

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.

Q36. What Do You Understand By Trient Variables In Java?

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.

Q37. Can You Declare Multiple Classes In Your Java Source Code File?

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

Q38. Differentiate Between A Process And A Thread?

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.

Q39. We Know That The Garbage Collector In Java Cle Up Memory But Still It Does Not Guarantee That Program Will Run Out Of Memory. Can You Explain The Reason For This?

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.

Q40. Which Is The Only Variable That Needs To Be Set In The Conf/hadoop-env.sh File For Hadoop Mapreduce To Work?

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

Q41. What Is The Base Class For Exception And Error In Java?

Throwable

Q42. Is It Mandatory To Have A Catch Block After Every Try Block In The Program Code?

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.

Q43. What Is The Difference Between Method Overloading And Overriding In Java?

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.

Q44. What Is The Return Type Of Main () Method In Java?

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

Q45. What Is The Fundamental Difference Between Shallow Copy And Deep Copy In Java?

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.

Q46. How Will You Declare A Pointer In Java?

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

Q47. What Do You Understand By Mutable And Immutable Objects?

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.

Q48. How Will You Find If Two Strings Are Same Or Not?

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.

Q49. What Is The Basic Difference Between A Queue And A Stack Data Structure?

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