Java Review (Essentials of Java For Hadoop)
Java Review (Essentials of Java For Hadoop)
What is Java ?
Java
- Java is not just a programming language but it is a complete
platform for object oriented programming.
JRE
- Java standard class libraries which provide Application
Programming Interface and JVM together form JRE (Java Runtime
Environment).
JDK
- JDK (Java development kit) provides all the needed support for
software development in Java.
Range
long
64
-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
int
32
2,147,483,648 to 2,147,483,647
Short
16
byte
double
64
4.9e324 to 1.8e+308
float
32
1.4e045 to 3.4e+038
char
16
0 to 65,536
boolean
??
32,768 to 32,767
128 to 127
true/false
Operators
Provide a way to perform different operations on
variables
Categories of Java Operators
Assignment Operators
Arithmetic Operators
Relational Operators
>
<
>=
<=
==
Logical Operators
&&
||
&
Unary Operators
++
--
!=
Relational Operators
Used to compare two values.
Binary operators, and their operands are numeric
expressions.
Relational Operators
>
<
>=
<=
==
!=
Logical Operators
Return a true or false value based on the state of
the variables
There are six logical operators
Logical Operators
Conditional AND
Conditional OR
AND
OR
NOT
Exclusive OR
&&
||
&
Flow of Control
Ifelse
Switch Statement
For Loop
While Loop
Do...While Loop
If else Syntax
if ( <condition> )
{
// Execute these statements if <condition> is TRUE
}
else
{
// Execute these statements if < condition> is FALSE
}
switch Syntax
switch (expression)
{
case cond1:
block_1;
break;
case cond2:
block_2;
break;
...
default:
block_default;
}
For Syntax
for (initialization; condition; increment/decrement)
{
statement 1;
statement 2; . .
}
Sample:
for( int i=0; i<5; i++ )
{
System.out.println(i);
}
While Syntax
while (condition)
{
statement 1;
statement 2; . .
}
Sample:
int i=0;
while (i<5)
{
System.out.println(i);
i++;
int i=0;
while(i < 5){
Statement 1;
Statement 2;
i++;
}
Do While Syntax
do
{
statement 1;
statement 2; . .
} while (condition) ;
Sample:
int i=0;
do
{
System.out.println(i);
i++;
} while (i<5);
int i=0;
do{
Statement 1;
Statement 2;
i++;
} while(i < 5)
Arrays
An array is a list of similar things.
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.
Example of an Array
5
4
3
2
1
array[4]
array[3]
array[2]
array[1]
array[0]
An Example class
package com.edureka.entity ;
// package
//class declaration
//
Methods
A method is a named sequence of code that can be
invoked by other Java code.
A method takes some parameters, performs some
computations and then optionally returns a value (or
object).
Ex:
public float convert_to _Celsius( float temp) {
return(((temp * 9.0f) / 5.0f) + 32.0f );
}
Methods
Methods have five components:
Modifiers
The return type
The method name
The parameter list in parenthesis
The method body, enclosed
between braces
Value to be
returned
Name of the
Method
Any Number of
Parameters
Modifiers
public: any method (in any class) can access the
field.
protected: any method in the same package or any
32
Q& A..?
Thanks..!