Basic Java Concepts for Hadoop

  • Basic Java Concepts for Hadoop

Hadoop is open source framework and Hadoop programming are written in Java so Java is important to learn Hadoop.Below Java topics are mostly used for Hadoop Programming.

  • Arrays
  • Objects and Classes
  • Control Flow Statements
  • Inheritance
  • Exception Handling
  • Serialization

Recommended Reading – Top Reasons to Switch your Career from Java to Hadoop

Arrays:


The array is a collection of a set of elements and we can store fixed set of elements in the array. The array is an index based and the first element of the array stored in 0 indexes.

Syntax:

dataType[] arrayRefVar = new dataType[arraySize];

Types of Array:


  • Single dimensional array
  • Multidimensional array

Single Dimensional Array:


Many numbers of items grouped into one variable name that is called single dimensional array.

Syntax:

arrayRefVar=new datatype[size];

Multi-Dimensional Array:


In Multidimensional array data are stored in row and column bases index.

Syntax:

dataType arrayRefVar[][];

Objects and Classes:


Objects have states and behaviors of entity and it is an instance of Class

Syntax:

Classname objectname=new classname();

Class:


The class is a group of objects and it includes fields and methods.The class is Specified by “Class” Keyword.The class contains three types of variable.That variable is

  • Local variable
  • Global Variable
  • Instance Variable

Control Flow Statements:


Control statements are controls the order of execution in Java program.

Main Categories of Contol Flow Statements:


  • Selection statements: if, if-else and switch
  • Loop statements: while, do-while and for

Selection Statements:


If:


It executes a block of code if specified conditions are true.If the condition is false it skipped the execution of the block.

Syntax:

if(Condition)
{
a block of code
}

If-else:


if are executes a block of code if specified conditions are true.If the condition is false else block statements are executed.

Syntax:

if(condition)

{

a block of code

}

else

{

a block of code

}

Switch Statement:


It executes one statement from multiple conditions.switch statement execution is based on user input.User input is not matched in switch condition the default block of code is executed.

Syntax:

Switch()

{

case 1:

{block of code}

case 2:

{block of code}

default:

}

Loop statements:


While:


While loop is used to executes one condition at several times and number of iterations are not fixed in this loop

Syntax:

while(condition)

{

a block of code

}

do-While:


While loop is used to executes one condition at several times and a number of iterations are not fixed in this loop but this loop executes at least one time.

Syntax:

do{

a block of code

}while(condition);

For Loop:


While loop are used to executes one condition at several times and number of iterations are fixed in this loop

Syntax:

for(initialization;condition;increment/decrement)

Inheritance:


Inheritance means derived one class from another class that derived class is base class.Base class automatically takes all values from that superclass.Superclass has many subclasses but subclasses have one Super Class.

Extends” keyword is used to mention the inheritance in Java program.

Syntax:

class Subclass-name extends Superclass-name

{

Block of code

}

Exception Handling:


Exception handling is a powerful mechanism in Java is mainly used to handle runtime error in java program.

Serialization: 


Serialization used to convert an object into a sequence of bytes and through into streams.Deserialization means convert stream object into normal java object.