SlideShare une entreprise Scribd logo
1  sur  22
1
Presentation on
Core Java
by Mayank Sinha
Appendix A: Introduction
to Java
2
What is Java?
• Java is a programming language.
• similar to C++ in syntax
• Java is a high level , secured and object oriented
language.
• Java is palteform indepenedent language. It has its own
runtime environment(JRE) & API’s called platform.
3
Some Salient Characteristics of Java
• Java is platform independent: the same program can run
on any correctly implemented Java system
• Java is object-oriented:
• Structured in terms of classes, which group data with
operations on that data
• Can construct new classes by extending existing ones
• Java designed as
• A core language
• A rich collection of commonly available packages
• Java used to build desktop, mobile, web applications,games
etc..
OOPS in java
• Java has been built around the core concepts of OOP
• In Java, everything revolves around classes and objects.
• A class is a blueprint or template that defines the structure and behavior of
objects.
• An object is an instance of a class that represents a specific entity or instance
in a program.
• Polymorphism : Polymorphism enables us to write generic code that can work with
objects of different types
• Encapsulation : This states the principle of bundling data (attributes) and related
behaviors (methods) together within a class.
• Abstraction : Abstraction allows us to define abstract classes and interfaces, which
define common attributes and methods that can be shared among multiple classes.
• Inheritance : Inheritance allows us to define a hierarchy of classes, where
subclasses inherit properties and behaviors from a superclass.
5
Java Processing and Execution
• Execution of Java Begin with Java source code in text
files: Model.java
• A Java source code compiler produces Java byte code
• Outputs one file per class: Model.class
• May be standalone or part of an IDE
• A Java Virtual Machine loads and executes class files
• May compile them to native code (e.g., x86) internally
6
Compiling and Executing a Java Program
7
Classes and Objects
• The class is the unit of programming
• A Java program is a collection of classes
• Each class definition (usually) in its own .java file
• The file name must match the class name
• A class describes objects (instances)
• Describes their common characteristics: is a blueprint
• Thus all the instances have these same characteristics
• These characteristics are:
• Data fields for each object
• Methods (operations) that do work on the objects
8
A Little Example of import and main
import javax.swing.*;
// all classes from javax.swing
public class HelloWorld { // starts a class
public static void main (String[] args) {
// starts a main method
// in: array of String; out: none (void)
}
}
9
References and Primitive Data Types
• Java distinguishes two kinds of entities
• Primitive types
• Objects
• Primitive-type data is stored in primitive-type variables
Represent numbers, characters, boolean values
Integers: byte, short, int, and long
Real numbers: float and double
Characters: char
• Reference variables store the address of an object
10
Primitive Data Types
True or false
boolean
Unicode characters (generally 16 bits per char)
char
+/-10-308 to +/-10+308 and 0, about 15 digits precision
double
+/-10-38 to +/-10+38 and 0, about 6 digits precision
float
-9,223,372,036,854,775,808 .. ... (64 bits)
long
-2,147,483,648 .. 2,147,483,647 (32 bits)
int
-32,768 .. 32,767 (16 bits)
short
-128 .. 127 (8 bits)
byte
Range of values
Data type
11
Operators
1. subscript [ ], call ( ), member access .
2. pre/post-increment ++ --, boolean complement !,
bitwise complement ~, unary + -, type cast (type),
object creation new
3. * / %
4. binary + - (+ also concatenates strings)
5. signed shift << >>, unsigned shift >>>
6. comparison < <= > >=, class test instanceof
7. equality comparison == !=
8. bitwise and &
9. bitwise or |
12
Operators
11.logical (sequential) and &&
12.logical (sequential) or ||
13.conditional cond ? true-expr : false-expr
14.assignment =, compound assignment += -= *= /=
<<= >>= >>>= &= |=
13
Escape Sequences
• An escape sequence is a sequence of two characters
beginning with the character 
• A way to represents special characters/symbols
14
Type Compatibility and Conversion
• Widening conversion:
• In operations on mixed-type operands, the numeric
type of the smaller range is converted to the numeric
type of the larger range
• In an assignment, a numeric type of smaller range
can be assigned to a numeric type of larger range
15
cont..
• byte to short, byte to long
byte bv = 100;
short sv = (short)/(long) bv;
• int to float,int to double
int a= 10;
float x=(float/double)a;
• int to char
int intValue = 65;
char charValue = (char) intValue;
Memory management in java
• memory management is handled automatically by the Java Virtual Machine (JVM),
which is responsible for allocating and deallocating memory for Java programs
>>Heap: The heap is the memory area used for dynamic memory allocation in Java.
Objects are created on the heap using the new keyword, and memory for objects is
automatically allocated and deallocated by the JVM's garbage collector.
>>Garbage Collection: Java uses automatic garbage collection to frees memory
occupied by objects that are no longer in use.
>>Stack: Each thread in a Java program has its own stack, known as the "call stack" or
"execution stack." The stack is used to store local variables, method calls, and
program execution information.
17
Referencing and Creating Objects
• You can declare reference variables
• They reference objects of specified types
• Two reference variables can reference the same object
• The new operator creates an instance of a class
• A constructor executes when a new object is created
• Example: String greeting = ″hello″;
18
The String Class
• The String class defines a data type that is used to
store a sequence of characters
• You cannot modify a String object
• If you attempt to do so, Java will create a new object
that contains the modified character sequence
19
Methods & Constructors
• A Java method defines a group of statements as performing a
particular operation
• static indicates a static or class method
• A method that is not static is an instance method
• All method arguments are call-by-value
• A constructor is a special method that is used to initialize objects of a
class. It is called automatically when an object is created using the new
keyword.
• Constructor has no return type
• name is exactly same to its class name
20
Summary of the Review
• A Java program is a collection of classes & objects
• The JVM approach enables a Java program written on
one machine to execute on any other machine that has a
JVM
• Java defines a set of primitive data types that are used
to represent numbers, characters, and boolean data
• The control structures of Java are similar to those found
in other languages
• The Java String and StringBuffer classes are used
to reference objects that store character strings
21
Chapter Review (continued)
• Be sure to use methods such as equals and
compareTo to compare the contents of String objects
• You can declare your own Java classes and create
objects of these classes using the new operator
• A class has data fields and instance methods
• The stream classes in package java.io read strings
from the console and display strings to the console, and
also support I/O file
Thank You

Contenu connexe

Similaire à ppt_on_java.pptx

Unit 1 Core Java for Compter Science 3rd
Unit 1 Core Java for Compter Science 3rdUnit 1 Core Java for Compter Science 3rd
Unit 1 Core Java for Compter Science 3rd
prat0ham
 
chapter_one_Introduction_to_Object_Oriented_Programming_OOP.pptx
chapter_one_Introduction_to_Object_Oriented_Programming_OOP.pptxchapter_one_Introduction_to_Object_Oriented_Programming_OOP.pptx
chapter_one_Introduction_to_Object_Oriented_Programming_OOP.pptx
FiromsaDine
 
Android webinar class_java_review
Android webinar class_java_reviewAndroid webinar class_java_review
Android webinar class_java_review
Edureka!
 
A begineers guide of JAVA - Getting Started
 A begineers guide of JAVA - Getting Started A begineers guide of JAVA - Getting Started
A begineers guide of JAVA - Getting Started
Rakesh Madugula
 
Java programing language unit 1 introduction
Java programing language unit 1 introductionJava programing language unit 1 introduction
Java programing language unit 1 introduction
chnrketan
 

Similaire à ppt_on_java.pptx (20)

Java Tutorials
Java Tutorials Java Tutorials
Java Tutorials
 
Java
JavaJava
Java
 
oop unit1.pptx
oop unit1.pptxoop unit1.pptx
oop unit1.pptx
 
CS8392 OOP
CS8392 OOPCS8392 OOP
CS8392 OOP
 
Unit 1 Core Java for Compter Science 3rd
Unit 1 Core Java for Compter Science 3rdUnit 1 Core Java for Compter Science 3rd
Unit 1 Core Java for Compter Science 3rd
 
intro_java (1).pptx
intro_java (1).pptxintro_java (1).pptx
intro_java (1).pptx
 
Java-Intro.pptx
Java-Intro.pptxJava-Intro.pptx
Java-Intro.pptx
 
Scala-Ls1
Scala-Ls1Scala-Ls1
Scala-Ls1
 
chapter_one_Introduction_to_Object_Oriented_Programming_OOP.pptx
chapter_one_Introduction_to_Object_Oriented_Programming_OOP.pptxchapter_one_Introduction_to_Object_Oriented_Programming_OOP.pptx
chapter_one_Introduction_to_Object_Oriented_Programming_OOP.pptx
 
Learning core java
Learning core javaLearning core java
Learning core java
 
Introduction_to_Java.ppt
Introduction_to_Java.pptIntroduction_to_Java.ppt
Introduction_to_Java.ppt
 
Comp102 lec 3
Comp102   lec 3Comp102   lec 3
Comp102 lec 3
 
Introduction to oop and java fundamentals
Introduction to oop and java fundamentalsIntroduction to oop and java fundamentals
Introduction to oop and java fundamentals
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Android webinar class_java_review
Android webinar class_java_reviewAndroid webinar class_java_review
Android webinar class_java_review
 
How to train the jdt dragon
How to train the jdt dragonHow to train the jdt dragon
How to train the jdt dragon
 
Java SpringMVC SpringBOOT (Divergent).ppt
Java SpringMVC SpringBOOT (Divergent).pptJava SpringMVC SpringBOOT (Divergent).ppt
Java SpringMVC SpringBOOT (Divergent).ppt
 
Unit 1
Unit 1Unit 1
Unit 1
 
A begineers guide of JAVA - Getting Started
 A begineers guide of JAVA - Getting Started A begineers guide of JAVA - Getting Started
A begineers guide of JAVA - Getting Started
 
Java programing language unit 1 introduction
Java programing language unit 1 introductionJava programing language unit 1 introduction
Java programing language unit 1 introduction
 

Dernier

Complex plane, Modulus, Argument, Graphical representation of a complex numbe...
Complex plane, Modulus, Argument, Graphical representation of a complex numbe...Complex plane, Modulus, Argument, Graphical representation of a complex numbe...
Complex plane, Modulus, Argument, Graphical representation of a complex numbe...
MohammadAliNayeem
 
Paint shop management system project report.pdf
Paint shop management system project report.pdfPaint shop management system project report.pdf
Paint shop management system project report.pdf
Kamal Acharya
 

Dernier (20)

Dairy management system project report..pdf
Dairy management system project report..pdfDairy management system project report..pdf
Dairy management system project report..pdf
 
How to Design and spec harmonic filter.pdf
How to Design and spec harmonic filter.pdfHow to Design and spec harmonic filter.pdf
How to Design and spec harmonic filter.pdf
 
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and VisualizationKIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
 
Complex plane, Modulus, Argument, Graphical representation of a complex numbe...
Complex plane, Modulus, Argument, Graphical representation of a complex numbe...Complex plane, Modulus, Argument, Graphical representation of a complex numbe...
Complex plane, Modulus, Argument, Graphical representation of a complex numbe...
 
Furniture showroom management system project.pdf
Furniture showroom management system project.pdfFurniture showroom management system project.pdf
Furniture showroom management system project.pdf
 
Natalia Rutkowska - BIM School Course in Kraków
Natalia Rutkowska - BIM School Course in KrakówNatalia Rutkowska - BIM School Course in Kraków
Natalia Rutkowska - BIM School Course in Kraków
 
ROAD CONSTRUCTION PRESENTATION.PPTX.pptx
ROAD CONSTRUCTION PRESENTATION.PPTX.pptxROAD CONSTRUCTION PRESENTATION.PPTX.pptx
ROAD CONSTRUCTION PRESENTATION.PPTX.pptx
 
Research Methodolgy & Intellectual Property Rights Series 1
Research Methodolgy & Intellectual Property Rights Series 1Research Methodolgy & Intellectual Property Rights Series 1
Research Methodolgy & Intellectual Property Rights Series 1
 
Artificial Intelligence Bayesian Reasoning
Artificial Intelligence Bayesian ReasoningArtificial Intelligence Bayesian Reasoning
Artificial Intelligence Bayesian Reasoning
 
Introduction to Artificial Intelligence and History of AI
Introduction to Artificial Intelligence and History of AIIntroduction to Artificial Intelligence and History of AI
Introduction to Artificial Intelligence and History of AI
 
ANSI(ST)-III_Manufacturing-I_05052020.pdf
ANSI(ST)-III_Manufacturing-I_05052020.pdfANSI(ST)-III_Manufacturing-I_05052020.pdf
ANSI(ST)-III_Manufacturing-I_05052020.pdf
 
Introduction to Machine Learning Unit-4 Notes for II-II Mechanical Engineering
Introduction to Machine Learning Unit-4 Notes for II-II Mechanical EngineeringIntroduction to Machine Learning Unit-4 Notes for II-II Mechanical Engineering
Introduction to Machine Learning Unit-4 Notes for II-II Mechanical Engineering
 
solid state electronics ktu module 5 slides
solid state electronics ktu module 5 slidessolid state electronics ktu module 5 slides
solid state electronics ktu module 5 slides
 
"United Nations Park" Site Visit Report.
"United Nations Park" Site  Visit Report."United Nations Park" Site  Visit Report.
"United Nations Park" Site Visit Report.
 
BRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWING
BRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWINGBRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWING
BRAKING SYSTEM IN INDIAN RAILWAY AutoCAD DRAWING
 
Lect_Z_Transform_Main_digital_image_processing.pptx
Lect_Z_Transform_Main_digital_image_processing.pptxLect_Z_Transform_Main_digital_image_processing.pptx
Lect_Z_Transform_Main_digital_image_processing.pptx
 
Arduino based vehicle speed tracker project
Arduino based vehicle speed tracker projectArduino based vehicle speed tracker project
Arduino based vehicle speed tracker project
 
Lab Manual Arduino UNO Microcontrollar.docx
Lab Manual Arduino UNO Microcontrollar.docxLab Manual Arduino UNO Microcontrollar.docx
Lab Manual Arduino UNO Microcontrollar.docx
 
Paint shop management system project report.pdf
Paint shop management system project report.pdfPaint shop management system project report.pdf
Paint shop management system project report.pdf
 
RM&IPR M5 notes.pdfResearch Methodolgy & Intellectual Property Rights Series 5
RM&IPR M5 notes.pdfResearch Methodolgy & Intellectual Property Rights Series 5RM&IPR M5 notes.pdfResearch Methodolgy & Intellectual Property Rights Series 5
RM&IPR M5 notes.pdfResearch Methodolgy & Intellectual Property Rights Series 5
 

ppt_on_java.pptx

  • 2. Appendix A: Introduction to Java 2 What is Java? • Java is a programming language. • similar to C++ in syntax • Java is a high level , secured and object oriented language. • Java is palteform indepenedent language. It has its own runtime environment(JRE) & API’s called platform.
  • 3. 3 Some Salient Characteristics of Java • Java is platform independent: the same program can run on any correctly implemented Java system • Java is object-oriented: • Structured in terms of classes, which group data with operations on that data • Can construct new classes by extending existing ones • Java designed as • A core language • A rich collection of commonly available packages • Java used to build desktop, mobile, web applications,games etc..
  • 4. OOPS in java • Java has been built around the core concepts of OOP • In Java, everything revolves around classes and objects. • A class is a blueprint or template that defines the structure and behavior of objects. • An object is an instance of a class that represents a specific entity or instance in a program. • Polymorphism : Polymorphism enables us to write generic code that can work with objects of different types • Encapsulation : This states the principle of bundling data (attributes) and related behaviors (methods) together within a class. • Abstraction : Abstraction allows us to define abstract classes and interfaces, which define common attributes and methods that can be shared among multiple classes. • Inheritance : Inheritance allows us to define a hierarchy of classes, where subclasses inherit properties and behaviors from a superclass.
  • 5. 5 Java Processing and Execution • Execution of Java Begin with Java source code in text files: Model.java • A Java source code compiler produces Java byte code • Outputs one file per class: Model.class • May be standalone or part of an IDE • A Java Virtual Machine loads and executes class files • May compile them to native code (e.g., x86) internally
  • 6. 6 Compiling and Executing a Java Program
  • 7. 7 Classes and Objects • The class is the unit of programming • A Java program is a collection of classes • Each class definition (usually) in its own .java file • The file name must match the class name • A class describes objects (instances) • Describes their common characteristics: is a blueprint • Thus all the instances have these same characteristics • These characteristics are: • Data fields for each object • Methods (operations) that do work on the objects
  • 8. 8 A Little Example of import and main import javax.swing.*; // all classes from javax.swing public class HelloWorld { // starts a class public static void main (String[] args) { // starts a main method // in: array of String; out: none (void) } }
  • 9. 9 References and Primitive Data Types • Java distinguishes two kinds of entities • Primitive types • Objects • Primitive-type data is stored in primitive-type variables Represent numbers, characters, boolean values Integers: byte, short, int, and long Real numbers: float and double Characters: char • Reference variables store the address of an object
  • 10. 10 Primitive Data Types True or false boolean Unicode characters (generally 16 bits per char) char +/-10-308 to +/-10+308 and 0, about 15 digits precision double +/-10-38 to +/-10+38 and 0, about 6 digits precision float -9,223,372,036,854,775,808 .. ... (64 bits) long -2,147,483,648 .. 2,147,483,647 (32 bits) int -32,768 .. 32,767 (16 bits) short -128 .. 127 (8 bits) byte Range of values Data type
  • 11. 11 Operators 1. subscript [ ], call ( ), member access . 2. pre/post-increment ++ --, boolean complement !, bitwise complement ~, unary + -, type cast (type), object creation new 3. * / % 4. binary + - (+ also concatenates strings) 5. signed shift << >>, unsigned shift >>> 6. comparison < <= > >=, class test instanceof 7. equality comparison == != 8. bitwise and & 9. bitwise or |
  • 12. 12 Operators 11.logical (sequential) and && 12.logical (sequential) or || 13.conditional cond ? true-expr : false-expr 14.assignment =, compound assignment += -= *= /= <<= >>= >>>= &= |=
  • 13. 13 Escape Sequences • An escape sequence is a sequence of two characters beginning with the character • A way to represents special characters/symbols
  • 14. 14 Type Compatibility and Conversion • Widening conversion: • In operations on mixed-type operands, the numeric type of the smaller range is converted to the numeric type of the larger range • In an assignment, a numeric type of smaller range can be assigned to a numeric type of larger range
  • 15. 15 cont.. • byte to short, byte to long byte bv = 100; short sv = (short)/(long) bv; • int to float,int to double int a= 10; float x=(float/double)a; • int to char int intValue = 65; char charValue = (char) intValue;
  • 16. Memory management in java • memory management is handled automatically by the Java Virtual Machine (JVM), which is responsible for allocating and deallocating memory for Java programs >>Heap: The heap is the memory area used for dynamic memory allocation in Java. Objects are created on the heap using the new keyword, and memory for objects is automatically allocated and deallocated by the JVM's garbage collector. >>Garbage Collection: Java uses automatic garbage collection to frees memory occupied by objects that are no longer in use. >>Stack: Each thread in a Java program has its own stack, known as the "call stack" or "execution stack." The stack is used to store local variables, method calls, and program execution information.
  • 17. 17 Referencing and Creating Objects • You can declare reference variables • They reference objects of specified types • Two reference variables can reference the same object • The new operator creates an instance of a class • A constructor executes when a new object is created • Example: String greeting = ″hello″;
  • 18. 18 The String Class • The String class defines a data type that is used to store a sequence of characters • You cannot modify a String object • If you attempt to do so, Java will create a new object that contains the modified character sequence
  • 19. 19 Methods & Constructors • A Java method defines a group of statements as performing a particular operation • static indicates a static or class method • A method that is not static is an instance method • All method arguments are call-by-value • A constructor is a special method that is used to initialize objects of a class. It is called automatically when an object is created using the new keyword. • Constructor has no return type • name is exactly same to its class name
  • 20. 20 Summary of the Review • A Java program is a collection of classes & objects • The JVM approach enables a Java program written on one machine to execute on any other machine that has a JVM • Java defines a set of primitive data types that are used to represent numbers, characters, and boolean data • The control structures of Java are similar to those found in other languages • The Java String and StringBuffer classes are used to reference objects that store character strings
  • 21. 21 Chapter Review (continued) • Be sure to use methods such as equals and compareTo to compare the contents of String objects • You can declare your own Java classes and create objects of these classes using the new operator • A class has data fields and instance methods • The stream classes in package java.io read strings from the console and display strings to the console, and also support I/O file