SlideShare une entreprise Scribd logo
1  sur  25
Télécharger pour lire hors ligne
Introduction to Java
Lecture 5
Naveen Kumar
 Development tools-part of java development kit (JDK)
 Classes and methods-part of Java Standard Library (JSL),
also known as Application Programming Interface (API)
1. JDK:
 Appletviewer ( for viewing applets)
 Javac (Compiler)
 Java (Interpreter)
 Javah (for C header files)
 Javadoc ( for creating HTML description)
Java Environment
2. Application Package Interface (API)
Contains hundreds of classes and methods grouped into several
functional packages:
 Language Support Package (String, Integer, Double, etc)
 Utility Packages (rand. num. gen., sys. date)
 Input/Output Packages
 Networking Packages (implementing networking appl. )
 AWT Package (classes for painting graphics and images)
 Applet Package (web page using java)
Java Environment
1. Java 1.0 (96)
2. Java 1.1 (97)(Add new library, redefine applet handling and
reconfigured many features.)
3. Java 2 (98)(Second generation). Version no:1.2 (Internal
version number of java library). Also known as J2SE [ Java
2 Platform Standard Edition].
- Add swing, the collection framework, enhanced JVM etc.
4. J2SE 1.3 (2000)
5. J2SE 1.4 (2002)
6. J2SE 1.5 (2004)
7. J2SE 1.6 (2006) [1.7-(2013), in queue 1.8 (exp in 2014) ]
The Evolution of Java
Comments
In Java, comments are preceded by two slashes (//) in a
line, or
enclosed between /* and */ in one or multiple lines
When the compiler sees //, it ignores all text after // in the
same line
When it sees /*, it scans for the next */ and ignores any text
between /* and */
Example
/* Traditional "Hello World!" program. */
// package pack1;
// import java.lang.System;
class A
{
public static void main (String args[])
{
System.out.println("Hello World!");
}
}
Save program as A.java
Java Program Structure
Package Statement
 Javac command compiles the source code A.java then,
generates A.class and store it under a directory which is
called as name of the package
 package statement if used must be the first statement in
a compilation unit. Its syntax is:
package packageName;
 For example:
package pack1;
Import Statement
 The import statements are similar to #include
statements in C and C++
 In the above program, System class of java.lang package
is imported into all Java programs by default. The
syntax of import statement is as:
import fullClassName;
 For example, the following import statement imports the
System class from java.lang:
import java.lang.System;
import java.lang.*;
Classes and Methods
 Class declarations contain a keyword class and an identifier (Ex: A)
 Class members are enclosed within braces. The syntax of defining a
class is shown below:
class A
{
// program code
}
 To execute a class, it must contain a valid main method
 It is the first method that automatically gets invoked when the program
executed
public static void main (String args[])
{
//instructions
}
Main method
public static void main (String args[])
{
//instructions
}
 The main method must always be defined as public:
to make it publicly accessible,
 static: to declare it as a class member and
 void: returns no value
 args[]: parameter, is an array of class String. It
provides access to command line parameters
System class
System.out.println("Hello World!");
 invokes println method on object
named out variable (of type
java.io.PrintStream), which is a member
of System class.
 The println method takes a String
parameter and displays it on the console
Example
/* Traditional "Hello World!" program. */
// package pack1;
// import java.lang.System;
class A
{
public static void main (String args[])
{
System.out.println("Hello World!");
}
}
Class definition
class A
{
int i;
char ch;
void set()
{…}
int get(int b)
{…}
}
Method Declarations
 General format of method declaration:
Modifier return-type method-name( parameter1, …, parameterN )
{
body (declarations and statements);
}
 Modifiers—such as public, private, and others you will learn later.
 return type—the data type of the value returned by the method, or void if
the method does not return a value.
 Method body can also return values:
return expression;
Access members of a class
Class A
{
int i;
char ch;
void set()
{ i=20; }
int get()
{return i; }
}
stack Heap
i
ch
A
How to access member of class A ?
A a= new A();
a.i;
a.ch;
a.set();
Types of Methods (4 basic types )
– Modifier (sometimes called a mutator)
 Changes the value associated with an attribute of the object
 E.g. A method like set()
– Accessor
 Returns the value associated with an attribute of the object
 E.g. A method like Get()
– Constructor
 Called once when the object is created (before any other
method will be invoked)
 E.g. A(int i)
– Destructor
 Called when the object is destroyed
 E.g.~A( )
Constructor
 Same name as class name
 No return type (as methods)
Why we need constructors?
 Initialize an object
Default cons (if we not defined)
– No parameter
– Ex: A()
{
}
Parameterized constructor
A(int in) A(int in, char c)
{ {
i=in; i=in;
} ch=c;
}
 Created when object init
 Can define any number of constructors
Example 2: two classes
class aa2
{
int i;
char ch;
void set()
{ i=20;}
int get()
{return i;}
}
19
public class aa4
{
public static void main(String args[])
{
aa2 obj= new aa2();
int b;
obj.set();
b= obj.get();
System.out.println("i="+ obj.i);
System.out.println("i="+ b);
}
}
Example 3: two classes uses cons.
class aa2
{
int i;
char ch;
void set()
{ i=20;}
int get()
{return i;}
aa2 (int in, char c)
{
i=in; ch=c;
}
}20
public class aa4
{
public static void main(String args[])
{
aa2 obj= new aa2(20,‘g’);
System.out.println("i="+ obj.i);
System.out.println("i="+ obj.ch);
}
}
Example 4: single class
public class aa1
{
int i;
char ch;
void set()
{ i=20;}
int get()
{return i;}
21
public static void main(String args[])
{
aa1 a= new aa1();
int b;
a.set();
b=a.get();
System.out.println("i="+ a.i);
System.out.println("i="+ b);
}
}
Introduction to Applets
 Java applet is a small appln. written in Java
 delivered to users in the form of bytecode
 user can launches Java applet from a web page
 it can appear in a frame of the web page, in a
new application window, or in Sun's
AppletViewer, a stand-alone tool for testing
applets
22
Applet Example 1
/*
<APPLET CODE="app1.class" WIDTH=150 HEIGHT=100>
</APPLET>
*/
import java.applet.Applet;
import java.awt.Graphics;
public class app1 extends Applet {
public void paint (Graphics g) {
g.drawString("Hello!",50,20);
} }
23
Applet program execution
Compile
javac app1.java
Execution
appletviewer app1.java
24
Execution through HTML file
<HTML>
<HEAD>
<TITLE> A simple Program</TITLE>
</HEAD>
<BODY> Here is the output:
<APPLET CODE="app1.class" WIDTH=150 HEIGHT=100>
</APPLET>
<BODY>
</HTML>
Store with name app1.htm
Execute from browser: C:javaapp1.htm25

Contenu connexe

Tendances

Presentation on class and object in Object Oriented programming.
Presentation on class and object in Object Oriented programming.Presentation on class and object in Object Oriented programming.
Presentation on class and object in Object Oriented programming.Enam Khan
 
Inheritance chepter 7
Inheritance chepter 7Inheritance chepter 7
Inheritance chepter 7kamal kotecha
 
Lecture 6 inheritance
Lecture   6 inheritanceLecture   6 inheritance
Lecture 6 inheritancemanish kumar
 
+2 CS class and objects
+2 CS class and objects+2 CS class and objects
+2 CS class and objectskhaliledapal
 
Lecture - 3 Variables-data type_operators_oops concept
Lecture - 3 Variables-data type_operators_oops conceptLecture - 3 Variables-data type_operators_oops concept
Lecture - 3 Variables-data type_operators_oops conceptmanish kumar
 
C# Variables and Operators
C# Variables and OperatorsC# Variables and Operators
C# Variables and OperatorsSunil OS
 
Lecture 4_Java Method-constructor_imp_keywords
Lecture   4_Java Method-constructor_imp_keywordsLecture   4_Java Method-constructor_imp_keywords
Lecture 4_Java Method-constructor_imp_keywordsmanish kumar
 

Tendances (20)

Presentation on class and object in Object Oriented programming.
Presentation on class and object in Object Oriented programming.Presentation on class and object in Object Oriented programming.
Presentation on class and object in Object Oriented programming.
 
Inheritance chepter 7
Inheritance chepter 7Inheritance chepter 7
Inheritance chepter 7
 
Java interface
Java interfaceJava interface
Java interface
 
Lecture 9
Lecture 9Lecture 9
Lecture 9
 
Java interface
Java interfaceJava interface
Java interface
 
Java Notes
Java Notes Java Notes
Java Notes
 
Lecture 6 inheritance
Lecture   6 inheritanceLecture   6 inheritance
Lecture 6 inheritance
 
Ppt chapter12
Ppt chapter12Ppt chapter12
Ppt chapter12
 
Java Programming Assignment
Java Programming AssignmentJava Programming Assignment
Java Programming Assignment
 
Unit 4 Java
Unit 4 JavaUnit 4 Java
Unit 4 Java
 
+2 CS class and objects
+2 CS class and objects+2 CS class and objects
+2 CS class and objects
 
Unit 5 java-awt (1)
Unit 5 java-awt (1)Unit 5 java-awt (1)
Unit 5 java-awt (1)
 
Lecture - 3 Variables-data type_operators_oops concept
Lecture - 3 Variables-data type_operators_oops conceptLecture - 3 Variables-data type_operators_oops concept
Lecture - 3 Variables-data type_operators_oops concept
 
C# Variables and Operators
C# Variables and OperatorsC# Variables and Operators
C# Variables and Operators
 
Oop objects_classes
Oop objects_classesOop objects_classes
Oop objects_classes
 
Ppt chapter03
Ppt chapter03Ppt chapter03
Ppt chapter03
 
Java cheat sheet
Java cheat sheet Java cheat sheet
Java cheat sheet
 
Unit3 part1-class
Unit3 part1-classUnit3 part1-class
Unit3 part1-class
 
Lecture 4_Java Method-constructor_imp_keywords
Lecture   4_Java Method-constructor_imp_keywordsLecture   4_Java Method-constructor_imp_keywords
Lecture 4_Java Method-constructor_imp_keywords
 
Ppt chapter02
Ppt chapter02Ppt chapter02
Ppt chapter02
 

Similaire à Lec 5 13_aug [compatibility mode]

Java Programs
Java ProgramsJava Programs
Java Programsvvpadhu
 
Object Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsObject Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsMuhammadTalha436
 
New features and enhancement
New features and enhancementNew features and enhancement
New features and enhancementRakesh Madugula
 
Java Generics
Java GenericsJava Generics
Java Genericsjeslie
 
21UCAC31 Java Programming.pdf(MTNC)(BCA)
21UCAC31 Java Programming.pdf(MTNC)(BCA)21UCAC31 Java Programming.pdf(MTNC)(BCA)
21UCAC31 Java Programming.pdf(MTNC)(BCA)ssuser7f90ae
 
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 ppt Gandhi Ravi (gandhiri@gmail.com)
Java ppt  Gandhi Ravi  (gandhiri@gmail.com)Java ppt  Gandhi Ravi  (gandhiri@gmail.com)
Java ppt Gandhi Ravi (gandhiri@gmail.com)Gandhi Ravi
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.Tarunsingh198
 
Chap-2 Classes & Methods.pptx
Chap-2 Classes & Methods.pptxChap-2 Classes & Methods.pptx
Chap-2 Classes & Methods.pptxchetanpatilcp783
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaCPD INDIA
 
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
 
Fundamentals of oop lecture 2
Fundamentals of oop lecture 2Fundamentals of oop lecture 2
Fundamentals of oop lecture 2miiro30
 

Similaire à Lec 5 13_aug [compatibility mode] (20)

Java Programs
Java ProgramsJava Programs
Java Programs
 
Object Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsObject Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ Exams
 
New features and enhancement
New features and enhancementNew features and enhancement
New features and enhancement
 
Packages and interfaces
Packages and interfacesPackages and interfaces
Packages and interfaces
 
Java Generics
Java GenericsJava Generics
Java Generics
 
21UCAC31 Java Programming.pdf(MTNC)(BCA)
21UCAC31 Java Programming.pdf(MTNC)(BCA)21UCAC31 Java Programming.pdf(MTNC)(BCA)
21UCAC31 Java Programming.pdf(MTNC)(BCA)
 
Java 5 and 6 New Features
Java 5 and 6 New FeaturesJava 5 and 6 New Features
Java 5 and 6 New Features
 
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 ppt
Java pptJava ppt
Java ppt
 
Java ppt Gandhi Ravi (gandhiri@gmail.com)
Java ppt  Gandhi Ravi  (gandhiri@gmail.com)Java ppt  Gandhi Ravi  (gandhiri@gmail.com)
Java ppt Gandhi Ravi (gandhiri@gmail.com)
 
Package.pptx
Package.pptxPackage.pptx
Package.pptx
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.
 
Chap-2 Classes & Methods.pptx
Chap-2 Classes & Methods.pptxChap-2 Classes & Methods.pptx
Chap-2 Classes & Methods.pptx
 
OOPs & Inheritance Notes
OOPs & Inheritance NotesOOPs & Inheritance Notes
OOPs & Inheritance Notes
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
 
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
 
Fundamentals of oop lecture 2
Fundamentals of oop lecture 2Fundamentals of oop lecture 2
Fundamentals of oop lecture 2
 
Java and j2ee_lab-manual
Java and j2ee_lab-manualJava and j2ee_lab-manual
Java and j2ee_lab-manual
 
Core java Essentials
Core java EssentialsCore java Essentials
Core java Essentials
 
Python for Beginners
Python  for BeginnersPython  for Beginners
Python for Beginners
 

Plus de Palak Sanghani

Plus de Palak Sanghani (20)

Survey form
Survey formSurvey form
Survey form
 
Survey
SurveySurvey
Survey
 
Nature2
Nature2Nature2
Nature2
 
Texture
TextureTexture
Texture
 
Lec 11 12_sept [compatibility mode]
Lec 11 12_sept [compatibility mode]Lec 11 12_sept [compatibility mode]
Lec 11 12_sept [compatibility mode]
 
Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]
 
Lec 8 03_sept [compatibility mode]
Lec 8 03_sept [compatibility mode]Lec 8 03_sept [compatibility mode]
Lec 8 03_sept [compatibility mode]
 
Lec 7 28_aug [compatibility mode]
Lec 7 28_aug [compatibility mode]Lec 7 28_aug [compatibility mode]
Lec 7 28_aug [compatibility mode]
 
Lec 10 10_sept [compatibility mode]
Lec 10 10_sept [compatibility mode]Lec 10 10_sept [compatibility mode]
Lec 10 10_sept [compatibility mode]
 
Lec 6 14_aug [compatibility mode]
Lec 6 14_aug [compatibility mode]Lec 6 14_aug [compatibility mode]
Lec 6 14_aug [compatibility mode]
 
Lec 4 06_aug [compatibility mode]
Lec 4 06_aug [compatibility mode]Lec 4 06_aug [compatibility mode]
Lec 4 06_aug [compatibility mode]
 
Lec 3 01_aug13
Lec 3 01_aug13Lec 3 01_aug13
Lec 3 01_aug13
 
Lec 2 30_jul13
Lec 2 30_jul13Lec 2 30_jul13
Lec 2 30_jul13
 
Lec 1 25_jul13
Lec 1 25_jul13Lec 1 25_jul13
Lec 1 25_jul13
 
Nature
NatureNature
Nature
 
Comparisionof trees
Comparisionof treesComparisionof trees
Comparisionof trees
 
My Structure Patterns
My Structure PatternsMy Structure Patterns
My Structure Patterns
 
My Similarity Patterns
My Similarity PatternsMy Similarity Patterns
My Similarity Patterns
 
My Radiation Patterns
My Radiation PatternsMy Radiation Patterns
My Radiation Patterns
 
My Gradation Patterns
My Gradation PatternsMy Gradation Patterns
My Gradation Patterns
 

Dernier

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 

Dernier (20)

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 

Lec 5 13_aug [compatibility mode]

  • 2.  Development tools-part of java development kit (JDK)  Classes and methods-part of Java Standard Library (JSL), also known as Application Programming Interface (API) 1. JDK:  Appletviewer ( for viewing applets)  Javac (Compiler)  Java (Interpreter)  Javah (for C header files)  Javadoc ( for creating HTML description) Java Environment
  • 3. 2. Application Package Interface (API) Contains hundreds of classes and methods grouped into several functional packages:  Language Support Package (String, Integer, Double, etc)  Utility Packages (rand. num. gen., sys. date)  Input/Output Packages  Networking Packages (implementing networking appl. )  AWT Package (classes for painting graphics and images)  Applet Package (web page using java) Java Environment
  • 4. 1. Java 1.0 (96) 2. Java 1.1 (97)(Add new library, redefine applet handling and reconfigured many features.) 3. Java 2 (98)(Second generation). Version no:1.2 (Internal version number of java library). Also known as J2SE [ Java 2 Platform Standard Edition]. - Add swing, the collection framework, enhanced JVM etc. 4. J2SE 1.3 (2000) 5. J2SE 1.4 (2002) 6. J2SE 1.5 (2004) 7. J2SE 1.6 (2006) [1.7-(2013), in queue 1.8 (exp in 2014) ] The Evolution of Java
  • 5. Comments In Java, comments are preceded by two slashes (//) in a line, or enclosed between /* and */ in one or multiple lines When the compiler sees //, it ignores all text after // in the same line When it sees /*, it scans for the next */ and ignores any text between /* and */
  • 6. Example /* Traditional "Hello World!" program. */ // package pack1; // import java.lang.System; class A { public static void main (String args[]) { System.out.println("Hello World!"); } } Save program as A.java
  • 7. Java Program Structure Package Statement  Javac command compiles the source code A.java then, generates A.class and store it under a directory which is called as name of the package  package statement if used must be the first statement in a compilation unit. Its syntax is: package packageName;  For example: package pack1;
  • 8. Import Statement  The import statements are similar to #include statements in C and C++  In the above program, System class of java.lang package is imported into all Java programs by default. The syntax of import statement is as: import fullClassName;  For example, the following import statement imports the System class from java.lang: import java.lang.System; import java.lang.*;
  • 9. Classes and Methods  Class declarations contain a keyword class and an identifier (Ex: A)  Class members are enclosed within braces. The syntax of defining a class is shown below: class A { // program code }  To execute a class, it must contain a valid main method  It is the first method that automatically gets invoked when the program executed public static void main (String args[]) { //instructions }
  • 10. Main method public static void main (String args[]) { //instructions }  The main method must always be defined as public: to make it publicly accessible,  static: to declare it as a class member and  void: returns no value  args[]: parameter, is an array of class String. It provides access to command line parameters
  • 11. System class System.out.println("Hello World!");  invokes println method on object named out variable (of type java.io.PrintStream), which is a member of System class.  The println method takes a String parameter and displays it on the console
  • 12. Example /* Traditional "Hello World!" program. */ // package pack1; // import java.lang.System; class A { public static void main (String args[]) { System.out.println("Hello World!"); } }
  • 13. Class definition class A { int i; char ch; void set() {…} int get(int b) {…} }
  • 14. Method Declarations  General format of method declaration: Modifier return-type method-name( parameter1, …, parameterN ) { body (declarations and statements); }  Modifiers—such as public, private, and others you will learn later.  return type—the data type of the value returned by the method, or void if the method does not return a value.  Method body can also return values: return expression;
  • 15. Access members of a class Class A { int i; char ch; void set() { i=20; } int get() {return i; } } stack Heap i ch A How to access member of class A ? A a= new A(); a.i; a.ch; a.set();
  • 16. Types of Methods (4 basic types ) – Modifier (sometimes called a mutator)  Changes the value associated with an attribute of the object  E.g. A method like set() – Accessor  Returns the value associated with an attribute of the object  E.g. A method like Get() – Constructor  Called once when the object is created (before any other method will be invoked)  E.g. A(int i) – Destructor  Called when the object is destroyed  E.g.~A( )
  • 17. Constructor  Same name as class name  No return type (as methods) Why we need constructors?  Initialize an object Default cons (if we not defined) – No parameter – Ex: A() { }
  • 18. Parameterized constructor A(int in) A(int in, char c) { { i=in; i=in; } ch=c; }  Created when object init  Can define any number of constructors
  • 19. Example 2: two classes class aa2 { int i; char ch; void set() { i=20;} int get() {return i;} } 19 public class aa4 { public static void main(String args[]) { aa2 obj= new aa2(); int b; obj.set(); b= obj.get(); System.out.println("i="+ obj.i); System.out.println("i="+ b); } }
  • 20. Example 3: two classes uses cons. class aa2 { int i; char ch; void set() { i=20;} int get() {return i;} aa2 (int in, char c) { i=in; ch=c; } }20 public class aa4 { public static void main(String args[]) { aa2 obj= new aa2(20,‘g’); System.out.println("i="+ obj.i); System.out.println("i="+ obj.ch); } }
  • 21. Example 4: single class public class aa1 { int i; char ch; void set() { i=20;} int get() {return i;} 21 public static void main(String args[]) { aa1 a= new aa1(); int b; a.set(); b=a.get(); System.out.println("i="+ a.i); System.out.println("i="+ b); } }
  • 22. Introduction to Applets  Java applet is a small appln. written in Java  delivered to users in the form of bytecode  user can launches Java applet from a web page  it can appear in a frame of the web page, in a new application window, or in Sun's AppletViewer, a stand-alone tool for testing applets 22
  • 23. Applet Example 1 /* <APPLET CODE="app1.class" WIDTH=150 HEIGHT=100> </APPLET> */ import java.applet.Applet; import java.awt.Graphics; public class app1 extends Applet { public void paint (Graphics g) { g.drawString("Hello!",50,20); } } 23
  • 24. Applet program execution Compile javac app1.java Execution appletviewer app1.java 24
  • 25. Execution through HTML file <HTML> <HEAD> <TITLE> A simple Program</TITLE> </HEAD> <BODY> Here is the output: <APPLET CODE="app1.class" WIDTH=150 HEIGHT=100> </APPLET> <BODY> </HTML> Store with name app1.htm Execute from browser: C:javaapp1.htm25