SlideShare ist ein Scribd-Unternehmen logo
1 von 25
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von Palak Sanghani

Mehr von 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
 

Kürzlich hochgeladen

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
🐬 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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
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
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
[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
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
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
 
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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 

Kürzlich hochgeladen (20)

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
[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
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
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
 
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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

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