SlideShare a Scribd company logo
1 of 35
Java Review
(Essentials of Java for Android)
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.
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.
Memory Management In Java
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.
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
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.
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;
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>
   Assignment Operator                                 =

• Java provides eight Arithmetic operators:
   – for addition, subtraction, multiplication, division, modulo (or
     remainder), increment (or add 1), decrement (or subtract
     1), and negation.
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:
  name = “Fred”;
• A block is a compound statement enclosed in curly brackets:
  {
       name1 = “Fred”; name2 = “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);
}
While – Syntax

while (condition)
{
            statement 1;
            statement 2; . .
 }

Sample:
int i=0;
while (i<5)
{
              System.out.println(i);
              i++;
}
Do While – Syntax

do
{
            statement 1;
            statement 2; . .
} while (condition) ;

Sample:
int i=0;
do
{
             System.out.println(i);
             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


     myArray =   3    6   3   1   6   3   4   1
                 0    1   2   3   4   5   6   7



     myArray has room for 8 elements
      the elements are accessed by their index.
      in Java, array indices starts at 0.
Some more Examples

float[] anArrayOfFloats = new float[5];
Car [] cars = new Car()[3]; // an array of cars capable
                            of storing 3 car objects

Object[] anArrayOfObjects = new Objects[100];
boolean[] answers = { true, false, true, true, false };

How to get the length of an array object ?
cars.length ✔ way
cars.length() ✗ way
Java Methods & Classes
Java OOP


• Create new object type with class keyword.
• A class definition can contain:
  – variables (fields)
  – initialization code
  – methods


                      Java Programming: OOP   29
An Example class
package com.edureka.entity;            // package
public class Car{        //class declaration
  String name;
    String color;
    float weight;
  ...
    public void move(){                // method
         ...
    }
}
Objects

•   Runtime representation of a class.
•   Objects hold state with variables
•   Objects do some work with methods.
•   Can be created during Runtime as follows :
    Car carRef = new Car();
                carRef                New Car()

             Object Reference      Newly created Object
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).
• Methods can be used as part of an expression statement.

  Ex:
   public float convert_to _Celsius( float temp) {
       return(((temp * 9.0f) / 5.0f) + 32.0f );
     }
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          33
•Q& A..?
Thanks..!

More Related Content

What's hot

L2 datatypes and variables
L2 datatypes and variablesL2 datatypes and variables
L2 datatypes and variablesteach4uin
 
01 Java Language And OOP PART I
01 Java Language And OOP PART I01 Java Language And OOP PART I
01 Java Language And OOP PART IHari Christian
 
Preparing Java 7 Certifications
Preparing Java 7 CertificationsPreparing Java 7 Certifications
Preparing Java 7 CertificationsGiacomo Veneri
 
Basic elements of java
Basic elements of java Basic elements of java
Basic elements of java Ahmad Idrees
 
Java basics variables
 Java basics   variables Java basics   variables
Java basics variablesJoeReddieMedia
 
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
 
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
 

What's hot (10)

L2 datatypes and variables
L2 datatypes and variablesL2 datatypes and variables
L2 datatypes and variables
 
Java
Java Java
Java
 
01 Java Language And OOP PART I
01 Java Language And OOP PART I01 Java Language And OOP PART I
01 Java Language And OOP PART I
 
Preparing Java 7 Certifications
Preparing Java 7 CertificationsPreparing Java 7 Certifications
Preparing Java 7 Certifications
 
Basic elements of java
Basic elements of java Basic elements of java
Basic elements of java
 
Java
JavaJava
Java
 
Java basics variables
 Java basics   variables Java basics   variables
Java basics variables
 
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
 
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...
 
Chapter 2 java
Chapter 2 javaChapter 2 java
Chapter 2 java
 

Similar to Java Review Essentials (20)

Java Tutorial
Java Tutorial Java Tutorial
Java Tutorial
 
Programming in java basics
Programming in java  basicsProgramming in java  basics
Programming in java basics
 
Java
JavaJava
Java
 
ppt_on_java.pptx
ppt_on_java.pptxppt_on_java.pptx
ppt_on_java.pptx
 
Java Review
Java ReviewJava Review
Java Review
 
Java
Java Java
Java
 
Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud Foundry
 
ITFT - Java
ITFT - JavaITFT - Java
ITFT - Java
 
Java Tutorial | My Heart
Java Tutorial | My HeartJava Tutorial | My Heart
Java Tutorial | My Heart
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.
 
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
 
Java tutorials
Java tutorialsJava tutorials
Java tutorials
 
Java Script
Java ScriptJava Script
Java Script
 
Java Script
Java ScriptJava Script
Java Script
 
gdscWorkShopJavascriptintroductions.pptx
gdscWorkShopJavascriptintroductions.pptxgdscWorkShopJavascriptintroductions.pptx
gdscWorkShopJavascriptintroductions.pptx
 
Ruby basics
Ruby basicsRuby basics
Ruby basics
 

More from Edureka!

What to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | EdurekaWhat to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | EdurekaEdureka!
 
Top 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | EdurekaTop 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | EdurekaEdureka!
 
Top 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | EdurekaTop 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | EdurekaEdureka!
 
Tableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | EdurekaTableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | EdurekaEdureka!
 
Python Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaPython Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaEdureka!
 
Top 5 PMP Certifications | Edureka
Top 5 PMP Certifications | EdurekaTop 5 PMP Certifications | Edureka
Top 5 PMP Certifications | EdurekaEdureka!
 
Top Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | EdurekaTop Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | EdurekaEdureka!
 
Linux Mint Tutorial | Edureka
Linux Mint Tutorial | EdurekaLinux Mint Tutorial | Edureka
Linux Mint Tutorial | EdurekaEdureka!
 
How to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| EdurekaHow to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| EdurekaEdureka!
 
Importance of Digital Marketing | Edureka
Importance of Digital Marketing | EdurekaImportance of Digital Marketing | Edureka
Importance of Digital Marketing | EdurekaEdureka!
 
RPA in 2020 | Edureka
RPA in 2020 | EdurekaRPA in 2020 | Edureka
RPA in 2020 | EdurekaEdureka!
 
Email Notifications in Jenkins | Edureka
Email Notifications in Jenkins | EdurekaEmail Notifications in Jenkins | Edureka
Email Notifications in Jenkins | EdurekaEdureka!
 
EA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | EdurekaEA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | EdurekaEdureka!
 
Cognitive AI Tutorial | Edureka
Cognitive AI Tutorial | EdurekaCognitive AI Tutorial | Edureka
Cognitive AI Tutorial | EdurekaEdureka!
 
AWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | EdurekaAWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | EdurekaEdureka!
 
Blue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | EdurekaBlue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | EdurekaEdureka!
 
Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka Edureka!
 
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | EdurekaA star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | EdurekaEdureka!
 
Kubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | EdurekaKubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | EdurekaEdureka!
 
Introduction to DevOps | Edureka
Introduction to DevOps | EdurekaIntroduction to DevOps | Edureka
Introduction to DevOps | EdurekaEdureka!
 

More from Edureka! (20)

What to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | EdurekaWhat to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | Edureka
 
Top 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | EdurekaTop 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | Edureka
 
Top 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | EdurekaTop 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | Edureka
 
Tableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | EdurekaTableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | Edureka
 
Python Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaPython Programming Tutorial | Edureka
Python Programming Tutorial | Edureka
 
Top 5 PMP Certifications | Edureka
Top 5 PMP Certifications | EdurekaTop 5 PMP Certifications | Edureka
Top 5 PMP Certifications | Edureka
 
Top Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | EdurekaTop Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | Edureka
 
Linux Mint Tutorial | Edureka
Linux Mint Tutorial | EdurekaLinux Mint Tutorial | Edureka
Linux Mint Tutorial | Edureka
 
How to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| EdurekaHow to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| Edureka
 
Importance of Digital Marketing | Edureka
Importance of Digital Marketing | EdurekaImportance of Digital Marketing | Edureka
Importance of Digital Marketing | Edureka
 
RPA in 2020 | Edureka
RPA in 2020 | EdurekaRPA in 2020 | Edureka
RPA in 2020 | Edureka
 
Email Notifications in Jenkins | Edureka
Email Notifications in Jenkins | EdurekaEmail Notifications in Jenkins | Edureka
Email Notifications in Jenkins | Edureka
 
EA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | EdurekaEA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | Edureka
 
Cognitive AI Tutorial | Edureka
Cognitive AI Tutorial | EdurekaCognitive AI Tutorial | Edureka
Cognitive AI Tutorial | Edureka
 
AWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | EdurekaAWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | Edureka
 
Blue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | EdurekaBlue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | Edureka
 
Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka
 
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | EdurekaA star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
 
Kubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | EdurekaKubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | Edureka
 
Introduction to DevOps | Edureka
Introduction to DevOps | EdurekaIntroduction to DevOps | Edureka
Introduction to DevOps | Edureka
 

Java Review Essentials

  • 1. Java Review (Essentials of Java for Android)
  • 2. 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.
  • 3. Java Virtual Machine (JVM) • Runs the Byte Code. • Makes Java platform independent. • Handles Memory Management.
  • 4. 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.
  • 6. 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.
  • 9. 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
  • 10. 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.
  • 11. 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;
  • 12. Operators • Provide a way to perform different operations on variables • Categories of Java Operators Assignment Operators = Arithmetic Operators - + * / % Relational Operators > < >= <= == != Logical Operators && || & | ^ Unary Operators + - ++ -- !
  • 13. Assignment and Arithmetic Operators • Used to assign a value to a variable • Syntax – <variable> = <expression> Assignment Operator = • Java provides eight Arithmetic operators: – for addition, subtraction, multiplication, division, modulo (or remainder), increment (or add 1), decrement (or subtract 1), and negation.
  • 14. Relational Operators • Used to compare two values. • Binary operators, and their operands are numeric expressions. Relational Operators > < >= <= == !=
  • 15. 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 && || & | ! ^
  • 16. 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.
  • 17. 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.
  • 18. 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
  • 19. Java Basic Constructs • If…else • Switch Statement • For Loop • While Loop • Do...While Loop
  • 20. If else– Syntax if ( <condition> ) { // Execute these statements if <condition> is TRUE } else { // Execute these statements if < condition> is FALSE }
  • 21. switch– Syntax switch (expression) { case cond1: block_1; break; case cond2: block_2; break; ... default: block_default; }
  • 22. For– Syntax for (initialization; condition; increment/decrement) { statement 1; statement 2; . . } Sample: for( int i=0; i<5; i++ ) { System.out.println(i); }
  • 23. While – Syntax while (condition) { statement 1; statement 2; . . } Sample: int i=0; while (i<5) { System.out.println(i); 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. 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.
  • 26. Example of an Array myArray = 3 6 3 1 6 3 4 1 0 1 2 3 4 5 6 7 myArray has room for 8 elements  the elements are accessed by their index.  in Java, array indices starts at 0.
  • 27. Some more Examples float[] anArrayOfFloats = new float[5]; Car [] cars = new Car()[3]; // an array of cars capable of storing 3 car objects Object[] anArrayOfObjects = new Objects[100]; boolean[] answers = { true, false, true, true, false }; How to get the length of an array object ? cars.length ✔ way cars.length() ✗ way
  • 28. Java Methods & Classes
  • 29. Java OOP • Create new object type with class keyword. • A class definition can contain: – variables (fields) – initialization code – methods Java Programming: OOP 29
  • 30. An Example class package com.edureka.entity; // package public class Car{ //class declaration String name; String color; float weight; ... public void move(){ // method ... } }
  • 31. Objects • Runtime representation of a class. • Objects hold state with variables • Objects do some work with methods. • Can be created during Runtime as follows : Car carRef = new Car(); carRef New Car() Object Reference Newly created Object
  • 32. 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). • Methods can be used as part of an expression statement. Ex: public float convert_to _Celsius( float temp) { return(((temp * 9.0f) / 5.0f) + 32.0f ); }
  • 33. 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 33

Editor's Notes

  1. Not just a programming language but a complete platformThe Programming language Java standard class libraries which provide Application Programming Interface and JVM together form JRE (Java Runtime Environment)JDK (Java development kit) provides all the needed support for software development in Java.
  2. Need a diagram to show garbage collection
  3. Java compilers convert your code from human readable Java source files to something called “bytecode” in the Java world. “Bytecode” is interpreted by a JVM, which operates much like a physical CPU might operate on machine code, to actually execute the compiled code. Performance - Java performance in generally second only to C/C++ in common language performance comparisons. In the Java programming language and environment, a just-in-time (JIT) compiler is a program that turns Java bytecode (a program that contains instructions that must be interpreted) into instructions that can be sent directly to the processor.The just-in-time compiler comes with the virtual machine and is used optionally. It compiles the bytecode into platform-specific executable code that is immediately executed
  4. Java compilers convert your code from human readable Java source files to something called “bytecode” in the Java world. “Bytecode” is interpreted by a JVM, which operates much like a physical CPU might operate on machine code, to actually execute the compiled code. Performance - Java performance in generally second only to C/C++ in common language performance comparisons. In the Java programming language and environment, a just-in-time (JIT) compiler is a program that turns Java bytecode (a program that contains instructions that must be interpreted) into instructions that can be sent directly to the processor.The just-in-time compiler comes with the virtual machine and is used optionally. It compiles the bytecode into platform-specific executable code that is immediately executed
  5. Adv. Question : What is the range of primitive data types ?Initalization:If no value is assigned prior to use, then the compiler will give an errorJava sets primitive variables to zero or false in the case of a boolean variableAll object references are initially set to null
  6. Java provides six relational operators:greater than (&gt;), less than (&lt;), greater than or equal (&gt;=), less than or equal (&lt;=), equal (==), and not equal (!=).
  7. Is it really needed to define all the types of operators.It will be better to show their differences through a program.
  8. DemoBroke into multiple sentences
  9. DemoReformatted and used clip art for right and wrong
  10. Demo
  11. Public/PrivateMethods/data may be declared public or private meaning they may or may not be accessed by code in other classes …Good practice:keep data privatekeep most methods privatewell-defined interface between classes - helps to eliminate errors