SlideShare uma empresa Scribd logo
1 de 34
Baixar para ler offline
Java Review
(Essentials of Java for Hadoop)
Have You Joined Our
LinkedIn Group?
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.
Java Virtual Machine (JVM)
• Runs the Byte Code.
• Makes Java platform independent.
• Handles Memory Management.
How Java works ?
• Java compilers convert your code from human readable to
so ethi g alled bytecode i the Ja a orld.
• Bytecode is i terpreted y 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.
How Java works ?
Basic Java Syntax
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,647
Short 16 –32,768 to 32,767
byte 8 –128 to 127
double 64 4.9e–324 to 1.8e+308
float 32 1.4e–045 to 3.4e+038
char 16 0 to 65,536
boolean ??
true/false
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 = Joh ;
 float $Val = 2.3f;
 int i, index = 2;
 double gamma = 1.2;
 boolean value2 = 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 + - ++ -- !
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 =
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
Conditional AND Conditional OR AND OR NOT Exclusive OR
Logical Operators && || & | ! ^
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.
Statements & Blocks
• A simple statement is a command terminated by a semi-colon:
a e = Fred ;
• A block is a compound statement enclosed in curly brackets:
{
a e = Fred ; a e = Bill ;
}
• Blocks may contain other blocks.
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
Looping:
for, while, do while
Java Basic Constructs
• If…else
• 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);
}
For loop - Working
For(int i=0; i<5; i++){
Statement 1;
Statement 2;
}
While – Syntax
while (condition)
{
statement 1;
statement 2; . .
}
Sample:
int i=0;
while (i<5)
{
System.out.println(i);
i++;
}
While Loop - Working
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);
Do While Loop - Working
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
int array [] = new int[5];
for(int i=0; i<5 ; i++)
{
array[i] = i+1;
}
1
2
3
4
5
array[0]
array[1]
array[2]
array[3]
array[4]
Java Methods & Classes
An Example class
package com.edureka.entity; // package
public class Car{ //class declaration
String name;
String color;
float weight;
...
public void move(){ //
method
...
}
}
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 );
}
return_type method_name (arg1, arg2, arg3)
{
____
____
}
Methods
Methods have five components:
• Modifiers
• The return type
• The method name
• The parameter list in parenthesis
• The method body, enclosed
between braces
Body of the
Method
Any Number of
Parameters
Name of the
MethodValue to be
returned
Modifiers
• public: any method (in any class) can access the
field.
• protected: any method in the same package or any
derived class can access the field.
• private: only methods within the class can access the
field.
• default is that only methods in the same package
can access the field.
Java Programming: OOP 32
•Q& A..?
Thanks..!

Mais conteúdo relacionado

Mais procurados

Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2Sagar Verma
 
Unit 2 Part 1 Constructors.pdf
Unit 2 Part 1 Constructors.pdfUnit 2 Part 1 Constructors.pdf
Unit 2 Part 1 Constructors.pdfArpana Awasthi
 
SQL Interview Questions For Experienced
SQL Interview Questions For ExperiencedSQL Interview Questions For Experienced
SQL Interview Questions For Experiencedzynofustechnology
 
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...Sagar Verma
 
Preparing Java 7 Certifications
Preparing Java 7 CertificationsPreparing Java 7 Certifications
Preparing Java 7 CertificationsGiacomo Veneri
 
Introduction to Scala JS
Introduction to Scala JSIntroduction to Scala JS
Introduction to Scala JSKnoldus Inc.
 
Java 101 Intro to Java Programming - Exercises
Java 101   Intro to Java Programming - ExercisesJava 101   Intro to Java Programming - Exercises
Java 101 Intro to Java Programming - Exercisesagorolabs
 
Java 101 Intro to Java Programming
Java 101 Intro to Java ProgrammingJava 101 Intro to Java Programming
Java 101 Intro to Java Programmingagorolabs
 
Java 102 intro to object-oriented programming in java
Java 102   intro to object-oriented programming in javaJava 102   intro to object-oriented programming in java
Java 102 intro to object-oriented programming in javaagorolabs
 
Introduction To Vavr: A Functional Java Library
Introduction To Vavr: A Functional Java LibraryIntroduction To Vavr: A Functional Java Library
Introduction To Vavr: A Functional Java LibraryKnoldus Inc.
 
Java Interview Questions For Freshers
Java Interview Questions For FreshersJava Interview Questions For Freshers
Java Interview Questions For Fresherszynofustechnology
 
Static keyword ppt
Static keyword pptStatic keyword ppt
Static keyword pptVinod Kumar
 
Java 101 intro to programming with java
Java 101  intro to programming with javaJava 101  intro to programming with java
Java 101 intro to programming with javaHawkman Academy
 

Mais procurados (17)

Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2
 
Unit 2 Part 1 Constructors.pdf
Unit 2 Part 1 Constructors.pdfUnit 2 Part 1 Constructors.pdf
Unit 2 Part 1 Constructors.pdf
 
SQL Interview Questions For Experienced
SQL Interview Questions For ExperiencedSQL Interview Questions For Experienced
SQL Interview Questions For Experienced
 
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
 
Preparing Java 7 Certifications
Preparing Java 7 CertificationsPreparing Java 7 Certifications
Preparing Java 7 Certifications
 
Scala-Ls1
Scala-Ls1Scala-Ls1
Scala-Ls1
 
Introduction to Scala JS
Introduction to Scala JSIntroduction to Scala JS
Introduction to Scala JS
 
Java 101 Intro to Java Programming - Exercises
Java 101   Intro to Java Programming - ExercisesJava 101   Intro to Java Programming - Exercises
Java 101 Intro to Java Programming - Exercises
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Java notes(OOP) jkuat IT esection
Java notes(OOP) jkuat IT esectionJava notes(OOP) jkuat IT esection
Java notes(OOP) jkuat IT esection
 
Java 101 Intro to Java Programming
Java 101 Intro to Java ProgrammingJava 101 Intro to Java Programming
Java 101 Intro to Java Programming
 
Java 102 intro to object-oriented programming in java
Java 102   intro to object-oriented programming in javaJava 102   intro to object-oriented programming in java
Java 102 intro to object-oriented programming in java
 
Introduction To Vavr: A Functional Java Library
Introduction To Vavr: A Functional Java LibraryIntroduction To Vavr: A Functional Java Library
Introduction To Vavr: A Functional Java Library
 
Java Interview Questions For Freshers
Java Interview Questions For FreshersJava Interview Questions For Freshers
Java Interview Questions For Freshers
 
Chapter 2 java
Chapter 2 javaChapter 2 java
Chapter 2 java
 
Static keyword ppt
Static keyword pptStatic keyword ppt
Static keyword ppt
 
Java 101 intro to programming with java
Java 101  intro to programming with javaJava 101  intro to programming with java
Java 101 intro to programming with java
 

Semelhante a Java Review

Semelhante a Java Review (20)

Programming in java basics
Programming in java  basicsProgramming in java  basics
Programming in java basics
 
Java 101
Java 101Java 101
Java 101
 
Java tutorials
Java tutorialsJava tutorials
Java tutorials
 
Learn To Code: Introduction to java
Learn To Code: Introduction to javaLearn To Code: Introduction to java
Learn To Code: Introduction to java
 
Java Tutorial | My Heart
Java Tutorial | My HeartJava Tutorial | My Heart
Java Tutorial | My Heart
 
Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
 
Java tut1
Java tut1Java tut1
Java tut1
 
Java tut1 Coderdojo Cahersiveen
Java tut1 Coderdojo CahersiveenJava tut1 Coderdojo Cahersiveen
Java tut1 Coderdojo Cahersiveen
 
Javatut1
Javatut1 Javatut1
Javatut1
 
Java tut1
Java tut1Java tut1
Java tut1
 
Introduction to java 101
Introduction to java 101Introduction to java 101
Introduction to java 101
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.
 
JAVA in Artificial intelligent
JAVA in Artificial intelligentJAVA in Artificial intelligent
JAVA in Artificial intelligent
 
java in Aartificial intelligent by virat andodariya
java in Aartificial intelligent by virat andodariyajava in Aartificial intelligent by virat andodariya
java in Aartificial intelligent by virat andodariya
 
Fundamentals of java --- version 2
Fundamentals of java --- version 2Fundamentals of java --- version 2
Fundamentals of java --- version 2
 
Core Java introduction | Basics | free course
Core Java introduction | Basics | free course Core Java introduction | Basics | free course
Core Java introduction | Basics | free course
 
Introduction to java (revised)
Introduction to java (revised)Introduction to java (revised)
Introduction to java (revised)
 
Core java
Core javaCore java
Core java
 
Java basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini indiaJava basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini india
 
Java basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini indiaJava basic tutorial by sanjeevini india
Java basic tutorial by sanjeevini india
 

Último

Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 

Último (20)

Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 

Java Review

  • 1. Java Review (Essentials of Java for Hadoop)
  • 2. Have You Joined Our LinkedIn Group?
  • 3. 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.
  • 4. Java Virtual Machine (JVM) • Runs the Byte Code. • Makes Java platform independent. • Handles Memory Management.
  • 5. How Java works ? • Java compilers convert your code from human readable to so ethi g alled bytecode i the Ja a orld. • Bytecode is i terpreted y 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.
  • 8. 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,647 Short 16 –32,768 to 32,767 byte 8 –128 to 127 double 64 4.9e–324 to 1.8e+308 float 32 1.4e–045 to 3.4e+038 char 16 0 to 65,536 boolean ?? true/false
  • 9. 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 = Joh ;  float $Val = 2.3f;  int i, index = 2;  double gamma = 1.2;  boolean value2 = false;
  • 10. Operators • Provide a way to perform different operations on variables • Categories of Java Operators Assignment Operators = Arithmetic Operators - + * / % Relational Operators > < >= <= == != Logical Operators && || & | ^ Unary Operators + - ++ -- !
  • 11. 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 =
  • 12. Relational Operators • Used to compare two values. • Binary operators, and their operands are numeric expressions. Relational Operators > < >= <= == !=
  • 13. 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 && || & | ! ^
  • 14. 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.
  • 15. Statements & Blocks • A simple statement is a command terminated by a semi-colon: a e = Fred ; • A block is a compound statement enclosed in curly brackets: { a e = Fred ; a e = Bill ; } • Blocks may contain other blocks.
  • 16. 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 Looping: for, while, do while
  • 17. Java Basic Constructs • If…else • Switch Statement • For Loop • While Loop • Do...While Loop
  • 18. If else– Syntax if ( <condition> ) { // Execute these statements if <condition> is TRUE } else { // Execute these statements if < condition> is FALSE }
  • 19. switch– Syntax switch (expression) { case cond1: block_1; break; case cond2: block_2; break; ... default: block_default; }
  • 20. For– Syntax for (initialization; condition; increment/decrement) { statement 1; statement 2; . . } Sample: for( int i=0; i<5; i++ ) { System.out.println(i); }
  • 21. For loop - Working For(int i=0; i<5; i++){ Statement 1; Statement 2; }
  • 22. While – Syntax while (condition) { statement 1; statement 2; . . } Sample: int i=0; while (i<5) { System.out.println(i); i++; }
  • 23. While Loop - Working int i=0; while(i < 5){ Statement 1; Statement 2; i++; }
  • 24. Do While – Syntax do { statement 1; statement 2; . . } while (condition) ; Sample: int i=0; do { System.out.println(i); i++; } while (i<5);
  • 25. Do While Loop - Working int i=0; do{ Statement 1; Statement 2; i++; } while(i < 5)
  • 26. 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.
  • 27. Example of an Array int array [] = new int[5]; for(int i=0; i<5 ; i++) { array[i] = i+1; } 1 2 3 4 5 array[0] array[1] array[2] array[3] array[4]
  • 28. Java Methods & Classes
  • 29. An Example class package com.edureka.entity; // package public class Car{ //class declaration String name; String color; float weight; ... public void move(){ // method ... } }
  • 30. 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 ); }
  • 31. return_type method_name (arg1, arg2, arg3) { ____ ____ } Methods Methods have five components: • Modifiers • The return type • The method name • The parameter list in parenthesis • The method body, enclosed between braces Body of the Method Any Number of Parameters Name of the MethodValue to be returned
  • 32. Modifiers • public: any method (in any class) can access the field. • protected: any method in the same package or any derived class can access the field. • private: only methods within the class can access the field. • default is that only methods in the same package can access the field. Java Programming: OOP 32