SlideShare a Scribd company logo
1 of 34
Jigar Jobanputra
 Object- objects have states and behaviors.
Example:A dog has states-color, name, breed
, as well as behaviors – barking, eating.An
object is an instance of a class.
 Class- A class can be defined as a
template/blue print that describe the
behavior/states that object of its type
support.
 public class dog
{
String breed;
int age;
String color;
void barking(){}
void hungry(){}
void sleeping(){}
}
 Local variable: variables defined inside the methods,
constructor or block are called local variables.The
variable will declared and initialized within the
method and the variable will be destroyed when the
method has completed.
 Instance variable: instance variable are variable within
a class but outside any method.These variables are
instantiated when class is loaded. Instance variable
can be accessed form inside any method, constructor
or blocks at the particular class.
 Class variables: class variables are variables declared
within a class, outside any method, with the static
keyword.
 When discussing about classes one of the most
important sub topic would be constructors.
Every class has a constructor. If we do not
explicitly write a constructor for a class the java
compiler builds a default constructor for that
class.
 Each time a new object is created at least one
constructor will be invoked.The main rule of
constructors is that they should have the same
name as the class. A class can have more than
one constructor.
 public class std
{
public std()
{
}
public std(String name)
{
// the constructor has one parameter, name
}
}
public class std
{
public std(String name)
{
System.out.println(“passed name is” +
name);
}
public static void main(String args[])
{
std s1= new std(“ram”);
}
}
/* First create an object */
Objectreference= new constructor();
/* Now call a variable as follows */
objectreference.variableName;
/* Now you can call a class method as follows */
objectreference.MethodName();
 There can be only one public class per source
file.
 A source file can have multiple non public
classes.
 The public class name should be the name of the
source file as well as which should be appended
by .Java at the end. For example: the class name
is . Public class employee{} then the source file
should be as employee.java
 if the class is defined inside a package, then the
package statement should be the first statement
in source file.
 Java provides a rich set of operators to
manipulate variables.We can divide all the
java operators into the following groups:
 Arithmetic operators
 Relational operators
 Bitwise operators
 Logical operators
 Assignment operators
 Misc operators
 Arithmetic operators are used in
mathematical expressions in the same way
that they are used in algebra.The following
table lists the arithmetic operators:
 Java defines several bitwise operators which can be
applied to the integer types, long , int , short, char and
byte.
 Bitwise operator works on bits and perform bit by bit
operation. Assume if a=60; and b= 13; now in binary
format they will be as follows:
a= 0011 1100
b= 0000 1101
---------------------------
a & b= 0000 1100
a | b = 0011 1101
a ^ b = 0011 0001
~a = 1100 0011
 Conditional operator is also known as the
ternary operator.This operator consist of
three operands and is used to evaluate
boolean expressions.The goal of the operator
is to decide which value should be assigned to
the variable.The operator written as:
 Variable x= (expression)?Value if true: value if
false
 public class test
{
public static void main(String args[])
{
int a,b; a= 10; b= (a==1)?20:30;
System.out.println(“value of b is:” + b);
b=(a==10)?20:30;
System.out.println(“value of b is:”+b);
}
}
 The operator is used only for object reference
variables.The operator checks whether the
object is of a particular type(class type or
interface type). instanceOf operator is written
as:
 (Object reference variable) instanceOf
(class/interface type)
 String name==‘james’;
 boolean result = name instanceOf String;
 //this will return true since name is type of String
 Conditional
 Looping Statement
 If statement
 An if statement consists of a boolean
expression followd by one or more
statements.
If(boolean_expression)
{
//statement will execute if the boolean
expression is true.
}
 If Statement
 If…else Statement
 If…else if…else statement
 Nested if…else statement
 A switch statement allows a variable to be tested for equality
against a list of values. Each value is called a case, and the variable
being switched on is checked for each case:
switch(expression)
{
case value:
break;
case value:
break;
case value:
break;
default:
//optional statements
}
public class test
{
public static void main(String args[])
{
char grade=args[0].charAt(0);
switch(grade)
{
case ’A’ :
System.out.println(“Excellent!”);
break;
case ’B’ :
case ’C’ :
System.out.println(“Well Done”);
break;
case ‘D’:
System.out.println(“you passed”);
break;
case ‘F’:
System.out.println(“Better try again”);
break;
default:
System.out.println(“invalid grade”);
}
System.out.println(“your grade is ” + grade);
}
}
 There may be a situation when we need to
execute a block of code several number of times,
and is often referred to as a loop.
 Java has very flexible three looping mechanisms.
You can use one of the following three loops :
 While loop
 Do…while loop
 For loop
 As of java 5 the enhanced for loop was introduced.
This is mainly used for arrays.
While (boolean_expression)
{
//statement
}
While(x<20)
{
System.out.print(“Value of x:” + x);
x++;
System.out.print(“n”);
}
do
{
//statements
} while(boolean_expression);
do
{
System.out.print(“value of x:” + x);
x++;
System.out.print(“n”);
}while(x<20)
For(initialization;boolean_expression;update)
{
//statements
}
for(int x=10;x<20;x=x+1)
{
System.out.print(“value of x=” + x);
System.out.print(“n”);
}
for (declaration:expression)
{
//statements
}
int[] numbers={10,20,30,40,50};
for(int x:numbers)
{
System.out.println(x);
}
 The break keyword is used to stop the entire
loop.The break keyword must be used inside
any loop or a switch statement.
 The break keyword will stop the execution of
the innermost loop and start executing the
next line of code after the block.
 The continue keyword can be used in any of
the loop control structures. It causes the loop
to immediately jump to the next iteration of
the loop.
 In a for loop, the continue keyword causes
flow of control to immediately jump to the
update statement.
 In a while loop or do/while loop, flow of
control immediately jumps to the boolean
expression.
Java session4

More Related Content

What's hot

Dive into Python Class
Dive into Python ClassDive into Python Class
Dive into Python ClassJim Yeh
 
Classes & objects new
Classes & objects newClasses & objects new
Classes & objects newlykado0dles
 
Lecture - 2 Environment setup & JDK, JRE, JVM
Lecture - 2 Environment setup & JDK, JRE, JVMLecture - 2 Environment setup & JDK, JRE, JVM
Lecture - 2 Environment setup & JDK, JRE, JVMmanish kumar
 
Lecture 8 abstract class and interface
Lecture   8 abstract class and interfaceLecture   8 abstract class and interface
Lecture 8 abstract class and interfacemanish kumar
 
Ppt on this and super keyword
Ppt on this and super keywordPpt on this and super keyword
Ppt on this and super keywordtanu_jaswal
 
Unit3 inheritance
Unit3 inheritanceUnit3 inheritance
Unit3 inheritanceKalai Selvi
 
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYAPYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYAMaulik Borsaniya
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++rprajat007
 
ITFT-Classes and object in java
ITFT-Classes and object in javaITFT-Classes and object in java
ITFT-Classes and object in javaAtul Sehdev
 
encapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloadingencapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloadingShivam Singhal
 
Python unit 3 m.sc cs
Python unit 3 m.sc csPython unit 3 m.sc cs
Python unit 3 m.sc csKALAISELVI P
 
Data members and member functions
Data members and member functionsData members and member functions
Data members and member functionsMarlom46
 
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...Ayes Chinmay
 

What's hot (20)

Lecture 7 arrays
Lecture   7 arraysLecture   7 arrays
Lecture 7 arrays
 
Dive into Python Class
Dive into Python ClassDive into Python Class
Dive into Python Class
 
Classes & objects new
Classes & objects newClasses & objects new
Classes & objects new
 
OOPs & Inheritance Notes
OOPs & Inheritance NotesOOPs & Inheritance Notes
OOPs & Inheritance Notes
 
Lecture - 2 Environment setup & JDK, JRE, JVM
Lecture - 2 Environment setup & JDK, JRE, JVMLecture - 2 Environment setup & JDK, JRE, JVM
Lecture - 2 Environment setup & JDK, JRE, JVM
 
Lecture 8 abstract class and interface
Lecture   8 abstract class and interfaceLecture   8 abstract class and interface
Lecture 8 abstract class and interface
 
Classes&amp;objects
Classes&amp;objectsClasses&amp;objects
Classes&amp;objects
 
Ppt on this and super keyword
Ppt on this and super keywordPpt on this and super keyword
Ppt on this and super keyword
 
Unit3 inheritance
Unit3 inheritanceUnit3 inheritance
Unit3 inheritance
 
Class or Object
Class or ObjectClass or Object
Class or Object
 
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYAPYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
 
ITFT-Classes and object in java
ITFT-Classes and object in javaITFT-Classes and object in java
ITFT-Classes and object in java
 
encapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloadingencapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloading
 
Python unit 3 m.sc cs
Python unit 3 m.sc csPython unit 3 m.sc cs
Python unit 3 m.sc cs
 
Unit 5 java-awt (1)
Unit 5 java-awt (1)Unit 5 java-awt (1)
Unit 5 java-awt (1)
 
Dynamic method dispatch
Dynamic method dispatchDynamic method dispatch
Dynamic method dispatch
 
Class and object in C++ By Pawan Thakur
Class and object in C++ By Pawan ThakurClass and object in C++ By Pawan Thakur
Class and object in C++ By Pawan Thakur
 
Data members and member functions
Data members and member functionsData members and member functions
Data members and member functions
 
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
 

Viewers also liked (13)

File mangement
File mangementFile mangement
File mangement
 
Java session2
Java session2Java session2
Java session2
 
Basic object oriented approach
Basic object oriented approachBasic object oriented approach
Basic object oriented approach
 
Java session14
Java session14Java session14
Java session14
 
Java session13
Java session13Java session13
Java session13
 
C programming
C programmingC programming
C programming
 
Computer networks
Computer networksComputer networks
Computer networks
 
Java session3
Java session3Java session3
Java session3
 
Unit 1
Unit 1Unit 1
Unit 1
 
Java session5
Java session5Java session5
Java session5
 
Unit 1(sem-iv)
Unit 1(sem-iv)Unit 1(sem-iv)
Unit 1(sem-iv)
 
Unit 2
Unit 2Unit 2
Unit 2
 
Unit 2
Unit 2Unit 2
Unit 2
 

Similar to Java session4

Lecture - 3 Variables-data type_operators_oops concept
Lecture - 3 Variables-data type_operators_oops conceptLecture - 3 Variables-data type_operators_oops concept
Lecture - 3 Variables-data type_operators_oops conceptmanish kumar
 
Lect 1-java object-classes
Lect 1-java object-classesLect 1-java object-classes
Lect 1-java object-classesFajar Baskoro
 
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...vekariyakashyap
 
Introduction of Object Oriented Programming Language using Java. .pptx
Introduction of Object Oriented Programming Language using Java. .pptxIntroduction of Object Oriented Programming Language using Java. .pptx
Introduction of Object Oriented Programming Language using Java. .pptxPoonam60376
 
Unit vi(dsc++)
Unit vi(dsc++)Unit vi(dsc++)
Unit vi(dsc++)Durga Devi
 
Keyword of java
Keyword of javaKeyword of java
Keyword of javaJani Harsh
 
Basic concept of class, method , command line-argument
Basic concept of class, method , command line-argumentBasic concept of class, method , command line-argument
Basic concept of class, method , command line-argumentSuresh Mohta
 
class as the basis.pptx
class as the basis.pptxclass as the basis.pptx
class as the basis.pptxEpsiba1
 
Java tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelJava tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelRamrao Desai
 
14. Defining Classes
14. Defining Classes14. Defining Classes
14. Defining ClassesIntro C# Book
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.Tarunsingh198
 

Similar to Java session4 (20)

Object oriented concepts
Object oriented conceptsObject oriented concepts
Object oriented concepts
 
Ch-2ppt.pptx
Ch-2ppt.pptxCh-2ppt.pptx
Ch-2ppt.pptx
 
Lecture - 3 Variables-data type_operators_oops concept
Lecture - 3 Variables-data type_operators_oops conceptLecture - 3 Variables-data type_operators_oops concept
Lecture - 3 Variables-data type_operators_oops concept
 
Overview of Java
Overview of Java Overview of Java
Overview of Java
 
Lect 1-java object-classes
Lect 1-java object-classesLect 1-java object-classes
Lect 1-java object-classes
 
Java For Automation
Java   For AutomationJava   For Automation
Java For Automation
 
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
 
Introduction of Object Oriented Programming Language using Java. .pptx
Introduction of Object Oriented Programming Language using Java. .pptxIntroduction of Object Oriented Programming Language using Java. .pptx
Introduction of Object Oriented Programming Language using Java. .pptx
 
Java Basic day-2
Java Basic day-2Java Basic day-2
Java Basic day-2
 
Unit vi(dsc++)
Unit vi(dsc++)Unit vi(dsc++)
Unit vi(dsc++)
 
Classes objects in java
Classes objects in javaClasses objects in java
Classes objects in java
 
Keyword of java
Keyword of javaKeyword of java
Keyword of java
 
Java Programming - 04 object oriented in java
Java Programming - 04 object oriented in javaJava Programming - 04 object oriented in java
Java Programming - 04 object oriented in java
 
Basic concept of class, method , command line-argument
Basic concept of class, method , command line-argumentBasic concept of class, method , command line-argument
Basic concept of class, method , command line-argument
 
class as the basis.pptx
class as the basis.pptxclass as the basis.pptx
class as the basis.pptx
 
Basic_Java_02.pptx
Basic_Java_02.pptxBasic_Java_02.pptx
Basic_Java_02.pptx
 
Java tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelJava tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry Level
 
14. Defining Classes
14. Defining Classes14. Defining Classes
14. Defining Classes
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.
 
Lecture 6.pptx
Lecture 6.pptxLecture 6.pptx
Lecture 6.pptx
 

Recently uploaded

CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 

Recently uploaded (20)

CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 

Java session4

  • 2.  Object- objects have states and behaviors. Example:A dog has states-color, name, breed , as well as behaviors – barking, eating.An object is an instance of a class.  Class- A class can be defined as a template/blue print that describe the behavior/states that object of its type support.
  • 3.  public class dog { String breed; int age; String color; void barking(){} void hungry(){} void sleeping(){} }
  • 4.  Local variable: variables defined inside the methods, constructor or block are called local variables.The variable will declared and initialized within the method and the variable will be destroyed when the method has completed.  Instance variable: instance variable are variable within a class but outside any method.These variables are instantiated when class is loaded. Instance variable can be accessed form inside any method, constructor or blocks at the particular class.  Class variables: class variables are variables declared within a class, outside any method, with the static keyword.
  • 5.  When discussing about classes one of the most important sub topic would be constructors. Every class has a constructor. If we do not explicitly write a constructor for a class the java compiler builds a default constructor for that class.  Each time a new object is created at least one constructor will be invoked.The main rule of constructors is that they should have the same name as the class. A class can have more than one constructor.
  • 6.  public class std { public std() { } public std(String name) { // the constructor has one parameter, name } }
  • 7. public class std { public std(String name) { System.out.println(“passed name is” + name); } public static void main(String args[]) { std s1= new std(“ram”); } }
  • 8. /* First create an object */ Objectreference= new constructor(); /* Now call a variable as follows */ objectreference.variableName; /* Now you can call a class method as follows */ objectreference.MethodName();
  • 9.  There can be only one public class per source file.  A source file can have multiple non public classes.  The public class name should be the name of the source file as well as which should be appended by .Java at the end. For example: the class name is . Public class employee{} then the source file should be as employee.java  if the class is defined inside a package, then the package statement should be the first statement in source file.
  • 10.  Java provides a rich set of operators to manipulate variables.We can divide all the java operators into the following groups:  Arithmetic operators  Relational operators  Bitwise operators  Logical operators  Assignment operators  Misc operators
  • 11.  Arithmetic operators are used in mathematical expressions in the same way that they are used in algebra.The following table lists the arithmetic operators:
  • 12.
  • 13.
  • 14.  Java defines several bitwise operators which can be applied to the integer types, long , int , short, char and byte.  Bitwise operator works on bits and perform bit by bit operation. Assume if a=60; and b= 13; now in binary format they will be as follows: a= 0011 1100 b= 0000 1101 --------------------------- a & b= 0000 1100 a | b = 0011 1101 a ^ b = 0011 0001 ~a = 1100 0011
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.  Conditional operator is also known as the ternary operator.This operator consist of three operands and is used to evaluate boolean expressions.The goal of the operator is to decide which value should be assigned to the variable.The operator written as:  Variable x= (expression)?Value if true: value if false
  • 20.  public class test { public static void main(String args[]) { int a,b; a= 10; b= (a==1)?20:30; System.out.println(“value of b is:” + b); b=(a==10)?20:30; System.out.println(“value of b is:”+b); } }
  • 21.  The operator is used only for object reference variables.The operator checks whether the object is of a particular type(class type or interface type). instanceOf operator is written as:  (Object reference variable) instanceOf (class/interface type)  String name==‘james’;  boolean result = name instanceOf String;  //this will return true since name is type of String
  • 23.  If statement  An if statement consists of a boolean expression followd by one or more statements. If(boolean_expression) { //statement will execute if the boolean expression is true. }
  • 24.  If Statement  If…else Statement  If…else if…else statement  Nested if…else statement
  • 25.  A switch statement allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each case: switch(expression) { case value: break; case value: break; case value: break; default: //optional statements }
  • 26. public class test { public static void main(String args[]) { char grade=args[0].charAt(0); switch(grade) { case ’A’ : System.out.println(“Excellent!”); break; case ’B’ : case ’C’ : System.out.println(“Well Done”); break; case ‘D’: System.out.println(“you passed”); break; case ‘F’: System.out.println(“Better try again”); break; default: System.out.println(“invalid grade”); } System.out.println(“your grade is ” + grade); } }
  • 27.  There may be a situation when we need to execute a block of code several number of times, and is often referred to as a loop.  Java has very flexible three looping mechanisms. You can use one of the following three loops :  While loop  Do…while loop  For loop  As of java 5 the enhanced for loop was introduced. This is mainly used for arrays.
  • 29. do { //statements } while(boolean_expression); do { System.out.print(“value of x:” + x); x++; System.out.print(“n”); }while(x<20)
  • 32.  The break keyword is used to stop the entire loop.The break keyword must be used inside any loop or a switch statement.  The break keyword will stop the execution of the innermost loop and start executing the next line of code after the block.
  • 33.  The continue keyword can be used in any of the loop control structures. It causes the loop to immediately jump to the next iteration of the loop.  In a for loop, the continue keyword causes flow of control to immediately jump to the update statement.  In a while loop or do/while loop, flow of control immediately jumps to the boolean expression.