SlideShare a Scribd company logo
Khasimsaheb
 The javadoc program generates HTML API
documentation from the “javadoc” style comments in
your code.
/* This kind comment can span multiple lines */
// This kind is of to the end of the line
/* This kind of comment is a special
* ‘javadoc’ style comment
*/
 The class is the fundamental concept in JAVA (and other
OOPLs)
 A class describes some data object(s), and the
operations (or methods) that can be applied to those
objects
 Every object and method in Java belongs to a class
 Classes have data (fields) and code (methods) and
classes (member classes or inner classes)
 Static methods and fields belong to the class itself
 Others belong to instances
class Person { Variable
String name;
int age; Method
void birthday ( )
{
age++;
System.out.println (name +
' is now ' + age);
}
}
{ int x = 12;
/* only x available */
{ int q = 96;
/* both x and q available */
}
/* only x available */
/* q “out of scope” */
}
{ int x = 12;
{ int x = 96; /* illegal */
}
}
This is ok in C/C++ but not in Java.
 Java objects don’t have the same lifetimes as
primitives.
 When you create a Java object using new, it
hangs around past the end of the scope.
 Here, the scope of name s is delimited by the {}s
but the String object hangs around until GC’d
{
String s = new String("a string");
} /* end of scope */
 Java methods and variables can be declared static
 These exist independent of any object
 This means that a Class’s
◦ static methods can be called even if no objects of that
class have been created and
◦ static data is “shared” by all instances (i.e., one rvalue
per class instead of one per instance
class StaticTest {static int i = 47;}
StaticTest st1 = new StaticTest();
StaticTest st2 = new StaticTest();
// st1.i == st2.I == 47
StaticTest.i++; // or st1.I++ or
st2.I++
// st1.i == st2.I == 48
public class Circle {public class Circle {
// A class field// A class field
public static final double PI= 3.14159; // A usefulpublic static final double PI= 3.14159; // A useful
constantconstant
// A class method: just compute a value based on the// A class method: just compute a value based on the
argumentsarguments
public static double radiansToDegrees(double rads) {public static double radiansToDegrees(double rads) {
return rads * 180 / PI;return rads * 180 / PI;
}}
// An instance field// An instance field
public double r; // The radius of thepublic double r; // The radius of the
circlecircle
// Two methods which operate on the instance fields of// Two methods which operate on the instance fields of
an objectan object
public double area() { // Compute the area ofpublic double area() { // Compute the area of
the circlethe circle
return PI * r * r;return PI * r * r;
}}
public double circumference() { // Compute thepublic double circumference() { // Compute the
circumference of the circlecircumference of the circle
return 2 * PI * r;return 2 * PI * r;
}}
}}
 Subscripts always start at 0 as in C
 Subscript checking is done automatically
 Certain operations are defined on arrays of
objects, as for other classes
◦ e.g. myArray.length == 5
 Person mary = new Person ( );
 int myArray[ ] = new int[5];
 int myArray[ ] = {1, 4, 9, 16, 25};
 String languages [ ] = {"Prolog", "Java"};
 Since arrays are objects they are allocated dynamically
 Arrays, like all objects, are subject to garbage collection
when no more references remain
◦ so fewer memory leaks
◦ Java doesn’t have pointers!
Example
Programs
 C:UMBC331java>type echo.java
 // This is the Echo example from the Sun tutorial
 class echo {
 public static void main(String args[]) {
 for (int i=0; i < args.length; i++) {
 System.out.println( args[i] );
 }
 }
 }
 C:UMBC331java>javac echo.java
 C:UMBC331java>java echo this is pretty silly
 this
 is
 pretty
 silly
 C:UMBC331java> NSIT ,Jetalpur
/* This program computes the factorial of a number
*/
public class Factorial { // Define a class
public static void main(String[] args) { // The program starts
here
int input = Integer.parseInt(args[0]); // Get the user's
input
double result = factorial(input); // Compute the
factorial
System.out.println(result); // Print out the
result
} // The main() method
ends here
public static double factorial(int x) { // This method
computes x!
if (x < 0) // Check for bad
input
return 0.0; // if bad, return 0
double fact = 1.0; // Begin with an
initial value
while(x > 1) { // Loop until x
equals
fact = fact * x; // multiply by x
each time NSIT ,Jetalpur
 Classes should define one or more methods to create
or construct instances of the class
 Their name is the same as the class name
◦ note deviation from convention that methods begin with lower
case
 Constructors are differentiated by the number and
types of their arguments
◦ An example of overloading
 If you don’t define a constructor, a default one will be
created.
 Constructors automatically invoke the zero argument
constructor of their superclass when they begin (note
that this yields a recursive process!)
NSIT ,Jetalpur
 Java methods are like C/C++ functions.
General case:
returnType methodName ( arg1, arg2, … argN)
{
methodBody
}
The return keyword exits a method optionally with a value
int storage(String s) {return s.length() * 2;}
boolean flag() { return true; }
float naturalLogBase() { return 2.718f; }
void nothing() { return; }
void nothing2() {}

More Related Content

PPT
Java Concepts
PPT
Core java
PPTX
Core java concepts
PPT
Core java concepts
PPT
Best Core Java Training In Bangalore
PPT
Core java concepts
PPT
PPT
Object and class
Java Concepts
Core java
Core java concepts
Core java concepts
Best Core Java Training In Bangalore
Core java concepts
Object and class

What's hot (20)

PPTX
Constructor in java
PPT
Java Basics
PPT
Java: Objects and Object References
PPT
C++ classes
PPTX
Chapter2 array of objects
PPTX
Class object method constructors in java
PDF
ITFT-Classes and object in java
PDF
Java Methods
PPTX
Classes,object and methods java
PPT
Java basic tutorial
PPTX
Java class,object,method introduction
PPTX
Classes and Objects in C#
PDF
Class and Objects in Java
PPTX
Classes in c++ (OOP Presentation)
PPT
Lect 1-class and object
PPTX
Static keyword ppt
PPT
Core Java Concepts
PPTX
constructors in java ppt
PPTX
Class or Object
PPTX
[OOP - Lec 20,21] Inheritance
Constructor in java
Java Basics
Java: Objects and Object References
C++ classes
Chapter2 array of objects
Class object method constructors in java
ITFT-Classes and object in java
Java Methods
Classes,object and methods java
Java basic tutorial
Java class,object,method introduction
Classes and Objects in C#
Class and Objects in Java
Classes in c++ (OOP Presentation)
Lect 1-class and object
Static keyword ppt
Core Java Concepts
constructors in java ppt
Class or Object
[OOP - Lec 20,21] Inheritance
Ad

Viewers also liked (10)

PPTX
Computing homework
PDF
Fast Food Industry - Preventive Measures against Fraud/Theft by Employees (p...
PPTX
Eald staff meeting nov
PPTX
Ձյուն
PPT
"Morska energetyka wiatrowa" - seminaium popularnonaukowe (24-25.10.2012), Wi...
PPTX
Climate zones group 4
PPT
Mule architecture
PPTX
Apuntes seminario de vida en el Espíritu Santo-semana-1
PPTX
Turn Your Affiliate Marketing Up To 11 With Local SEO
Computing homework
Fast Food Industry - Preventive Measures against Fraud/Theft by Employees (p...
Eald staff meeting nov
Ձյուն
"Morska energetyka wiatrowa" - seminaium popularnonaukowe (24-25.10.2012), Wi...
Climate zones group 4
Mule architecture
Apuntes seminario de vida en el Espíritu Santo-semana-1
Turn Your Affiliate Marketing Up To 11 With Local SEO
Ad

Similar to Core Java (20)

PPT
Core java concepts
PPT
java02.pptsatrrhfhf https://www.slideshare.net/slideshow/java-notespdf-259708...
PPT
Java basic
PPTX
CORE JAVA PPT FOR ENGINEERS BBBBBBBBBBBBBBBBBBB
PPT
Java Basics
 
PPT
PPT
PPT
Corejava Training in Bangalore Tutorial
PPTX
Java assignment help
PPT
Core java concepts
PPT
Defining classes-and-objects-1.0
PDF
Java Programming - 04 object oriented in java
PDF
OOPs & Inheritance Notes
PDF
22 scheme OOPs with C++ BCS306B_module2.pdfmodule2.pdf
PPTX
Class and Object.pptx from nit patna ece department
PDF
Class and Object JAVA PROGRAMMING LANG .pdf
PPT
Java for the Impatient, Java Constructors, Scope, Wrappers, Inheritance, and ...
PPT
Unit 1 Part - 3 constructor Overloading Static.ppt
PPTX
object oriented programming using java, second sem BCA,UoM
PPTX
Week9 Intro to classes and objects in Java
Core java concepts
java02.pptsatrrhfhf https://www.slideshare.net/slideshow/java-notespdf-259708...
Java basic
CORE JAVA PPT FOR ENGINEERS BBBBBBBBBBBBBBBBBBB
Java Basics
 
Corejava Training in Bangalore Tutorial
Java assignment help
Core java concepts
Defining classes-and-objects-1.0
Java Programming - 04 object oriented in java
OOPs & Inheritance Notes
22 scheme OOPs with C++ BCS306B_module2.pdfmodule2.pdf
Class and Object.pptx from nit patna ece department
Class and Object JAVA PROGRAMMING LANG .pdf
Java for the Impatient, Java Constructors, Scope, Wrappers, Inheritance, and ...
Unit 1 Part - 3 constructor Overloading Static.ppt
object oriented programming using java, second sem BCA,UoM
Week9 Intro to classes and objects in Java

More from Khasim Saheb (20)

PPT
Mule anypoint exchange
PPTX
Mule soap
PPTX
Mule soa
PPT
Mule security saml
PPT
Mule security jaas
PPTX
Mule integration with linkedin
PPTX
Mule for each scope headerc ollection
PPTX
Mule esb
PPTX
Mule esb stripe
PPT
Mule esb api layer
PPTX
PPTX
Mmc rest api user groups
PPTX
Mapping and listing with mule
PPTX
How to use message properties component
PPTX
How to use expression filter
PPTX
Data weave
PPT
Anypoint data gateway
PPTX
Creating dynamic json
PPTX
Converting with custom transforme
PPTX
Caching and invalidating with managed store
Mule anypoint exchange
Mule soap
Mule soa
Mule security saml
Mule security jaas
Mule integration with linkedin
Mule for each scope headerc ollection
Mule esb
Mule esb stripe
Mule esb api layer
Mmc rest api user groups
Mapping and listing with mule
How to use message properties component
How to use expression filter
Data weave
Anypoint data gateway
Creating dynamic json
Converting with custom transforme
Caching and invalidating with managed store

Recently uploaded (20)

PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
Cloud computing and distributed systems.
PDF
KodekX | Application Modernization Development
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Review of recent advances in non-invasive hemoglobin estimation
Mobile App Security Testing_ A Comprehensive Guide.pdf
Programs and apps: productivity, graphics, security and other tools
Building Integrated photovoltaic BIPV_UPV.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Unlocking AI with Model Context Protocol (MCP)
Cloud computing and distributed systems.
KodekX | Application Modernization Development
Digital-Transformation-Roadmap-for-Companies.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
The AUB Centre for AI in Media Proposal.docx
Advanced methodologies resolving dimensionality complications for autism neur...
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
20250228 LYD VKU AI Blended-Learning.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...

Core Java

  • 2.  The javadoc program generates HTML API documentation from the “javadoc” style comments in your code. /* This kind comment can span multiple lines */ // This kind is of to the end of the line /* This kind of comment is a special * ‘javadoc’ style comment */
  • 3.  The class is the fundamental concept in JAVA (and other OOPLs)  A class describes some data object(s), and the operations (or methods) that can be applied to those objects  Every object and method in Java belongs to a class  Classes have data (fields) and code (methods) and classes (member classes or inner classes)  Static methods and fields belong to the class itself  Others belong to instances
  • 4. class Person { Variable String name; int age; Method void birthday ( ) { age++; System.out.println (name + ' is now ' + age); } }
  • 5. { int x = 12; /* only x available */ { int q = 96; /* both x and q available */ } /* only x available */ /* q “out of scope” */ } { int x = 12; { int x = 96; /* illegal */ } } This is ok in C/C++ but not in Java.
  • 6.  Java objects don’t have the same lifetimes as primitives.  When you create a Java object using new, it hangs around past the end of the scope.  Here, the scope of name s is delimited by the {}s but the String object hangs around until GC’d { String s = new String("a string"); } /* end of scope */
  • 7.  Java methods and variables can be declared static  These exist independent of any object  This means that a Class’s ◦ static methods can be called even if no objects of that class have been created and ◦ static data is “shared” by all instances (i.e., one rvalue per class instead of one per instance class StaticTest {static int i = 47;} StaticTest st1 = new StaticTest(); StaticTest st2 = new StaticTest(); // st1.i == st2.I == 47 StaticTest.i++; // or st1.I++ or st2.I++ // st1.i == st2.I == 48
  • 8. public class Circle {public class Circle { // A class field// A class field public static final double PI= 3.14159; // A usefulpublic static final double PI= 3.14159; // A useful constantconstant // A class method: just compute a value based on the// A class method: just compute a value based on the argumentsarguments public static double radiansToDegrees(double rads) {public static double radiansToDegrees(double rads) { return rads * 180 / PI;return rads * 180 / PI; }} // An instance field// An instance field public double r; // The radius of thepublic double r; // The radius of the circlecircle // Two methods which operate on the instance fields of// Two methods which operate on the instance fields of an objectan object public double area() { // Compute the area ofpublic double area() { // Compute the area of the circlethe circle return PI * r * r;return PI * r * r; }} public double circumference() { // Compute thepublic double circumference() { // Compute the circumference of the circlecircumference of the circle return 2 * PI * r;return 2 * PI * r; }} }}
  • 9.  Subscripts always start at 0 as in C  Subscript checking is done automatically  Certain operations are defined on arrays of objects, as for other classes ◦ e.g. myArray.length == 5
  • 10.  Person mary = new Person ( );  int myArray[ ] = new int[5];  int myArray[ ] = {1, 4, 9, 16, 25};  String languages [ ] = {"Prolog", "Java"};  Since arrays are objects they are allocated dynamically  Arrays, like all objects, are subject to garbage collection when no more references remain ◦ so fewer memory leaks ◦ Java doesn’t have pointers!
  • 12.  C:UMBC331java>type echo.java  // This is the Echo example from the Sun tutorial  class echo {  public static void main(String args[]) {  for (int i=0; i < args.length; i++) {  System.out.println( args[i] );  }  }  }  C:UMBC331java>javac echo.java  C:UMBC331java>java echo this is pretty silly  this  is  pretty  silly  C:UMBC331java> NSIT ,Jetalpur
  • 13. /* This program computes the factorial of a number */ public class Factorial { // Define a class public static void main(String[] args) { // The program starts here int input = Integer.parseInt(args[0]); // Get the user's input double result = factorial(input); // Compute the factorial System.out.println(result); // Print out the result } // The main() method ends here public static double factorial(int x) { // This method computes x! if (x < 0) // Check for bad input return 0.0; // if bad, return 0 double fact = 1.0; // Begin with an initial value while(x > 1) { // Loop until x equals fact = fact * x; // multiply by x each time NSIT ,Jetalpur
  • 14.  Classes should define one or more methods to create or construct instances of the class  Their name is the same as the class name ◦ note deviation from convention that methods begin with lower case  Constructors are differentiated by the number and types of their arguments ◦ An example of overloading  If you don’t define a constructor, a default one will be created.  Constructors automatically invoke the zero argument constructor of their superclass when they begin (note that this yields a recursive process!) NSIT ,Jetalpur
  • 15.  Java methods are like C/C++ functions. General case: returnType methodName ( arg1, arg2, … argN) { methodBody } The return keyword exits a method optionally with a value int storage(String s) {return s.length() * 2;} boolean flag() { return true; } float naturalLogBase() { return 2.718f; } void nothing() { return; } void nothing2() {}