SlideShare une entreprise Scribd logo
1  sur  58
Télécharger pour lire hors ligne
Java
Gandhi Ravi
Introduction of Java
Java is a programming language and a platform.
Java is a high level, robust, secured and object-oriented programming language.
Platform:
Any hardware or software environment in which a program runs, is known
as a platform.
Java has its own runtime environment (JRE) and API, it is called platform.
Java Program
How to compile and execute java file
What happens at compile time?
At compile time, java file is compiled by Java Compiler (It does not interact with OS) and converts the java code into bytecode.
Jdk : Java Development kit
JRE- Java Runtime Environment
JVM- Java Virtual Machine
The JVM performs following main tasks:
1. Loads code
2. Verifies code
3. Executes code
4. Provides runtime environment
Application of Java
Desktop Applications, media player, antivirus etc.
Web Applications such as irctc.co.in,
Enterprise Applications such as banking
Mobile
Embedded System
Smart Card
Robotics
Games etc.
Types of Java Applications
There are mainly 4 type of applications
1) Standalone Application
2) Web Application
3) Enterprise Application
4) Mobile Application
Features of Java
❖ Simple
❖ Object-Oriented
❖ Platform independent
❖ Secured
❖ Robust
❖ Architecture neutral
❖ Portable
❖ Dynamic
❖ Interpreted
❖ Multithreaded
❖ Distributed
Variable in Java
Variable is name of reserved area allocated in memory.
int my =50;//Here my is variable
There are three types of variables in java
1) local variable: A variable that is declared inside the method is called local variable.
2) instance variable:A variable that is declared inside the class but outside the method is called instance variable . It is not
declared as static.
3) static variable:A variable that is declared as static is called static variable. It cannot be local.
class A
{
int data=50;//instance variable
static int m=100;//static variable
void method(){
int n=90;//local variable
}
}//end of class
Datatypes in Java
Data Type - Default Value and size
Operator in Java
A - Arithmetic Operator + - * / %
R - Relational Operator < <= > >= == !=
I - Increment/Decrement Operator ++ --
L - Logical Operator && || !
A - Assignment Operator c=a+b
C - Conditional Operator max= (a>b)?a:b;
B - Bitwise Logical Operator
S- Special operator . dot operator
Keyword In Java
Constructor in Java
Constructor in java is a special type of method that is used to initialize the object.
Java constructor is invoked at the time of object creation.
It constructs the values i.e. provides data for the object that is why it is known as constructor.
Rules for creating java constructor
There are basically two rules defined for the constructor.
1. Constructor name must be same as its class name
2. Constructor must have no explicit return type
Types of java constructors
There are two types of constructors:
1. Default constructor (no-arg constructor)
2. Parameterized constructor
Default Constructor
Rule: If there is no constructor in a class, compiler automatically creates a default constructor.
Difference Between Method & Constructor
Q) Does constructor return any value?
Ans:yes, that is current class instance (You cannot use return type yet it returns a value).
static Keyword in Java
The static keyword in java is used for memory management mainly.
We can apply java static keyword with variables, methods, blocks and nested class. The static keyword belongs to the class than
instance of the class.
The static can be:
1. variable (also known as class variable)
2. method (also known as class method)
3. block
Java static method
If you apply static keyword with any method, it is known as static method.
● A static method belongs to the class rather than object of a class.
● A static method can be invoked without the need for creating an instance of a class.
● static method can access static data member and can change the value of it.
Static Method in java
//Program to get cube of a given number by static method
class Calculate{
static int cube(int x){
return x*x*x;
}
public static void main(String args[])
{
int result=Calculate.cube(5);
System.out.println(result);
}
}
There are two Restriction for static method in java
1. The static method can not use non static data member or call non-static method directly.
2. this and super cannot be used in static context.
why java main method is static?
Because object is not required to call static method if it were non-static method, jvm create object first then call main() method
that will lead the problem of extra memory allocation.
class My
{
Static
{
System.out.println("static block work");
}
public static void main(String args[]){
System.out.println("Hello Compindia Technologies");
}
}
Output:
Static block here
Hello compindia technologies
Inheritance in Java
Inheritance in java is a mechanism in which one object acquires all the properties and behaviors of parent object.
Why use inheritance in java
● For Method Overriding (so runtime polymorphism can be achieved).
● For Code Reusability.
Syntax of Java Inheritance
class Subclass-name extends Superclass-name
{
//methods and fields
}
The extends keyword indicates that you are making a new class that derives from an existing class.
In the terminology of Java, a class that is inherited is called a super class. The new class is called a subclass.
Types of inheritance in Java
There can be three types of inheritance in java: single, multilevel and hierarchical.
In java programming, multiple and hybrid inheritance is supported through interface only. We will learn about interfaces later.
Note: Multiple inheritance is not supported in java through class.
Multiple Inheritance in Java
Why multiple inheritance is not supported in java?
class A{
void msg(){System.out.println("Hello");}
}
class B{
void msg(){System.out.println("Welcome");}
}
class C extends A,B{//suppose if it were
Public Static void main(String args[]){
C obj=new C();
obj.msg();//Now which msg() method would be invoked?
}
} //compile time error
Real example of Java Method Overriding
class Bank{ int getRateOfInterest(){ return 0;} }
class SBI extends Bank{ int getRateOfInterest(){ return 8;} }
class ICICI extends Bank{ int getRateOfInterest(){ return 7;} }
class AXIS extends Bank{ int getRateOfInterest(){ return 9;} }
class Test2{
public static void main(String args[]){
SBI s=new SBI();
ICICI i=new ICICI();
AXIS a=new AXIS();
System.out.println("SBI Rate of Interest: "+s.getRateOfInterest());
System.out.println("ICICI Rate of Interest: "+i.getRateOfInterest());
System.out.println("AXIS Rate of Interest: "+a.getRateOfInterest());
}
}
Output: SBI Rate of Interest: 8
ICICI Rate of Interest: 7
AXIS Rate of Interest: 9
Method Overloading VS Method Overriding
Java Array
Normally, array is a collection of similar type of elements that have contiguous memory location.
Java array is an object the contains elements of similar data type.
It is a data structure where we store similar elements. We can store only fixed set of elements in a java array.
Array in java is index based, first element of the array is stored at 0 index.
Advantage of Java Array
● Code Optimization: It makes the code optimized, we can retrieve or sort the data easily.
● Random access: We can get any data located at any index position.
Types of Array in java
There are two types of array.
● Single Dimensional Array
● Multidimensional Array
Declare an Array in java
dataType[] arr; (or)
dataType []arr; (or)
dataType arr[];
Instantiation of an Array in java
arr =new datatype[size];
Declaration, Instantiation and Initialization of Java Array
int a[] = {33,3,4,5}; //declaration, instantiation and initialization
Example Of Array
class Testarray
{
public static void main(String args[]){
int a[]=new int[5];//declaration and instantiation
a[0]=10;//initialization
a[1]=20;
a[2]=70;
a[3]=40;
a[4]=50;
//printing array
for(int i=0;i<a.length;i++)//length is the property of array
System.out.println(a[i]);
}
}
Multidimensional Array in java
class Testarray3
{
public static void main(String args[]){
//declaring and initializing 2D array
int arr[][]={{1,2,3},{2,4,5},{4,4,5}};
//printing 2D array
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
System.out.print(arr[i][j]+" ");
}
System.out.println();
}
}}
Final Keyword In Java
The final keyword in java is used to restrict the user.
The java final keyword can be used in many context.
Final can be:
1. variable
2. method
3. class
final variable
class Bike9
{
final int speedlimit=90;//final variable
void run(){
speedlimit=400;
}
public static void main(String args[]){
Bike9 obj=new Bike9();
obj.run();
}
}//end of class
//compile time error generate here
final method
class Bike
{
final void run(){System.out.println("running");}
}
class Honda extends Bike{
void run(){System.out.println("running safely with 100kmph");}
public static void main(String args[]){
Honda honda= new Honda();
honda.run();
}
}
//compile time error generate here
final class in Java
final class Bike
{
}
class Honda1 extends Bike{
void run(){System.out.println("running safely with 100kmph");}
public static void main(String args[]){
Honda1 honda= new Honda();
honda.run();
}
}
// compile time error generate here
super keyword in java
The super keyword in java is a reference variable that is used to refer immediate parent class object.
Whenever you create the instance of subclass, an instance of parent class is created implicitly i.e. referred by super reference
variable.
1. super is used to refer immediate parent class instance variable.
2. super() is used to invoke immediate parent class constructor.
3. super is used to invoke immediate parent class method.
Java Copy Constructor
There is no copy constructor in java.
But, we can copy the values of one object to another like copy constructor in C++.
There are many ways to copy the values of one object into another in java. They are:
● By constructor
● By assigning the values of one object into another
● By clone() method of Object class
In this example, we are going to copy the values of one object into another using java constructor.
Wrapper class in Java
Wrapper class in java provides the mechanism to convert primitive into object and object into primitive.
Access Modifier in Java
Java Package
A java package is a group of similar types of classes, interfaces and sub-packages.
Package in java can be categorized in two form, built-in package and user-defined package.
There are many built-in packages such as java, lang, awt, javax, swing, net, io, util, sql etc.
1. Private access Modifier
class A
{
private int data=40;
private void msg()
{
System.out.println("Hello java");}
}
public class Simple
{
public static void main(String args[]){
A obj=new A();
System.out.println(obj.data);//Compile Time Error
obj.msg();//Compile Time Error
}
}
1.Role of Private Constructor
If you make any class constructor private, you cannot create the instance of that class from outside the class.
For example:
class A
{
private A(){}//private constructor
void msg(){System.out.println("Hello java");}
}
public class Simple
{
public static void main(String args[]){
A obj=new A();//Compile Time Error
}
}
2. default access modifier
If you don't use any modifier, it is treated as default by default. The default modifier is accessible only within package.
In this example, we have created two packages pack and mypack. We are accessing the A class from outside its package, since A
class is not public, so it cannot be accessed from outside the package.
package pack;
class A{
void msg(){System.out.println("Hello");}
}
In the above example, the scope of class A and its method msg() is default so it cannot be accessed from outside the package.
3. protected access modifier
The protected access modifier is accessible within package and outside the package but through inheritance only.
The protected access modifier can be applied on the data member, method and constructor. It can't be applied on the class.
In this example, we have created the two packages pack and mypack. The A class of pack package is public, so can be accessed
from outside the package.
But msg method of this package is declared as protected, so it can be accessed from outside the class only through inheritance.
4. public access modifier
The public access modifier is accessible everywhere. It has the widest scope among all other modifiers.
Java Command Line Arguments
The java command-line argument is an argument i.e. passed at the time of running the java program.
The arguments passed from the console can be received in the java program and it can be used as an input.
class A
{
public static void main(String args[])
{
for(int i=0;i<args.length;i++)
{
System.out.println(args[i]);
}
}
}
output:
compile by > javac A.java
run by > java A hello comp india
Multiple Inheritance in Java
Interface
An interface in java is a blueprint of a class.
It has static constants and abstract methods only.
The interface is a mechanism to achieve fully abstraction.
There can be only abstract methods in the java interface not method body.
It is used to achieve fully abstraction and multiple inheritance in Java.
Java Interface also represents IS-A relationship.
It cannot be instantiated just like abstract class.
Why use Java interface?
There are mainly three reasons to use interface. They are given below.
● It is used to achieve fully abstraction.
● By interface, we can support the functionality of multiple inheritance.
● It can be used to achieve loose coupling.
Relation between class and interface
interface Printable
{
void print();
}
interface Showable
{
void show();
}
class A7 implements Printable,Showable
{
public void print(){System.out.println("Hello");}
public void show(){System.out.println("Welcome");}
public static void main(String args[])
{
A7 obj = new A7();
obj.print();
obj.show();
}
}
Interface inheritance
interface Printable{
void print();
}
interface Showable extends Printable{
void show();
}
class Testinterface2 implements Showable{
public void print(){System.out.println("Hello");}
public void show(){System.out.println("Welcome");}
public static void main(String args[]){
Testinterface2 obj = new Testinterface2();
obj.print();
obj.show();
}
}
What is marker or tagged interface?
An interface that have no member is known as marker or tagged interface.
For example: Serializable, Cloneable, Remote etc.
They are used to provide some essential information to the JVM so that JVM may perform some useful operation.
Thread Life Cycle
Process & Thread
An executing instance of a program is called a process. Processes have their own address space(memory space). A process can contain multiple
threads.
Thread : Threading is a facility to allow multiple activities to coexist within a single process.
Threads are sometimes referred to as lightweight processes.
Like processes, threads are independent, concurrent paths of execution through a program, and each thread has its own stack, its own program
counter, and its own local variables.
Multithreading in java is a process of executing multiple threads simultaneously.
We use multithreading than multiprocessing because threads share a common memory area. They don't allocate separate
memory area so saves memory, and context-switching between the threads takes less time than process.
Java Multithreading is mostly used in games, animation etc.
As shown in the below figure, thread is executed inside the process. There is context-switching between the threads. There can
be multiple processes inside the OS and one process can have multiple threads.

Contenu connexe

Tendances (19)

Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructors
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 
Kotlin
KotlinKotlin
Kotlin
 
Class introduction in java
Class introduction in javaClass introduction in java
Class introduction in java
 
Constructor and Destructor in c++
Constructor  and Destructor in c++Constructor  and Destructor in c++
Constructor and Destructor in c++
 
Introduction to class in java
Introduction to class in javaIntroduction to class in java
Introduction to class in java
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
Presentation to java
Presentation  to  javaPresentation  to  java
Presentation to java
 
Classes in c++ (OOP Presentation)
Classes in c++ (OOP Presentation)Classes in c++ (OOP Presentation)
Classes in c++ (OOP Presentation)
 
Op ps
Op psOp ps
Op ps
 
Constructors destructors
Constructors destructorsConstructors destructors
Constructors destructors
 
Core java concepts
Core java  conceptsCore java  concepts
Core java concepts
 
C++ Constructor destructor
C++ Constructor destructorC++ Constructor destructor
C++ Constructor destructor
 
OOPS Basics With Example
OOPS Basics With ExampleOOPS Basics With Example
OOPS Basics With Example
 
Classes and objects1
Classes and objects1Classes and objects1
Classes and objects1
 
Java Programming - 05 access control in java
Java Programming - 05 access control in javaJava Programming - 05 access control in java
Java Programming - 05 access control in java
 
Java OOP Programming language (Part 3) - Class and Object
Java OOP Programming language (Part 3) - Class and ObjectJava OOP Programming language (Part 3) - Class and Object
Java OOP Programming language (Part 3) - Class and Object
 
Object Oriented Programming using C++ - Part 4
Object Oriented Programming using C++ - Part 4Object Oriented Programming using C++ - Part 4
Object Oriented Programming using C++ - Part 4
 
Java Programming - 03 java control flow
Java Programming - 03 java control flowJava Programming - 03 java control flow
Java Programming - 03 java control flow
 

En vedette (20)

Java lec constructors
Java lec constructorsJava lec constructors
Java lec constructors
 
Ppt on java basics1
Ppt on java basics1Ppt on java basics1
Ppt on java basics1
 
Java presentation
Java presentation Java presentation
Java presentation
 
Media evaluation question 5
Media evaluation question 5Media evaluation question 5
Media evaluation question 5
 
Overview of java web services
Overview of java web servicesOverview of java web services
Overview of java web services
 
Java for the Beginners
Java for the BeginnersJava for the Beginners
Java for the Beginners
 
Java seminar
Java seminarJava seminar
Java seminar
 
ANDROID FDP PPT
ANDROID FDP PPTANDROID FDP PPT
ANDROID FDP PPT
 
Intro to java
Intro to javaIntro to java
Intro to java
 
Ppt on java basics
Ppt on java basicsPpt on java basics
Ppt on java basics
 
Overview of Java EE 6 by Roberto Chinnici at SFJUG
Overview of Java EE 6 by Roberto Chinnici at SFJUGOverview of Java EE 6 by Roberto Chinnici at SFJUG
Overview of Java EE 6 by Roberto Chinnici at SFJUG
 
Part3
Part3Part3
Part3
 
Oop java
Oop javaOop java
Oop java
 
Presentation on java
Presentation  on  javaPresentation  on  java
Presentation on java
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
 
Java Basics for selenium
Java Basics for seleniumJava Basics for selenium
Java Basics for selenium
 
java Basic Programming Needs
java Basic Programming Needsjava Basic Programming Needs
java Basic Programming Needs
 
Exception handling
Exception handlingException handling
Exception handling
 
String handling session 5
String handling session 5String handling session 5
String handling session 5
 

Similaire à Java ppt Gandhi Ravi (gandhiri@gmail.com)

Java Programs
Java ProgramsJava Programs
Java Programsvvpadhu
 
4CS4-25-Java-Lab-Manual.pdf
4CS4-25-Java-Lab-Manual.pdf4CS4-25-Java-Lab-Manual.pdf
4CS4-25-Java-Lab-Manual.pdfamitbhachne
 
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
 
java: basics, user input, data type, constructor
java:  basics, user input, data type, constructorjava:  basics, user input, data type, constructor
java: basics, user input, data type, constructorShivam Singhal
 
Unit No 2 Objects and Classes.pptx
Unit No 2 Objects and Classes.pptxUnit No 2 Objects and Classes.pptx
Unit No 2 Objects and Classes.pptxDrYogeshDeshmukh1
 
Java basic part 2 : Datatypes Keywords Features Components Security Exceptions
Java basic part 2 : Datatypes Keywords Features Components Security Exceptions Java basic part 2 : Datatypes Keywords Features Components Security Exceptions
Java basic part 2 : Datatypes Keywords Features Components Security Exceptions Soumen Santra
 
Java programming concept
Java programming conceptJava programming concept
Java programming conceptSanjay Gunjal
 
Packages and inbuilt classes of java
Packages and inbuilt classes of javaPackages and inbuilt classes of java
Packages and inbuilt classes of javakamal kotecha
 
java_bba_21_vision academy_final.pdf
java_bba_21_vision academy_final.pdfjava_bba_21_vision academy_final.pdf
java_bba_21_vision academy_final.pdfakankshasorate1
 
Chap-2 Classes & Methods.pptx
Chap-2 Classes & Methods.pptxChap-2 Classes & Methods.pptx
Chap-2 Classes & Methods.pptxchetanpatilcp783
 
Java Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPRECJava Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPRECSreedhar Chowdam
 
Java programing language unit 1 introduction
Java programing language unit 1 introductionJava programing language unit 1 introduction
Java programing language unit 1 introductionchnrketan
 

Similaire à Java ppt Gandhi Ravi (gandhiri@gmail.com) (20)

Java Programs
Java ProgramsJava Programs
Java Programs
 
4CS4-25-Java-Lab-Manual.pdf
4CS4-25-Java-Lab-Manual.pdf4CS4-25-Java-Lab-Manual.pdf
4CS4-25-Java-Lab-Manual.pdf
 
1_JavIntro
1_JavIntro1_JavIntro
1_JavIntro
 
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: basics, user input, data type, constructor
java:  basics, user input, data type, constructorjava:  basics, user input, data type, constructor
java: basics, user input, data type, constructor
 
11.Object Oriented Programming.pdf
11.Object Oriented Programming.pdf11.Object Oriented Programming.pdf
11.Object Oriented Programming.pdf
 
Unit No 2 Objects and Classes.pptx
Unit No 2 Objects and Classes.pptxUnit No 2 Objects and Classes.pptx
Unit No 2 Objects and Classes.pptx
 
Java basic part 2 : Datatypes Keywords Features Components Security Exceptions
Java basic part 2 : Datatypes Keywords Features Components Security Exceptions Java basic part 2 : Datatypes Keywords Features Components Security Exceptions
Java basic part 2 : Datatypes Keywords Features Components Security Exceptions
 
Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
 
Core java
Core javaCore java
Core java
 
java basic .pdf
java basic .pdfjava basic .pdf
java basic .pdf
 
Java programming concept
Java programming conceptJava programming concept
Java programming concept
 
Packages and inbuilt classes of java
Packages and inbuilt classes of javaPackages and inbuilt classes of java
Packages and inbuilt classes of java
 
java_bba_21_vision academy_final.pdf
java_bba_21_vision academy_final.pdfjava_bba_21_vision academy_final.pdf
java_bba_21_vision academy_final.pdf
 
Chap-2 Classes & Methods.pptx
Chap-2 Classes & Methods.pptxChap-2 Classes & Methods.pptx
Chap-2 Classes & Methods.pptx
 
Java bcs 21_vision academy_final
Java bcs 21_vision academy_finalJava bcs 21_vision academy_final
Java bcs 21_vision academy_final
 
Java Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPRECJava Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPREC
 
Java Notes
Java Notes Java Notes
Java Notes
 
Java programing language unit 1 introduction
Java programing language unit 1 introductionJava programing language unit 1 introduction
Java programing language unit 1 introduction
 
Java For Automation
Java   For AutomationJava   For Automation
Java For Automation
 

Dernier

Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxUmeshTimilsina1
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 

Dernier (20)

Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 

Java ppt Gandhi Ravi (gandhiri@gmail.com)

  • 2. Introduction of Java Java is a programming language and a platform. Java is a high level, robust, secured and object-oriented programming language. Platform: Any hardware or software environment in which a program runs, is known as a platform. Java has its own runtime environment (JRE) and API, it is called platform.
  • 4. How to compile and execute java file
  • 5. What happens at compile time? At compile time, java file is compiled by Java Compiler (It does not interact with OS) and converts the java code into bytecode.
  • 6. Jdk : Java Development kit
  • 7. JRE- Java Runtime Environment
  • 8. JVM- Java Virtual Machine The JVM performs following main tasks: 1. Loads code 2. Verifies code 3. Executes code 4. Provides runtime environment
  • 9. Application of Java Desktop Applications, media player, antivirus etc. Web Applications such as irctc.co.in, Enterprise Applications such as banking Mobile Embedded System Smart Card Robotics Games etc.
  • 10. Types of Java Applications There are mainly 4 type of applications 1) Standalone Application 2) Web Application 3) Enterprise Application 4) Mobile Application
  • 11. Features of Java ❖ Simple ❖ Object-Oriented ❖ Platform independent ❖ Secured ❖ Robust ❖ Architecture neutral ❖ Portable ❖ Dynamic ❖ Interpreted ❖ Multithreaded ❖ Distributed
  • 12. Variable in Java Variable is name of reserved area allocated in memory. int my =50;//Here my is variable There are three types of variables in java 1) local variable: A variable that is declared inside the method is called local variable. 2) instance variable:A variable that is declared inside the class but outside the method is called instance variable . It is not declared as static. 3) static variable:A variable that is declared as static is called static variable. It cannot be local. class A { int data=50;//instance variable static int m=100;//static variable void method(){ int n=90;//local variable } }//end of class
  • 14. Data Type - Default Value and size
  • 15. Operator in Java A - Arithmetic Operator + - * / % R - Relational Operator < <= > >= == != I - Increment/Decrement Operator ++ -- L - Logical Operator && || ! A - Assignment Operator c=a+b C - Conditional Operator max= (a>b)?a:b; B - Bitwise Logical Operator S- Special operator . dot operator
  • 17. Constructor in Java Constructor in java is a special type of method that is used to initialize the object. Java constructor is invoked at the time of object creation. It constructs the values i.e. provides data for the object that is why it is known as constructor. Rules for creating java constructor There are basically two rules defined for the constructor. 1. Constructor name must be same as its class name 2. Constructor must have no explicit return type Types of java constructors There are two types of constructors: 1. Default constructor (no-arg constructor) 2. Parameterized constructor
  • 18. Default Constructor Rule: If there is no constructor in a class, compiler automatically creates a default constructor.
  • 19. Difference Between Method & Constructor Q) Does constructor return any value? Ans:yes, that is current class instance (You cannot use return type yet it returns a value).
  • 20. static Keyword in Java The static keyword in java is used for memory management mainly. We can apply java static keyword with variables, methods, blocks and nested class. The static keyword belongs to the class than instance of the class. The static can be: 1. variable (also known as class variable) 2. method (also known as class method) 3. block Java static method If you apply static keyword with any method, it is known as static method. ● A static method belongs to the class rather than object of a class. ● A static method can be invoked without the need for creating an instance of a class. ● static method can access static data member and can change the value of it.
  • 21. Static Method in java //Program to get cube of a given number by static method class Calculate{ static int cube(int x){ return x*x*x; } public static void main(String args[]) { int result=Calculate.cube(5); System.out.println(result); } } There are two Restriction for static method in java 1. The static method can not use non static data member or call non-static method directly. 2. this and super cannot be used in static context.
  • 22. why java main method is static? Because object is not required to call static method if it were non-static method, jvm create object first then call main() method that will lead the problem of extra memory allocation. class My { Static { System.out.println("static block work"); } public static void main(String args[]){ System.out.println("Hello Compindia Technologies"); } } Output: Static block here Hello compindia technologies
  • 23. Inheritance in Java Inheritance in java is a mechanism in which one object acquires all the properties and behaviors of parent object. Why use inheritance in java ● For Method Overriding (so runtime polymorphism can be achieved). ● For Code Reusability. Syntax of Java Inheritance class Subclass-name extends Superclass-name { //methods and fields } The extends keyword indicates that you are making a new class that derives from an existing class. In the terminology of Java, a class that is inherited is called a super class. The new class is called a subclass.
  • 24. Types of inheritance in Java There can be three types of inheritance in java: single, multilevel and hierarchical. In java programming, multiple and hybrid inheritance is supported through interface only. We will learn about interfaces later. Note: Multiple inheritance is not supported in java through class.
  • 26. Why multiple inheritance is not supported in java? class A{ void msg(){System.out.println("Hello");} } class B{ void msg(){System.out.println("Welcome");} } class C extends A,B{//suppose if it were Public Static void main(String args[]){ C obj=new C(); obj.msg();//Now which msg() method would be invoked? } } //compile time error
  • 27. Real example of Java Method Overriding class Bank{ int getRateOfInterest(){ return 0;} } class SBI extends Bank{ int getRateOfInterest(){ return 8;} } class ICICI extends Bank{ int getRateOfInterest(){ return 7;} } class AXIS extends Bank{ int getRateOfInterest(){ return 9;} } class Test2{ public static void main(String args[]){ SBI s=new SBI(); ICICI i=new ICICI(); AXIS a=new AXIS(); System.out.println("SBI Rate of Interest: "+s.getRateOfInterest()); System.out.println("ICICI Rate of Interest: "+i.getRateOfInterest()); System.out.println("AXIS Rate of Interest: "+a.getRateOfInterest()); } } Output: SBI Rate of Interest: 8 ICICI Rate of Interest: 7 AXIS Rate of Interest: 9
  • 28. Method Overloading VS Method Overriding
  • 29. Java Array Normally, array is a collection of similar type of elements that have contiguous memory location. Java array is an object the contains elements of similar data type. It is a data structure where we store similar elements. We can store only fixed set of elements in a java array. Array in java is index based, first element of the array is stored at 0 index. Advantage of Java Array ● Code Optimization: It makes the code optimized, we can retrieve or sort the data easily. ● Random access: We can get any data located at any index position.
  • 30. Types of Array in java There are two types of array. ● Single Dimensional Array ● Multidimensional Array Declare an Array in java dataType[] arr; (or) dataType []arr; (or) dataType arr[]; Instantiation of an Array in java arr =new datatype[size]; Declaration, Instantiation and Initialization of Java Array int a[] = {33,3,4,5}; //declaration, instantiation and initialization
  • 31. Example Of Array class Testarray { public static void main(String args[]){ int a[]=new int[5];//declaration and instantiation a[0]=10;//initialization a[1]=20; a[2]=70; a[3]=40; a[4]=50; //printing array for(int i=0;i<a.length;i++)//length is the property of array System.out.println(a[i]); } }
  • 32. Multidimensional Array in java class Testarray3 { public static void main(String args[]){ //declaring and initializing 2D array int arr[][]={{1,2,3},{2,4,5},{4,4,5}}; //printing 2D array for(int i=0;i<3;i++){ for(int j=0;j<3;j++){ System.out.print(arr[i][j]+" "); } System.out.println(); } }}
  • 33. Final Keyword In Java The final keyword in java is used to restrict the user. The java final keyword can be used in many context. Final can be: 1. variable 2. method 3. class
  • 34. final variable class Bike9 { final int speedlimit=90;//final variable void run(){ speedlimit=400; } public static void main(String args[]){ Bike9 obj=new Bike9(); obj.run(); } }//end of class //compile time error generate here
  • 35. final method class Bike { final void run(){System.out.println("running");} } class Honda extends Bike{ void run(){System.out.println("running safely with 100kmph");} public static void main(String args[]){ Honda honda= new Honda(); honda.run(); } } //compile time error generate here
  • 36. final class in Java final class Bike { } class Honda1 extends Bike{ void run(){System.out.println("running safely with 100kmph");} public static void main(String args[]){ Honda1 honda= new Honda(); honda.run(); } } // compile time error generate here
  • 37. super keyword in java The super keyword in java is a reference variable that is used to refer immediate parent class object. Whenever you create the instance of subclass, an instance of parent class is created implicitly i.e. referred by super reference variable. 1. super is used to refer immediate parent class instance variable. 2. super() is used to invoke immediate parent class constructor. 3. super is used to invoke immediate parent class method.
  • 38. Java Copy Constructor There is no copy constructor in java. But, we can copy the values of one object to another like copy constructor in C++. There are many ways to copy the values of one object into another in java. They are: ● By constructor ● By assigning the values of one object into another ● By clone() method of Object class In this example, we are going to copy the values of one object into another using java constructor.
  • 39. Wrapper class in Java Wrapper class in java provides the mechanism to convert primitive into object and object into primitive.
  • 41. Java Package A java package is a group of similar types of classes, interfaces and sub-packages. Package in java can be categorized in two form, built-in package and user-defined package. There are many built-in packages such as java, lang, awt, javax, swing, net, io, util, sql etc.
  • 42.
  • 43. 1. Private access Modifier class A { private int data=40; private void msg() { System.out.println("Hello java");} } public class Simple { public static void main(String args[]){ A obj=new A(); System.out.println(obj.data);//Compile Time Error obj.msg();//Compile Time Error } }
  • 44. 1.Role of Private Constructor If you make any class constructor private, you cannot create the instance of that class from outside the class. For example: class A { private A(){}//private constructor void msg(){System.out.println("Hello java");} } public class Simple { public static void main(String args[]){ A obj=new A();//Compile Time Error } }
  • 45. 2. default access modifier If you don't use any modifier, it is treated as default by default. The default modifier is accessible only within package. In this example, we have created two packages pack and mypack. We are accessing the A class from outside its package, since A class is not public, so it cannot be accessed from outside the package. package pack; class A{ void msg(){System.out.println("Hello");} } In the above example, the scope of class A and its method msg() is default so it cannot be accessed from outside the package.
  • 46. 3. protected access modifier The protected access modifier is accessible within package and outside the package but through inheritance only. The protected access modifier can be applied on the data member, method and constructor. It can't be applied on the class. In this example, we have created the two packages pack and mypack. The A class of pack package is public, so can be accessed from outside the package. But msg method of this package is declared as protected, so it can be accessed from outside the class only through inheritance.
  • 47. 4. public access modifier The public access modifier is accessible everywhere. It has the widest scope among all other modifiers.
  • 48. Java Command Line Arguments The java command-line argument is an argument i.e. passed at the time of running the java program. The arguments passed from the console can be received in the java program and it can be used as an input. class A { public static void main(String args[]) { for(int i=0;i<args.length;i++) { System.out.println(args[i]); } } } output: compile by > javac A.java run by > java A hello comp india
  • 50. Interface An interface in java is a blueprint of a class. It has static constants and abstract methods only. The interface is a mechanism to achieve fully abstraction. There can be only abstract methods in the java interface not method body. It is used to achieve fully abstraction and multiple inheritance in Java. Java Interface also represents IS-A relationship. It cannot be instantiated just like abstract class.
  • 51. Why use Java interface? There are mainly three reasons to use interface. They are given below. ● It is used to achieve fully abstraction. ● By interface, we can support the functionality of multiple inheritance. ● It can be used to achieve loose coupling.
  • 52. Relation between class and interface
  • 53. interface Printable { void print(); } interface Showable { void show(); } class A7 implements Printable,Showable { public void print(){System.out.println("Hello");} public void show(){System.out.println("Welcome");} public static void main(String args[]) { A7 obj = new A7(); obj.print(); obj.show(); } }
  • 54. Interface inheritance interface Printable{ void print(); } interface Showable extends Printable{ void show(); } class Testinterface2 implements Showable{ public void print(){System.out.println("Hello");} public void show(){System.out.println("Welcome");} public static void main(String args[]){ Testinterface2 obj = new Testinterface2(); obj.print(); obj.show(); } }
  • 55. What is marker or tagged interface? An interface that have no member is known as marker or tagged interface. For example: Serializable, Cloneable, Remote etc. They are used to provide some essential information to the JVM so that JVM may perform some useful operation.
  • 57. Process & Thread An executing instance of a program is called a process. Processes have their own address space(memory space). A process can contain multiple threads. Thread : Threading is a facility to allow multiple activities to coexist within a single process. Threads are sometimes referred to as lightweight processes. Like processes, threads are independent, concurrent paths of execution through a program, and each thread has its own stack, its own program counter, and its own local variables. Multithreading in java is a process of executing multiple threads simultaneously. We use multithreading than multiprocessing because threads share a common memory area. They don't allocate separate memory area so saves memory, and context-switching between the threads takes less time than process. Java Multithreading is mostly used in games, animation etc.
  • 58. As shown in the below figure, thread is executed inside the process. There is context-switching between the threads. There can be multiple processes inside the OS and one process can have multiple threads.