SlideShare a Scribd company logo
1 of 25
By 
SHRIDHAR B
 Java supports single-line and multi-line comments that is 
very similar to c and c++ 
public class MyFirstJavaProgram{ 
/* this is my first java program 
* this will print Hello World as output 
* this is an example of multi-line comments 
*/ 
public static void main(String args[]) 
{ 
//This is an Example of a single line comment 
/* This is also an example of a single line comment */ 
}
 Class is a blue print from which individual objects are created. 
public class Dog{ 
String breed; 
int age; 
String color; 
void barking(){ 
} 
void hungry(){ 
} 
}
 Object is nothing but an instance of a class 
 Objects have both state and behaviors 
 Ex: 
If we consider dog then its state is – name , 
breed and the behavior is barking, wagging ,running
 public class Puppy { 
Public Puppy(String name) { 
// This constructor has one parameter, name. 
System.out.println("Passed Name is :"+ name ); 
} 
public static void main(String[]args) { 
// Following statement would create an object myPuppy 
Puppy myPuppy =new Puppy("tommy"); 
} 
}
 A class contain any of the following variable types 
 Local Variables 
Instance Variables 
Class Variables
public class Test{ 
public void pupAge(){ 
int age =0; 
age = age +7; 
System.out.println("Puppy age is : "+age); 
} 
public static void main(String args[]){ 
Test test =new Test(); 
test.pupAge(); 
} 
}
public class Test{ 
int age; 
public void pupAge(){ 
System.out.println("Puppy age is :"+age); 
} 
public static void main(String args[]){ 
Test test =new Test(); 
test.pupAge(); 
} 
}
 import java.io.*; 
public class Employee{ 
public static final String DEPARTMENT="Development "; 
public static void main(String args[]){ 
salary =1000; 
System.out.println(DEPARTMENT+"averagesalary:"+sa 
lary); } 
}
public class Puppy { 
public puppy(){ 
} 
public puppy(String name) { 
// This constructor has one parameter, name. 
} 
}
 Visible to the package, the default. No modifiers are 
needed. 
 Visible to the class only (private). 
 Visible to the world (public). 
 Visible to the package and all subclasses (protected).
package cert; 
public class Sludge { 
public void testIt() { 
System.out.println("sludge"); 
} 
} 
package book; 
import cert.*; // Import all classes in the cert package 
class Goo { 
public static void main(String[] args) { 
Sludge o = new Sludge(); 
o.testIt(); 
} 
}
public classLogger{ 
private String format; 
public String getFormat() 
{ 
return this.format; 
} 
public void setFormat(String format){ 
this.format = format; 
} 
}
package cert; 
class Beverage { 
} 
package exam.stuff; 
import cert.Beverage; 
class Tea extends Beverage { 
} 
 Can't access class cert.Beverage. Class or interface must 
be public, in same package, or an accessible member 
class.
class AudioPlayer{ 
protected boolean openSpeaker(Speaker sp){ 
//implementation details 
} 
} 
class StreamingAudioPlayer{ 
boolean openSpeaker(Speaker sp){ 
// implementation details 
} 
}
 Final 
 Abstract 
 Static 
 Synchronized
package cert; 
public final class Beverage { 
public void importantMethod() { 
} 
} 
package exam.stuff; 
import cert.Beverage; 
class Tea extends Beverage { 
} 
Can't subclass final classes: class 
cert.Beverage class Tea extends Beverage{ 
1 error
Class Bank{ 
int accountBalance ; 
public Bank(){ 
accountbalance = 10000; 
} 
Synchronized void BalanceInquiry(){ 
System.out.println(“account balance is 
:”+accountbalance); 
} 
}
abstract class Hotel 
{ 
public void Idli(){ 
System.out.println(“Prepare Idli”); 
} 
abstract public void Dosa(); 
}
 A literal is source code representation of a fixed 
value 
 Literals can be assigned to any primitive type 
variable 
 Ex: 
byte a = 68; 
int decimal = 100; 
String name = “shridhar”
 Reference Data Types: 
 Reference variables are created using defined 
constructors of the classes. They are used to access 
objects. These variables are declared to be of a specific 
type that cannot be changed. For example, Employee, 
Puppy, etc. 
 Class objects and various types of array variables come 
under reference data type. 
 Default value of any reference variable is null. 
 A reference variable can be used to refer to any object of 
the declared type or any compatible type. 
 Example: Animal animal = new Animal("giraffe");
 Instance variables and methods are accessed via 
created objects. 
/* 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();
public class Puppy{ 
int puppyAge; 
public Puppy(String name){ 
System.out.println("Passed Name is :"+name ); 
} 
public void setAge(int age ){ 
puppyAge = age; 
} 
publicint getAge(){ 
System.out.println("Puppy's age is :"+ puppyAge ); 
return puppyAge; 
}
public static void main(String[]args){ 
Puppy myPuppy =newPuppy("tommy"); 
myPuppy.setAge(2); 
myPuppy.getAge(); 
/* You can access instance variable as follows as 
well */ 
System.out.println("Variable Value :"+ 
myPuppy.puppyAge ); 
} 
}
Java2

More Related Content

What's hot

How to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programmingHow to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programmingSyed Faizan Hassan
 
Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonBasics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonSujith Kumar
 
Object oriented programming with python
Object oriented programming with pythonObject oriented programming with python
Object oriented programming with pythonArslan Arshad
 
[OOP - Lec 13,14,15] Constructors / Destructor and its Types
[OOP - Lec 13,14,15] Constructors / Destructor and its Types[OOP - Lec 13,14,15] Constructors / Destructor and its Types
[OOP - Lec 13,14,15] Constructors / Destructor and its TypesMuhammad Hammad Waseem
 
Java ppt Gandhi Ravi (gandhiri@gmail.com)
Java ppt  Gandhi Ravi  (gandhiri@gmail.com)Java ppt  Gandhi Ravi  (gandhiri@gmail.com)
Java ppt Gandhi Ravi (gandhiri@gmail.com)Gandhi Ravi
 
Data members and member functions
Data members and member functionsData members and member functions
Data members and member functionsMarlom46
 
09 Object Oriented Programming in PHP #burningkeyboards
09 Object Oriented Programming in PHP #burningkeyboards09 Object Oriented Programming in PHP #burningkeyboards
09 Object Oriented Programming in PHP #burningkeyboardsDenis Ristic
 
Declarative Data Modeling in Python
Declarative Data Modeling in PythonDeclarative Data Modeling in Python
Declarative Data Modeling in PythonJoshua Forman
 
Class and object in c++
Class and object in c++Class and object in c++
Class and object in c++NainaKhan28
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingAhmed Swilam
 
object oriented programming language by c++
object oriented programming language by c++object oriented programming language by c++
object oriented programming language by c++Mohamad Al_hsan
 
Classes in c++ (OOP Presentation)
Classes in c++ (OOP Presentation)Classes in c++ (OOP Presentation)
Classes in c++ (OOP Presentation)Majid Saeed
 

What's hot (20)

Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
[OOP - Lec 20,21] Inheritance
[OOP - Lec 20,21] Inheritance[OOP - Lec 20,21] Inheritance
[OOP - Lec 20,21] Inheritance
 
How to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programmingHow to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programming
 
Oop concepts in python
Oop concepts in pythonOop concepts in python
Oop concepts in python
 
C++ classes
C++ classesC++ classes
C++ classes
 
Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonBasics of Object Oriented Programming in Python
Basics of Object Oriented Programming in Python
 
Object oriented programming with python
Object oriented programming with pythonObject oriented programming with python
Object oriented programming with python
 
Introduction to c ++ part -2
Introduction to c ++   part -2Introduction to c ++   part -2
Introduction to c ++ part -2
 
[OOP - Lec 13,14,15] Constructors / Destructor and its Types
[OOP - Lec 13,14,15] Constructors / Destructor and its Types[OOP - Lec 13,14,15] Constructors / Destructor and its Types
[OOP - Lec 13,14,15] Constructors / Destructor and its Types
 
Java ppt Gandhi Ravi (gandhiri@gmail.com)
Java ppt  Gandhi Ravi  (gandhiri@gmail.com)Java ppt  Gandhi Ravi  (gandhiri@gmail.com)
Java ppt Gandhi Ravi (gandhiri@gmail.com)
 
Data members and member functions
Data members and member functionsData members and member functions
Data members and member functions
 
Introduction to php oop
Introduction to php oopIntroduction to php oop
Introduction to php oop
 
09 Object Oriented Programming in PHP #burningkeyboards
09 Object Oriented Programming in PHP #burningkeyboards09 Object Oriented Programming in PHP #burningkeyboards
09 Object Oriented Programming in PHP #burningkeyboards
 
Declarative Data Modeling in Python
Declarative Data Modeling in PythonDeclarative Data Modeling in Python
Declarative Data Modeling in Python
 
C++ And Object in lecture3
C++  And Object in lecture3C++  And Object in lecture3
C++ And Object in lecture3
 
Class and object in c++
Class and object in c++Class and object in c++
Class and object in c++
 
Class 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented ProgrammingClass 7 - PHP Object Oriented Programming
Class 7 - PHP Object Oriented Programming
 
object oriented programming language by c++
object oriented programming language by c++object oriented programming language by c++
object oriented programming language by c++
 
Classes in c++ (OOP Presentation)
Classes in c++ (OOP Presentation)Classes in c++ (OOP Presentation)
Classes in c++ (OOP Presentation)
 

Similar to Java2

14. Defining Classes
14. Defining Classes14. Defining Classes
14. Defining ClassesIntro C# Book
 
Keywords of java
Keywords of javaKeywords of java
Keywords of javaJani Harsh
 
Week9 Intro to classes and objects in Java
Week9 Intro to classes and objects in JavaWeek9 Intro to classes and objects in Java
Week9 Intro to classes and objects in Javakjkleindorfer
 
3. Объекты, классы и пакеты в Java
3. Объекты, классы и пакеты в Java3. Объекты, классы и пакеты в Java
3. Объекты, классы и пакеты в JavaDEVTYPE
 
Core java concepts
Core java concepts Core java concepts
Core java concepts javeed_mhd
 
Keyword of java
Keyword of javaKeyword of java
Keyword of javaJani Harsh
 
Defining classes-and-objects-1.0
Defining classes-and-objects-1.0Defining classes-and-objects-1.0
Defining classes-and-objects-1.0BG Java EE Course
 
CONSTRUCTORS IN C++ +2 COMPUTER SCIENCE
CONSTRUCTORS IN C++ +2 COMPUTER SCIENCECONSTRUCTORS IN C++ +2 COMPUTER SCIENCE
CONSTRUCTORS IN C++ +2 COMPUTER SCIENCEVenugopalavarma Raja
 
object oriented programming using java, second sem BCA,UoM
object oriented programming using java, second sem BCA,UoMobject oriented programming using java, second sem BCA,UoM
object oriented programming using java, second sem BCA,UoMambikavenkatesh2
 
Java Generics
Java GenericsJava Generics
Java Genericsjeslie
 
Java oops PPT
Java oops PPTJava oops PPT
Java oops PPTkishu0005
 
Internet programming slide - java.ppt
Internet programming slide - java.pptInternet programming slide - java.ppt
Internet programming slide - java.pptMikeAdva
 
02-OOP with Java.ppt
02-OOP with Java.ppt02-OOP with Java.ppt
02-OOP with Java.pptEmanAsem4
 
Java осень 2012 лекция 2
Java осень 2012 лекция 2Java осень 2012 лекция 2
Java осень 2012 лекция 2Technopark
 

Similar to Java2 (20)

OOP Lab Report.docx
OOP Lab Report.docxOOP Lab Report.docx
OOP Lab Report.docx
 
14. Defining Classes
14. Defining Classes14. Defining Classes
14. Defining Classes
 
OOPs & Inheritance Notes
OOPs & Inheritance NotesOOPs & Inheritance Notes
OOPs & Inheritance Notes
 
Keywords of java
Keywords of javaKeywords of java
Keywords of java
 
Week9 Intro to classes and objects in Java
Week9 Intro to classes and objects in JavaWeek9 Intro to classes and objects in Java
Week9 Intro to classes and objects in Java
 
3. Объекты, классы и пакеты в Java
3. Объекты, классы и пакеты в Java3. Объекты, классы и пакеты в Java
3. Объекты, классы и пакеты в Java
 
Java session4
Java session4Java session4
Java session4
 
Core java concepts
Core java concepts Core java concepts
Core java concepts
 
Core Java
Core JavaCore Java
Core Java
 
Keyword of java
Keyword of javaKeyword of java
Keyword of java
 
Defining classes-and-objects-1.0
Defining classes-and-objects-1.0Defining classes-and-objects-1.0
Defining classes-and-objects-1.0
 
CONSTRUCTORS IN C++ +2 COMPUTER SCIENCE
CONSTRUCTORS IN C++ +2 COMPUTER SCIENCECONSTRUCTORS IN C++ +2 COMPUTER SCIENCE
CONSTRUCTORS IN C++ +2 COMPUTER SCIENCE
 
Java Concepts
Java ConceptsJava Concepts
Java Concepts
 
object oriented programming using java, second sem BCA,UoM
object oriented programming using java, second sem BCA,UoMobject oriented programming using java, second sem BCA,UoM
object oriented programming using java, second sem BCA,UoM
 
Java Generics
Java GenericsJava Generics
Java Generics
 
Java oops PPT
Java oops PPTJava oops PPT
Java oops PPT
 
Class introduction in java
Class introduction in javaClass introduction in java
Class introduction in java
 
Internet programming slide - java.ppt
Internet programming slide - java.pptInternet programming slide - java.ppt
Internet programming slide - java.ppt
 
02-OOP with Java.ppt
02-OOP with Java.ppt02-OOP with Java.ppt
02-OOP with Java.ppt
 
Java осень 2012 лекция 2
Java осень 2012 лекция 2Java осень 2012 лекция 2
Java осень 2012 лекция 2
 

More from Shridhar Ramesh

More from Shridhar Ramesh (6)

Core java
Core javaCore java
Core java
 
Java(Access Modifiers)
Java(Access Modifiers)Java(Access Modifiers)
Java(Access Modifiers)
 
Java Object-Oriented Programming Conecpts(Real-Time) Examples
Java Object-Oriented Programming Conecpts(Real-Time) ExamplesJava Object-Oriented Programming Conecpts(Real-Time) Examples
Java Object-Oriented Programming Conecpts(Real-Time) Examples
 
Java
JavaJava
Java
 
Java
JavaJava
Java
 
Android
AndroidAndroid
Android
 

Recently uploaded

AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 

Recently uploaded (20)

AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 

Java2

  • 2.  Java supports single-line and multi-line comments that is very similar to c and c++ public class MyFirstJavaProgram{ /* this is my first java program * this will print Hello World as output * this is an example of multi-line comments */ public static void main(String args[]) { //This is an Example of a single line comment /* This is also an example of a single line comment */ }
  • 3.  Class is a blue print from which individual objects are created. public class Dog{ String breed; int age; String color; void barking(){ } void hungry(){ } }
  • 4.  Object is nothing but an instance of a class  Objects have both state and behaviors  Ex: If we consider dog then its state is – name , breed and the behavior is barking, wagging ,running
  • 5.  public class Puppy { Public Puppy(String name) { // This constructor has one parameter, name. System.out.println("Passed Name is :"+ name ); } public static void main(String[]args) { // Following statement would create an object myPuppy Puppy myPuppy =new Puppy("tommy"); } }
  • 6.  A class contain any of the following variable types  Local Variables Instance Variables Class Variables
  • 7. public class Test{ public void pupAge(){ int age =0; age = age +7; System.out.println("Puppy age is : "+age); } public static void main(String args[]){ Test test =new Test(); test.pupAge(); } }
  • 8. public class Test{ int age; public void pupAge(){ System.out.println("Puppy age is :"+age); } public static void main(String args[]){ Test test =new Test(); test.pupAge(); } }
  • 9.  import java.io.*; public class Employee{ public static final String DEPARTMENT="Development "; public static void main(String args[]){ salary =1000; System.out.println(DEPARTMENT+"averagesalary:"+sa lary); } }
  • 10. public class Puppy { public puppy(){ } public puppy(String name) { // This constructor has one parameter, name. } }
  • 11.  Visible to the package, the default. No modifiers are needed.  Visible to the class only (private).  Visible to the world (public).  Visible to the package and all subclasses (protected).
  • 12. package cert; public class Sludge { public void testIt() { System.out.println("sludge"); } } package book; import cert.*; // Import all classes in the cert package class Goo { public static void main(String[] args) { Sludge o = new Sludge(); o.testIt(); } }
  • 13. public classLogger{ private String format; public String getFormat() { return this.format; } public void setFormat(String format){ this.format = format; } }
  • 14. package cert; class Beverage { } package exam.stuff; import cert.Beverage; class Tea extends Beverage { }  Can't access class cert.Beverage. Class or interface must be public, in same package, or an accessible member class.
  • 15. class AudioPlayer{ protected boolean openSpeaker(Speaker sp){ //implementation details } } class StreamingAudioPlayer{ boolean openSpeaker(Speaker sp){ // implementation details } }
  • 16.  Final  Abstract  Static  Synchronized
  • 17. package cert; public final class Beverage { public void importantMethod() { } } package exam.stuff; import cert.Beverage; class Tea extends Beverage { } Can't subclass final classes: class cert.Beverage class Tea extends Beverage{ 1 error
  • 18. Class Bank{ int accountBalance ; public Bank(){ accountbalance = 10000; } Synchronized void BalanceInquiry(){ System.out.println(“account balance is :”+accountbalance); } }
  • 19. abstract class Hotel { public void Idli(){ System.out.println(“Prepare Idli”); } abstract public void Dosa(); }
  • 20.  A literal is source code representation of a fixed value  Literals can be assigned to any primitive type variable  Ex: byte a = 68; int decimal = 100; String name = “shridhar”
  • 21.  Reference Data Types:  Reference variables are created using defined constructors of the classes. They are used to access objects. These variables are declared to be of a specific type that cannot be changed. For example, Employee, Puppy, etc.  Class objects and various types of array variables come under reference data type.  Default value of any reference variable is null.  A reference variable can be used to refer to any object of the declared type or any compatible type.  Example: Animal animal = new Animal("giraffe");
  • 22.  Instance variables and methods are accessed via created objects. /* 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();
  • 23. public class Puppy{ int puppyAge; public Puppy(String name){ System.out.println("Passed Name is :"+name ); } public void setAge(int age ){ puppyAge = age; } publicint getAge(){ System.out.println("Puppy's age is :"+ puppyAge ); return puppyAge; }
  • 24. public static void main(String[]args){ Puppy myPuppy =newPuppy("tommy"); myPuppy.setAge(2); myPuppy.getAge(); /* You can access instance variable as follows as well */ System.out.println("Variable Value :"+ myPuppy.puppyAge ); } }