java essentials for hadoop

22
Java Essentials for Hadoop

Upload: seo-gyansha

Post on 13-Jul-2015

2.008 views

Category:

Education


0 download

TRANSCRIPT

Java Essentials for Hadoop

Agenda

What is Java ?Features of JavaHow Java WorksJava Data TypesJava OperatorsStatements & Blocks in JavaJava Class Java Basic ConstructsCreating an ObjectArrays

What is Java ?

Java is a high level programming language developed by Sun Microsystems and released in November 1995.

Java can be used to create complete applications that may run on a single computer or be distributed among servers and clients in a network.

Java is Object-Oriented and follows the principal of “write once run anywhere” codes.

Features of Java

Simple

Object Oriented

Multithreaded

Distributed

Platform Independent

Secure

Robust

What is JDK and JRE ?

JDK

+

Development tools

Compiler Debugger

JRE

JVMUtility

Classes

How Java Works ?

Source Code

Byte Code

JVM

JIT Compiler

Java Interpreter

Runtime System

Output of the

program

Java Compiler

Hexadecimal format

It is used to speed up the execution

Converts total byte code into machine code

Data Types

Data Type Size Default value

Boolean 1 bit False

char 2 bytes '\u0000'

byte 1 byte 0

short 2 bytes 0

int 4 bytes 0

long 8 bytes 0L

float 4 bytes 0.0f

double 8 bytes 0.0d

String(any object) - null

Primitive Data TypesNon-primitive Data Types

(Reference type)

1. Class Type2. Interface Type3. Array type

Operators

Provide a way to perform different operations on variables.

Operator Type operators

Assignment =

Arithmetic + , - , * , /

Relational < , > , <= , >= , == , !=

Logical && , || , !

Bitwise &, |, ^, >>, <<

Unary ++ , --, +, -, !

Statements & Blocks in JAVA

Statements are always terminated by a semi-colon(;)

A block is a compound statement enclosed in curly

brackets.

Statement forms a complete command to be executed.

class Stat{Boolean flag ; //statement 1Int x = 20 ; //Statement 2..

}

Open braces for a block

End of block, using close braces

A class can be defined as a template/blue print that describes the behaviors and states that object of its type support.

Objects have states and behaviors. Example: Bicycles have state (current gear, current pedal cadence, two wheels, number of gears) and behavior (braking, accelerating, slowing down, changing gears).

An object is an instance of a class.

Java Class

Example of a class

public class hello {public static void main(String[] args)

{int number = 10; //variableSystem.out.println("Hello");System.out.println(number);

}}

class Myclass{

//data members//constructors

// methods or member functions}

Method

Public static void myFunction(arg1, arg2, arg3){

}

Modifier

Java keyword

return type

function name

Any number of arguments

//Body of the method

Public• Can be accessed from anywhere.

Protected

• Can be accessed in the same package or any derived class.

Default

• Can be accessed within the class only. Private

• Can be accessed within the same package.

Modifiers

Java Basic Constructs

If…else case

Switch Case

Loops in Java – for loop, while loop, do while loop

If Else - Syntax

If (condition){

Statements }

else{

Statements}

Statementstrue

false

condition

Switch - Syntax

Switch(x){

Case 1:Statements

Case 2:Statements

default :Statements

}

Case 1

Statements

Statements

Case 2

true

false

true

false

default

End of the switch Statement

For Loop - Syntax

for (initialization; condition; increment/decrement;)

{statement 1;

statement 2; …

}

Initialization

Inside the for looptrue

false

Increment/decrement

End of for loop

condition

While Loop - Syntax

while (<condition>) {

statement1;…

}

Initialization

Inside the for looptrue

false

Increment/decrement

End of for loop

condition

Do While Loop Syntax

do {

statement 1;statement 2;……

} while (<condition>) ;

Initialization

Inside the do while loop

true

false

Increment/decrement

End of for loop

condition

condition

Creation of the Object

Class_name object_name = new class_name();

Name of the class

Creates a reference object

Allocate memory

Constructor of the class

Creates a new object

An array is a list of similar elements. An array has a fixed:

- name- type- length

These must be declared when the array is created. Array size cannot be changed during the execution

of the code.

Arrays