java class 1

29
Java Review

Upload: edureka

Post on 20-Nov-2014

981 views

Category:

Technology


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Java class 1

Java Review

Page 2: Java class 1

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.

Page 3: Java class 1

Java Virtual Machine (JVM)

• Runs the Byte Code.• Makes Java platform independent.• Handles Memory Management.

Page 4: Java class 1

Byte Code

• Java bytecode is the form of instructions that the Java Virtual Machine executes

• A Java programmer does not need to be aware of or understand Java bytecode at all.

• The model of computation of Java bytecode is that of a stack oriented programming language.

Page 5: Java class 1

Garbage Collection

• The programmer is not responsible for memory management in Java.

• The memory area in JVM where objects are created is called Heap.

• The memory is freed during runtime by a special thread called Garbage Collector.

• The GC looks for objects which are no longer needed by the program and destroys them.

Page 6: Java class 1

Garbage Collection

Page 7: Java class 1

Garbage Collection

Page 8: Java class 1

Garbage Collection

Page 9: Java class 1

Garbage Collection

Page 10: Java class 1

How Java works ?

• Java compilers convert your code from human readable to something called “bytecode” in the Java world.

• “Bytecode” is interpreted by a JVM, which operates much like a physical CPU to actually execute the compiled code.

• Just-in-time (JIT) compiler is a program that turns Java bytecode into instructions that can be sent directly to the processor.

Page 11: Java class 1

How Java works ?

Page 12: Java class 1

Basic Java Syntax

Page 13: Java class 1

Data Types in Java• Data types define the nature of a value• We need different data-types to handle real-world information

Name Size (in bits) 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,647Short 16 –32,768 to 32,767byte 8 –128 to 127

double 644.9e–324 to 1.8e+308

float 32 1.4e–045 to 3.4e+038char 16 0 to 65,536

boolean ??true/false

Page 14: Java class 1

Primitive Types and Variables

• boolean, char, byte, short, int, long, float, double etc.• These basic (or primitive) types are the only types that are

not objects (due to performance issues).• This means that you don’t use the new operator to create

a primitive variable.

Page 15: Java class 1

Naming Convention of Variables• Can start with a letter, an underscore(_), or a dollar sign ($)• Cannot start with a number.

long _LongNumber = 9999999; String firstName = “John”; float $Val = 2.3f; int i, index = 2; double gamma = 1.2; boolean value2 = false;

Page 16: Java class 1

Statements & Blocks

• A simple statement is a command terminated by a semi-colon:name = “Fred”;

• A block is a compound statement enclosed in curly brackets:{

name1 = “Fred”; name2 = “Bill”;}

• Blocks may contain other blocks.

Page 17: Java class 1

Flow of Control

• Java executes one statement after the other in the order they are written.

• Many Java statements are flow control statements:Alternation:

if, if else, switch

Page 18: Java class 1

Java Basic Constructs

• If • If…else• Nested If…else• Switch Statement

Page 19: Java class 1

If else– Syntax

if ( <condition> ) {

// Execute these statements if <condition> is TRUE }

Page 20: Java class 1

If else– Syntax

if ( <condition> ) {

// Execute these statements if <condition> is TRUE } else {

// Execute these statements if < condition> is FALSE }

Page 21: Java class 1

If else– Syntax

if ( <condition1> ) {

// Execute these statements if <condition1> is TRUE } else if ( <condition2> ) {

// Execute these statements if <condition2> is TRUE } else {

// if both <condition1> and <condition2> is FALSE }

Page 22: Java class 1

switch– Syntax

switch (expression) { case cond1:

block_1;break;

case cond2: block_2;break;

...default:

block_default;}

Page 23: Java class 1

Operators• Provide a way to perform different operations on

variables

• Categories of Java OperatorsAssignment Operators =

Arithmetic Operators - + * / %

Relational Operators > < >= <= == !=

Logical Operators && || & | ^

Unary Operators + - ++ -- !

Page 24: Java class 1

Assignment and Arithmetic Operators• Used to assign a value to a variable• Syntax

– <variable> = <expression>

• Java provides eight Arithmetic operators:– for addition, subtraction, multiplication, division, modulo (or

remainder), increment (or add 1), decrement (or subtract 1), and negation.

Assignment Operator =

Page 25: Java class 1

Relational Operators

• Used to compare two values.• Binary operators, and their operands are numeric

expressions.Relational Operators > < >= <= == !=

Page 26: Java class 1

Logical Operators

• Return a true or false value based on the state of the variables

• There are six logical operators Conditional AND Conditional OR AND OR NOT Exclusive OR

Logical Operators && || & | ! ^

Page 27: Java class 1

Static versus Non-static Variables

• Static variables are shared across all the objects of a class– There is only one copy

• Non-Static variables are not shared– There is a separate copy for each individual live object.

• Static variables cannot be declared within a method.

Page 28: Java class 1

•Q& A..?

Page 29: Java class 1

Thanks..!