Java essentials for hadoop
-
Upload
easylearning -
Category
Education
-
view
147 -
download
1
description
Transcript of Java essentials for hadoop
![Page 1: Java essentials for hadoop](https://reader034.fdocuments.in/reader034/viewer/2022050816/54c461514a7959d10d8b4653/html5/thumbnails/1.jpg)
Java Essentials for Hadoop
![Page 2: Java essentials for hadoop](https://reader034.fdocuments.in/reader034/viewer/2022050816/54c461514a7959d10d8b4653/html5/thumbnails/2.jpg)
Agenda
What is Java ?Features of JavaHow Java WorksJava Data TypesJava OperatorsStatements & Blocks in JavaJava Class Java Basic ConstructsCreating an ObjectArrays
![Page 3: Java essentials for hadoop](https://reader034.fdocuments.in/reader034/viewer/2022050816/54c461514a7959d10d8b4653/html5/thumbnails/3.jpg)
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.
![Page 4: Java essentials for hadoop](https://reader034.fdocuments.in/reader034/viewer/2022050816/54c461514a7959d10d8b4653/html5/thumbnails/4.jpg)
Features of Java
Simple
Object Oriented
Multithreaded
Distributed
Platform Independent
Secure
Robust
![Page 5: Java essentials for hadoop](https://reader034.fdocuments.in/reader034/viewer/2022050816/54c461514a7959d10d8b4653/html5/thumbnails/5.jpg)
What is JDK and JRE ?
JDK
+
Development tools
Compiler Debugger
JRE
JVMUtility
Classes
![Page 6: Java essentials for hadoop](https://reader034.fdocuments.in/reader034/viewer/2022050816/54c461514a7959d10d8b4653/html5/thumbnails/6.jpg)
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
![Page 7: Java essentials for hadoop](https://reader034.fdocuments.in/reader034/viewer/2022050816/54c461514a7959d10d8b4653/html5/thumbnails/7.jpg)
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
![Page 8: Java essentials for hadoop](https://reader034.fdocuments.in/reader034/viewer/2022050816/54c461514a7959d10d8b4653/html5/thumbnails/8.jpg)
Operators
Provide a way to perform different operations on variables.
Operator Type operators
Assignment =
Arithmetic + , - , * , /
Relational < , > , <= , >= , == , !=
Logical && , || , !
Bitwise &, |, ^, >>, <<
Unary ++ , --, +, -, !
![Page 9: Java essentials for hadoop](https://reader034.fdocuments.in/reader034/viewer/2022050816/54c461514a7959d10d8b4653/html5/thumbnails/9.jpg)
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
![Page 10: Java essentials for hadoop](https://reader034.fdocuments.in/reader034/viewer/2022050816/54c461514a7959d10d8b4653/html5/thumbnails/10.jpg)
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
![Page 11: Java essentials for hadoop](https://reader034.fdocuments.in/reader034/viewer/2022050816/54c461514a7959d10d8b4653/html5/thumbnails/11.jpg)
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}
![Page 12: Java essentials for hadoop](https://reader034.fdocuments.in/reader034/viewer/2022050816/54c461514a7959d10d8b4653/html5/thumbnails/12.jpg)
Method
Public static void myFunction(arg1, arg2, arg3){
}
Modifier
Java keyword
return type
function name
Any number of arguments
//Body of the method
![Page 13: Java essentials for hadoop](https://reader034.fdocuments.in/reader034/viewer/2022050816/54c461514a7959d10d8b4653/html5/thumbnails/13.jpg)
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
![Page 14: Java essentials for hadoop](https://reader034.fdocuments.in/reader034/viewer/2022050816/54c461514a7959d10d8b4653/html5/thumbnails/14.jpg)
Java Basic Constructs
If…else case
Switch Case
Loops in Java – for loop, while loop, do while loop
![Page 15: Java essentials for hadoop](https://reader034.fdocuments.in/reader034/viewer/2022050816/54c461514a7959d10d8b4653/html5/thumbnails/15.jpg)
If Else - Syntax
If (condition){
Statements }
else{
Statements}
Statementstrue
false
condition
![Page 16: Java essentials for hadoop](https://reader034.fdocuments.in/reader034/viewer/2022050816/54c461514a7959d10d8b4653/html5/thumbnails/16.jpg)
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
![Page 17: Java essentials for hadoop](https://reader034.fdocuments.in/reader034/viewer/2022050816/54c461514a7959d10d8b4653/html5/thumbnails/17.jpg)
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
![Page 18: Java essentials for hadoop](https://reader034.fdocuments.in/reader034/viewer/2022050816/54c461514a7959d10d8b4653/html5/thumbnails/18.jpg)
While Loop - Syntax
while (<condition>) {
statement1;…
}
Initialization
Inside the for looptrue
false
Increment/decrement
End of for loop
condition
![Page 19: Java essentials for hadoop](https://reader034.fdocuments.in/reader034/viewer/2022050816/54c461514a7959d10d8b4653/html5/thumbnails/19.jpg)
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
![Page 20: Java essentials for hadoop](https://reader034.fdocuments.in/reader034/viewer/2022050816/54c461514a7959d10d8b4653/html5/thumbnails/20.jpg)
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
![Page 21: Java essentials for hadoop](https://reader034.fdocuments.in/reader034/viewer/2022050816/54c461514a7959d10d8b4653/html5/thumbnails/21.jpg)
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
![Page 22: Java essentials for hadoop](https://reader034.fdocuments.in/reader034/viewer/2022050816/54c461514a7959d10d8b4653/html5/thumbnails/22.jpg)