SlideShare a Scribd company logo
1 of 34
Download to read 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..!

More Related Content

What's hot

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
 

What's hot (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
 

Similar to 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
 

Recently uploaded

"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
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
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
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
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 

Recently uploaded (20)

"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
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!
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
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
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 

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