SlideShare a Scribd company logo
ABDUL IMRAN KHAN
CORE JAVA
Comments are almost like C++
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
*/
JAVA Classes
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
An example of a class
class Person { Variable
String name;
int age; Method
void birthday ( )
{
age++;
System.out.println (name +
' is now ' + age);
}
}
Scoping
As in C/C++, scope is determined by the placement of curly braces {}.
A variable defined within a scope is available only to the end of that scope.
{ 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.
Scope of Objects
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;
}}
}}
Array Operations
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
An array is an object
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
NSIT ,Jetalpur
 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
x = x - 1; // and then
decrement x
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!)
values
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

What's hot (20)

PPT
Object and class
mohit tripathi
 
PPT
Java
javeed_mhd
 
PPTX
Class object method constructors in java
Raja Sekhar
 
PPT
Java
Khasim Cise
 
PPT
Core Java Concepts
mdfkhan625
 
PPTX
Constructor in java
Pavith Gunasekara
 
PPT
Java: Objects and Object References
Tareq Hasan
 
PDF
Class and Objects in Java
Spotle.ai
 
PPT
C++ classes
imhammadali
 
PPTX
Classes, objects in JAVA
Abhilash Nair
 
PPTX
Classes,object and methods java
Padma Kannan
 
PPT
Basic c#
kishore4268
 
PPTX
Unit ii
donny101
 
PPTX
Classes in c++ (OOP Presentation)
Majid Saeed
 
PPT
Classes and data abstraction
Hoang Nguyen
 
PDF
Java Methods
Rosmina Joy Cabauatan
 
PPT
Lect 1-class and object
Fajar Baskoro
 
PDF
ITFT-Classes and object in java
Atul Sehdev
 
PPT
11 Using classes and objects
maznabili
 
PPT
Java oops PPT
kishu0005
 
Object and class
mohit tripathi
 
Class object method constructors in java
Raja Sekhar
 
Core Java Concepts
mdfkhan625
 
Constructor in java
Pavith Gunasekara
 
Java: Objects and Object References
Tareq Hasan
 
Class and Objects in Java
Spotle.ai
 
C++ classes
imhammadali
 
Classes, objects in JAVA
Abhilash Nair
 
Classes,object and methods java
Padma Kannan
 
Basic c#
kishore4268
 
Unit ii
donny101
 
Classes in c++ (OOP Presentation)
Majid Saeed
 
Classes and data abstraction
Hoang Nguyen
 
Java Methods
Rosmina Joy Cabauatan
 
Lect 1-class and object
Fajar Baskoro
 
ITFT-Classes and object in java
Atul Sehdev
 
11 Using classes and objects
maznabili
 
Java oops PPT
kishu0005
 

Viewers also liked (20)

PPTX
01 introduction to oop and java
রাকিন রাকিন
 
ODP
Scala 2 + 2 > 4
Emil Vladev
 
PDF
History of java
Mani Sarkar
 
PPT
Java programming: Elementary practice
Karwan Mustafa Kareem
 
PPTX
Introduction to JAVA
javatrainingonline
 
PPTX
Java session2
Rajeev Kumar
 
PPTX
History of java'
deepthisujithra
 
PPTX
OOPs in Java
Ranjith Sekar
 
PPT
Java oops and fundamentals
javaease
 
PPTX
Java String
SATYAM SHRIVASTAV
 
ODP
Introduction To Java.
Tushar Chauhan
 
PPTX
Basic Concepts of OOPs (Object Oriented Programming in Java)
Michelle Anne Meralpis
 
PPT
Java basic
Sonam Sharma
 
PDF
Introduction to Java Programming Language
jaimefrozr
 
PPT
Java Tutorial
Vijay A Raj
 
PPTX
Java programming course for beginners
Eduonix Learning Solutions
 
PPT
Core java concepts
Ram132
 
PDF
Introduction to Java Programming
Ravi Kant Sahu
 
PPT
Java tutorial PPT
Intelligo Technologies
 
01 introduction to oop and java
রাকিন রাকিন
 
Scala 2 + 2 > 4
Emil Vladev
 
History of java
Mani Sarkar
 
Java programming: Elementary practice
Karwan Mustafa Kareem
 
Introduction to JAVA
javatrainingonline
 
Java session2
Rajeev Kumar
 
History of java'
deepthisujithra
 
OOPs in Java
Ranjith Sekar
 
Java oops and fundamentals
javaease
 
Java String
SATYAM SHRIVASTAV
 
Introduction To Java.
Tushar Chauhan
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Michelle Anne Meralpis
 
Java basic
Sonam Sharma
 
Introduction to Java Programming Language
jaimefrozr
 
Java Tutorial
Vijay A Raj
 
Java programming course for beginners
Eduonix Learning Solutions
 
Core java concepts
Ram132
 
Introduction to Java Programming
Ravi Kant Sahu
 
Java tutorial PPT
Intelligo Technologies
 
Ad

Similar to Java Concepts (20)

PPT
Best Core Java Training In Bangalore
rajkamaltibacademy
 
PPT
java02.pptsatrrhfhf https://www.slideshare.net/slideshow/java-notespdf-259708...
atharvtayde5632
 
PPTX
CORE JAVA PPT FOR ENGINEERS BBBBBBBBBBBBBBBBBBB
NagarathnaRajur2
 
PPT
Java Basics
F K
 
PPT
Corejava Training in Bangalore Tutorial
rajkamaltibacademy
 
PPT
Core java concepts
Chikugehlot
 
PPTX
Java assignment help
Jacob William
 
PDF
Java Programming - 04 object oriented in java
Danairat Thanabodithammachari
 
PPT
Unit 1 Part - 3 constructor Overloading Static.ppt
DeepVala5
 
PPT
Defining classes-and-objects-1.0
BG Java EE Course
 
PDF
Lecture 5
Muhammad Fayyaz
 
PDF
22 scheme OOPs with C++ BCS306B_module2.pdfmodule2.pdf
sindhus795217
 
PDF
OOPs & Inheritance Notes
Shalabh Chaudhary
 
PDF
Java Basic day-2
Kamlesh Singh
 
PPT
Java for the Impatient, Java Constructors, Scope, Wrappers, Inheritance, and ...
argsstring
 
PPT
Java tutorial for Beginners and Entry Level
Ramrao Desai
 
PDF
Java OO Revisited
Jussi Pohjolainen
 
PPTX
Inheritance.pptx
Karthik Rohan
 
PPTX
object oriented programming using java, second sem BCA,UoM
ambikavenkatesh2
 
DOCX
OOP Lab Report.docx
ArafatSahinAfridi
 
Best Core Java Training In Bangalore
rajkamaltibacademy
 
java02.pptsatrrhfhf https://www.slideshare.net/slideshow/java-notespdf-259708...
atharvtayde5632
 
CORE JAVA PPT FOR ENGINEERS BBBBBBBBBBBBBBBBBBB
NagarathnaRajur2
 
Java Basics
F K
 
Corejava Training in Bangalore Tutorial
rajkamaltibacademy
 
Core java concepts
Chikugehlot
 
Java assignment help
Jacob William
 
Java Programming - 04 object oriented in java
Danairat Thanabodithammachari
 
Unit 1 Part - 3 constructor Overloading Static.ppt
DeepVala5
 
Defining classes-and-objects-1.0
BG Java EE Course
 
Lecture 5
Muhammad Fayyaz
 
22 scheme OOPs with C++ BCS306B_module2.pdfmodule2.pdf
sindhus795217
 
OOPs & Inheritance Notes
Shalabh Chaudhary
 
Java Basic day-2
Kamlesh Singh
 
Java for the Impatient, Java Constructors, Scope, Wrappers, Inheritance, and ...
argsstring
 
Java tutorial for Beginners and Entry Level
Ramrao Desai
 
Java OO Revisited
Jussi Pohjolainen
 
Inheritance.pptx
Karthik Rohan
 
object oriented programming using java, second sem BCA,UoM
ambikavenkatesh2
 
OOP Lab Report.docx
ArafatSahinAfridi
 
Ad

More from AbdulImrankhan7 (20)

PPT
Web services Overview in depth
AbdulImrankhan7
 
PPTX
Install sonarqube plugin
AbdulImrankhan7
 
PPTX
Junit in mule
AbdulImrankhan7
 
PPTX
commit a project in svn
AbdulImrankhan7
 
PPTX
Github plugin setup in anypoint studio
AbdulImrankhan7
 
PPTX
For each component
AbdulImrankhan7
 
PPTX
Filter expression
AbdulImrankhan7
 
PPTX
Mule File component
AbdulImrankhan7
 
PPTX
Mule Database component
AbdulImrankhan7
 
PPTX
Mule Choice component
AbdulImrankhan7
 
PPTX
Mule stored procedure
AbdulImrankhan7
 
PPTX
Deploying and running in mule standalone
AbdulImrankhan7
 
PPT
Mule real-world
AbdulImrankhan7
 
PPT
Mule Overview
AbdulImrankhan7
 
PPTX
Webservice with vm in mule
AbdulImrankhan7
 
PPTX
Validating a soap request in mule
AbdulImrankhan7
 
PPTX
Using xslt in mule
AbdulImrankhan7
 
PPTX
Simple groovy example in mule
AbdulImrankhan7
 
PPTX
Scatter gather flow control
AbdulImrankhan7
 
PPTX
Mule with velocity
AbdulImrankhan7
 
Web services Overview in depth
AbdulImrankhan7
 
Install sonarqube plugin
AbdulImrankhan7
 
Junit in mule
AbdulImrankhan7
 
commit a project in svn
AbdulImrankhan7
 
Github plugin setup in anypoint studio
AbdulImrankhan7
 
For each component
AbdulImrankhan7
 
Filter expression
AbdulImrankhan7
 
Mule File component
AbdulImrankhan7
 
Mule Database component
AbdulImrankhan7
 
Mule Choice component
AbdulImrankhan7
 
Mule stored procedure
AbdulImrankhan7
 
Deploying and running in mule standalone
AbdulImrankhan7
 
Mule real-world
AbdulImrankhan7
 
Mule Overview
AbdulImrankhan7
 
Webservice with vm in mule
AbdulImrankhan7
 
Validating a soap request in mule
AbdulImrankhan7
 
Using xslt in mule
AbdulImrankhan7
 
Simple groovy example in mule
AbdulImrankhan7
 
Scatter gather flow control
AbdulImrankhan7
 
Mule with velocity
AbdulImrankhan7
 

Recently uploaded (20)

PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
July Patch Tuesday
Ivanti
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
July Patch Tuesday
Ivanti
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 

Java Concepts

  • 2. Comments are almost like C++ 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. JAVA Classes 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. An example of a class class Person { Variable String name; int age; Method void birthday ( ) { age++; System.out.println (name + ' is now ' + age); } }
  • 5. Scoping As in C/C++, scope is determined by the placement of curly braces {}. A variable defined within a scope is available only to the end of that scope. { 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. Scope of Objects 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. Array Operations 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. An array is an object 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. NSIT ,Jetalpur  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>
  • 13. 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 x = x - 1; // and then decrement x
  • 14. 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!)
  • 15. values 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() {}