SlideShare una empresa de Scribd logo
1 de 20
DESCRIBING JAVA API
PACKAGES
Chapter 2.2:
Java Application Programming
Interface (API)
 The Java Application Programming Interface (API)
is prewritten code (predefined classes), organized
into packages of similar topics. For instance, the
Applet and AWT packages include classes for
creating fonts, menus, and buttons.
 There are 3 editions of the Java API:
 Java 2 Standard Edition (J2SE) : to develop client-
side standalone applications or applets.
 Java 2 Enterprise Edition (J2EE) : to develop server-
side applications. E.g. Java servlets and JSP.
 Java 2 Micro Edition (J2ME) : to develop
applications for mobile devices.
Characters String
 A string literal is represented by putting
double quotes around the text
 Examples:
"This is a string literal."
"123 Main Street"
"X"
 Every character string is an object in Java,
defined by the String class
 Every string literal represents a String
object
The println() Method
 The System.out object represents a destination
(the monitor screen) to which we can send output
System.out.println ("Whatever you are, be a good one.");
object method
name information provided to the method
(parameters)
The print() Method
 The System.out object provides another service
as well
 The print method is similar to the println
method, except that it does not advance to the
next line
 Therefore anything printed after a print
statement will appear on the same line
 See Countdown.java
Goals
//********************************************************************
// Countdown.java Author: Lewis/Loftus
//
// Demonstrates the difference between print and println.
//********************************************************************
public class Countdown
{
//-----------------------------------------------------------------
// Prints two lines of output representing a rocket countdown.
//-----------------------------------------------------------------
public static void main (String[] args)
{
System.out.print ("Three... ");
System.out.print ("Two... ");
System.out.print ("One... ");
System.out.print ("Zero... ");
System.out.println ("Liftoff!"); // appears on first output line
System.out.println ("Houston, we have a problem.");
}
}
Goals
//********************************************************************
// Countdown.java Author: Lewis/Loftus
//
// Demonstrates the difference between print and println.
//********************************************************************
public class Countdown
{
//-----------------------------------------------------------------
// Prints two lines of output representing a rocket countdown.
//-----------------------------------------------------------------
public static void main (String[] args)
{
System.out.print ("Three... ");
System.out.print ("Two... ");
System.out.print ("One... ");
System.out.print ("Zero... ");
System.out.println ("Liftoff!"); // appears on first output line
System.out.println ("Houston, we have a problem.");
}
}
Output
Three... Two... One... Zero... Liftoff!
Houston, we have a problem.
The printf() Method
 To format output
 Usage (Syntax):
System.out.printf(formatString , items);
where
-formatString: a string with format specifiers
- items: list of data/variables to be displayed
Use printf() method in order to use the
above format. printf() method is only
supported in JDK 5 and higher version.
Formatting Output
 Output of floating point values can look strange:
Price per liter: 1.21997
 To control the output appearance of numeric variables,
use formatted output tools such as:
a) System.out.printf(“%.2f”, price);
Price per liter: 1.22
b) System.out.printf(“%10.2f”, price);
Price per liter: 1.22
 The %10.2f is called a format specifier
Formatting Output
-Format specifier specifies how item should be displayed
-Frequently used format type specifiers
specifier output example
%d decimal integer 200
%f a float number 35.3404
%s a string “Java”
%c a character ‘T’
%b a boolean value true
%n line separator
%e exponential 1.23e+1
Formatting Output – E.g
String Concatenation
 The string concatenation operator (+) is used to
append one string to the end of another
"Peanut butter " + "and jelly"
 It can also be used to append a number to a string
 A string literal cannot be broken across two lines in
a program
 See Facts.java
Goals//********************************************************************
// Facts.java Author: Lewis/Loftus
//
// Demonstrates the use of the string concatenation operator and the
// automatic conversion of an integer to a string.
//********************************************************************
public class Facts
{
//-----------------------------------------------------------------
// Prints various facts.
//-----------------------------------------------------------------
public static void main (String[] args)
{
// Strings can be concatenated into one long string
System.out.println ("We present the following facts for your "
+ "extracurricular edification:");
System.out.println ();
// A string can contain numeric digits
System.out.println ("Letters in the Hawaiian alphabet: 12");
continue
continue
// A numeric value can be concatenated to a string
System.out.println ("Dialing code for Antarctica: " + 672);
System.out.println ("Year in which Leonardo da Vinci invented "
+ "the parachute: " + 1515);
System.out.println ("Speed of ketchup: " + 40 + " km per year");
}
}
continue
// A numeric value can be concatenated to a string
System.out.println ("Dialing code for Antarctica: " + 672);
System.out.println ("Year in which Leonardo da Vinci invented "
+ "the parachute: " + 1515);
System.out.println ("Speed of ketchup: " + 40 + " km per year");
}
}
Output
We present the following facts for your extracurricular edification:
Letters in the Hawaiian alphabet: 12
Dialing code for Antarctica: 672
Year in which Leonardo da Vinci invented the parachute: 1515
Speed of ketchup: 40 km per year
String Concatenation
 The + operator is also used for arithmetic addition
 The function that it performs depends on the type
of the information on which it operates
 If both operands are strings, or if one is a string
and one is a number, it performs string
concatenation
 If both operands are numeric, it adds them
 The + operator is evaluated left to right, but
parentheses can be used to force the order
 See Addition.java
//********************************************************************
// Addition.java Author: Lewis/Loftus
//
// Demonstrates the difference between the addition and string
// concatenation operators.
//********************************************************************
public class Addition
{
//-----------------------------------------------------------------
// Concatenates and adds two numbers and prints the results.
//-----------------------------------------------------------------
public static void main (String[] args)
{
System.out.println ("24 and 45 concatenated: " + 24 + 45);
System.out.println ("24 and 45 added: " + (24 + 45));
}
}
//********************************************************************
// Addition.java Author: Lewis/Loftus
//
// Demonstrates the difference between the addition and string
// concatenation operators.
//********************************************************************
public class Addition
{
//-----------------------------------------------------------------
// Concatenates and adds two numbers and prints the results.
//-----------------------------------------------------------------
public static void main (String[] args)
{
System.out.println ("24 and 45 concatenated: " + 24 + 45);
System.out.println ("24 and 45 added: " + (24 + 45));
}
}
Output
24 and 45 concatenated: 2445
24 and 45 added: 69
Quick Check
 What output is produced by the following?
System.out.println ("X: " + 25);
System.out.println ("Y: " + (15 + 50));
System.out.println ("Z: " + 300 + 50);
Quick Check
 What output is produced by the following?
System.out.println ("X: " + 25);
System.out.println ("Y: " + (15 + 50));
System.out.println ("Z: " + 300 + 50);
X: 25
Y: 65
Z: 30050

Más contenido relacionado

La actualidad más candente

Iterator - a powerful but underappreciated design pattern
Iterator - a powerful but underappreciated design patternIterator - a powerful but underappreciated design pattern
Iterator - a powerful but underappreciated design patternNitin Bhide
 
Thumbtack Expertise Days # 5 - Javaz
Thumbtack Expertise Days # 5 - JavazThumbtack Expertise Days # 5 - Javaz
Thumbtack Expertise Days # 5 - JavazAlexey Remnev
 
Kotlin으로 안드로이드 개발하기
Kotlin으로 안드로이드 개발하기Kotlin으로 안드로이드 개발하기
Kotlin으로 안드로이드 개발하기Taehwan kwon
 
String & path functions in vba
String & path functions in vbaString & path functions in vba
String & path functions in vbagondwe Ben
 
Setup Java Path and classpath (from the java™ tutorials essential classes -...
Setup Java Path and classpath (from the java™ tutorials   essential classes -...Setup Java Path and classpath (from the java™ tutorials   essential classes -...
Setup Java Path and classpath (from the java™ tutorials essential classes -...Louis Slabbert
 

La actualidad más candente (10)

Iterator - a powerful but underappreciated design pattern
Iterator - a powerful but underappreciated design patternIterator - a powerful but underappreciated design pattern
Iterator - a powerful but underappreciated design pattern
 
LISP: Macros in lisp
LISP: Macros in lispLISP: Macros in lisp
LISP: Macros in lisp
 
Oracle: Cursors
Oracle: CursorsOracle: Cursors
Oracle: Cursors
 
Java Docs
Java DocsJava Docs
Java Docs
 
Thumbtack Expertise Days # 5 - Javaz
Thumbtack Expertise Days # 5 - JavazThumbtack Expertise Days # 5 - Javaz
Thumbtack Expertise Days # 5 - Javaz
 
SQL
SQLSQL
SQL
 
4 cursors
4 cursors4 cursors
4 cursors
 
Kotlin으로 안드로이드 개발하기
Kotlin으로 안드로이드 개발하기Kotlin으로 안드로이드 개발하기
Kotlin으로 안드로이드 개발하기
 
String & path functions in vba
String & path functions in vbaString & path functions in vba
String & path functions in vba
 
Setup Java Path and classpath (from the java™ tutorials essential classes -...
Setup Java Path and classpath (from the java™ tutorials   essential classes -...Setup Java Path and classpath (from the java™ tutorials   essential classes -...
Setup Java Path and classpath (from the java™ tutorials essential classes -...
 

Similar a Chapter 2.2

Microsoft word java
Microsoft word   javaMicrosoft word   java
Microsoft word javaRavi Purohit
 
Numerical Data And Expression
Numerical Data And ExpressionNumerical Data And Expression
Numerical Data And ExpressionPRN USM
 
Lewis jssap3 e_labman02
Lewis jssap3 e_labman02Lewis jssap3 e_labman02
Lewis jssap3 e_labman02auswhit
 
Java Chapter 05 - Conditions & Loops: part 5
Java Chapter 05 - Conditions & Loops: part 5Java Chapter 05 - Conditions & Loops: part 5
Java Chapter 05 - Conditions & Loops: part 5DanWooster1
 
(In java language)1. Use recursion in implementing the binarySearc.pdf
(In java language)1. Use recursion in implementing the binarySearc.pdf(In java language)1. Use recursion in implementing the binarySearc.pdf
(In java language)1. Use recursion in implementing the binarySearc.pdfrbjain2007
 
Treatment, Architecture and Threads
Treatment, Architecture and ThreadsTreatment, Architecture and Threads
Treatment, Architecture and ThreadsMathias Seguy
 
9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx
9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx
9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docxransayo
 
StackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfStackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfARCHANASTOREKOTA
 
Alcohol Awareness Special Lecture ReflectionAlcohol is among the.docx
Alcohol Awareness Special Lecture ReflectionAlcohol is among the.docxAlcohol Awareness Special Lecture ReflectionAlcohol is among the.docx
Alcohol Awareness Special Lecture ReflectionAlcohol is among the.docxsimonlbentley59018
 
Chapter 3.4
Chapter 3.4Chapter 3.4
Chapter 3.4sotlsoc
 
Gift-VT Tools Development Overview
Gift-VT Tools Development OverviewGift-VT Tools Development Overview
Gift-VT Tools Development Overviewstn_tkiller
 
The Mayans Lost Guide to RxJava on Android
The Mayans Lost Guide to RxJava on AndroidThe Mayans Lost Guide to RxJava on Android
The Mayans Lost Guide to RxJava on AndroidFernando Cejas
 

Similar a Chapter 2.2 (20)

Microsoft word java
Microsoft word   javaMicrosoft word   java
Microsoft word java
 
Java Print method
Java  Print methodJava  Print method
Java Print method
 
Numerical Data And Expression
Numerical Data And ExpressionNumerical Data And Expression
Numerical Data And Expression
 
Lewis jssap3 e_labman02
Lewis jssap3 e_labman02Lewis jssap3 e_labman02
Lewis jssap3 e_labman02
 
CS2309 JAVA LAB MANUAL
CS2309 JAVA LAB MANUALCS2309 JAVA LAB MANUAL
CS2309 JAVA LAB MANUAL
 
Ifi7107 lesson4
Ifi7107 lesson4Ifi7107 lesson4
Ifi7107 lesson4
 
Java Chapter 05 - Conditions & Loops: part 5
Java Chapter 05 - Conditions & Loops: part 5Java Chapter 05 - Conditions & Loops: part 5
Java Chapter 05 - Conditions & Loops: part 5
 
(In java language)1. Use recursion in implementing the binarySearc.pdf
(In java language)1. Use recursion in implementing the binarySearc.pdf(In java language)1. Use recursion in implementing the binarySearc.pdf
(In java language)1. Use recursion in implementing the binarySearc.pdf
 
Treatment, Architecture and Threads
Treatment, Architecture and ThreadsTreatment, Architecture and Threads
Treatment, Architecture and Threads
 
Spring boot
Spring boot Spring boot
Spring boot
 
9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx
9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx
9 11 25 14 44 6 41 15 57 9 39 16 41 2 58 8 43 12 4.docx
 
StackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfStackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdf
 
Vo.pdf
   Vo.pdf   Vo.pdf
Vo.pdf
 
Alcohol Awareness Special Lecture ReflectionAlcohol is among the.docx
Alcohol Awareness Special Lecture ReflectionAlcohol is among the.docxAlcohol Awareness Special Lecture ReflectionAlcohol is among the.docx
Alcohol Awareness Special Lecture ReflectionAlcohol is among the.docx
 
Chapter 3.4
Chapter 3.4Chapter 3.4
Chapter 3.4
 
Gift-VT Tools Development Overview
Gift-VT Tools Development OverviewGift-VT Tools Development Overview
Gift-VT Tools Development Overview
 
Spring
SpringSpring
Spring
 
backend
backendbackend
backend
 
backend
backendbackend
backend
 
The Mayans Lost Guide to RxJava on Android
The Mayans Lost Guide to RxJava on AndroidThe Mayans Lost Guide to RxJava on Android
The Mayans Lost Guide to RxJava on Android
 

Más de sotlsoc

Chapter 2.0 new
Chapter 2.0 newChapter 2.0 new
Chapter 2.0 newsotlsoc
 
Chapter 1.0 new
Chapter 1.0 newChapter 1.0 new
Chapter 1.0 newsotlsoc
 
Chapter 3.0 new
Chapter 3.0 newChapter 3.0 new
Chapter 3.0 newsotlsoc
 
Chapter 6.5 new
Chapter 6.5 newChapter 6.5 new
Chapter 6.5 newsotlsoc
 
Chapter 11.1
Chapter 11.1Chapter 11.1
Chapter 11.1sotlsoc
 
Chapter 10.3
Chapter 10.3Chapter 10.3
Chapter 10.3sotlsoc
 
Chapter 11.4
Chapter 11.4Chapter 11.4
Chapter 11.4sotlsoc
 
Chapter 11.3
Chapter 11.3Chapter 11.3
Chapter 11.3sotlsoc
 
Chapter 11.5
Chapter 11.5Chapter 11.5
Chapter 11.5sotlsoc
 
Chapter 11.2
Chapter 11.2Chapter 11.2
Chapter 11.2sotlsoc
 
Chapter 11.0
Chapter 11.0Chapter 11.0
Chapter 11.0sotlsoc
 
Chapter 10.2
Chapter 10.2Chapter 10.2
Chapter 10.2sotlsoc
 
Chapter 10.1
Chapter 10.1Chapter 10.1
Chapter 10.1sotlsoc
 
Chapter 8.0
Chapter 8.0Chapter 8.0
Chapter 8.0sotlsoc
 
Chapter 10.0
Chapter 10.0Chapter 10.0
Chapter 10.0sotlsoc
 
Chapter 9.3
Chapter 9.3Chapter 9.3
Chapter 9.3sotlsoc
 
Chapter 9.4
Chapter 9.4Chapter 9.4
Chapter 9.4sotlsoc
 
Chapter 9.1
Chapter 9.1Chapter 9.1
Chapter 9.1sotlsoc
 
Chapter 8.1
Chapter 8.1Chapter 8.1
Chapter 8.1sotlsoc
 
Chapter 9.0
Chapter 9.0Chapter 9.0
Chapter 9.0sotlsoc
 

Más de sotlsoc (20)

Chapter 2.0 new
Chapter 2.0 newChapter 2.0 new
Chapter 2.0 new
 
Chapter 1.0 new
Chapter 1.0 newChapter 1.0 new
Chapter 1.0 new
 
Chapter 3.0 new
Chapter 3.0 newChapter 3.0 new
Chapter 3.0 new
 
Chapter 6.5 new
Chapter 6.5 newChapter 6.5 new
Chapter 6.5 new
 
Chapter 11.1
Chapter 11.1Chapter 11.1
Chapter 11.1
 
Chapter 10.3
Chapter 10.3Chapter 10.3
Chapter 10.3
 
Chapter 11.4
Chapter 11.4Chapter 11.4
Chapter 11.4
 
Chapter 11.3
Chapter 11.3Chapter 11.3
Chapter 11.3
 
Chapter 11.5
Chapter 11.5Chapter 11.5
Chapter 11.5
 
Chapter 11.2
Chapter 11.2Chapter 11.2
Chapter 11.2
 
Chapter 11.0
Chapter 11.0Chapter 11.0
Chapter 11.0
 
Chapter 10.2
Chapter 10.2Chapter 10.2
Chapter 10.2
 
Chapter 10.1
Chapter 10.1Chapter 10.1
Chapter 10.1
 
Chapter 8.0
Chapter 8.0Chapter 8.0
Chapter 8.0
 
Chapter 10.0
Chapter 10.0Chapter 10.0
Chapter 10.0
 
Chapter 9.3
Chapter 9.3Chapter 9.3
Chapter 9.3
 
Chapter 9.4
Chapter 9.4Chapter 9.4
Chapter 9.4
 
Chapter 9.1
Chapter 9.1Chapter 9.1
Chapter 9.1
 
Chapter 8.1
Chapter 8.1Chapter 8.1
Chapter 8.1
 
Chapter 9.0
Chapter 9.0Chapter 9.0
Chapter 9.0
 

Último

Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 

Último (20)

Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 

Chapter 2.2

  • 2. Java Application Programming Interface (API)  The Java Application Programming Interface (API) is prewritten code (predefined classes), organized into packages of similar topics. For instance, the Applet and AWT packages include classes for creating fonts, menus, and buttons.  There are 3 editions of the Java API:  Java 2 Standard Edition (J2SE) : to develop client- side standalone applications or applets.  Java 2 Enterprise Edition (J2EE) : to develop server- side applications. E.g. Java servlets and JSP.  Java 2 Micro Edition (J2ME) : to develop applications for mobile devices.
  • 3. Characters String  A string literal is represented by putting double quotes around the text  Examples: "This is a string literal." "123 Main Street" "X"  Every character string is an object in Java, defined by the String class  Every string literal represents a String object
  • 4. The println() Method  The System.out object represents a destination (the monitor screen) to which we can send output System.out.println ("Whatever you are, be a good one."); object method name information provided to the method (parameters)
  • 5. The print() Method  The System.out object provides another service as well  The print method is similar to the println method, except that it does not advance to the next line  Therefore anything printed after a print statement will appear on the same line  See Countdown.java
  • 6. Goals //******************************************************************** // Countdown.java Author: Lewis/Loftus // // Demonstrates the difference between print and println. //******************************************************************** public class Countdown { //----------------------------------------------------------------- // Prints two lines of output representing a rocket countdown. //----------------------------------------------------------------- public static void main (String[] args) { System.out.print ("Three... "); System.out.print ("Two... "); System.out.print ("One... "); System.out.print ("Zero... "); System.out.println ("Liftoff!"); // appears on first output line System.out.println ("Houston, we have a problem."); } }
  • 7. Goals //******************************************************************** // Countdown.java Author: Lewis/Loftus // // Demonstrates the difference between print and println. //******************************************************************** public class Countdown { //----------------------------------------------------------------- // Prints two lines of output representing a rocket countdown. //----------------------------------------------------------------- public static void main (String[] args) { System.out.print ("Three... "); System.out.print ("Two... "); System.out.print ("One... "); System.out.print ("Zero... "); System.out.println ("Liftoff!"); // appears on first output line System.out.println ("Houston, we have a problem."); } } Output Three... Two... One... Zero... Liftoff! Houston, we have a problem.
  • 8. The printf() Method  To format output  Usage (Syntax): System.out.printf(formatString , items); where -formatString: a string with format specifiers - items: list of data/variables to be displayed Use printf() method in order to use the above format. printf() method is only supported in JDK 5 and higher version.
  • 9. Formatting Output  Output of floating point values can look strange: Price per liter: 1.21997  To control the output appearance of numeric variables, use formatted output tools such as: a) System.out.printf(“%.2f”, price); Price per liter: 1.22 b) System.out.printf(“%10.2f”, price); Price per liter: 1.22  The %10.2f is called a format specifier
  • 10. Formatting Output -Format specifier specifies how item should be displayed -Frequently used format type specifiers specifier output example %d decimal integer 200 %f a float number 35.3404 %s a string “Java” %c a character ‘T’ %b a boolean value true %n line separator %e exponential 1.23e+1
  • 12. String Concatenation  The string concatenation operator (+) is used to append one string to the end of another "Peanut butter " + "and jelly"  It can also be used to append a number to a string  A string literal cannot be broken across two lines in a program  See Facts.java
  • 13. Goals//******************************************************************** // Facts.java Author: Lewis/Loftus // // Demonstrates the use of the string concatenation operator and the // automatic conversion of an integer to a string. //******************************************************************** public class Facts { //----------------------------------------------------------------- // Prints various facts. //----------------------------------------------------------------- public static void main (String[] args) { // Strings can be concatenated into one long string System.out.println ("We present the following facts for your " + "extracurricular edification:"); System.out.println (); // A string can contain numeric digits System.out.println ("Letters in the Hawaiian alphabet: 12"); continue
  • 14. continue // A numeric value can be concatenated to a string System.out.println ("Dialing code for Antarctica: " + 672); System.out.println ("Year in which Leonardo da Vinci invented " + "the parachute: " + 1515); System.out.println ("Speed of ketchup: " + 40 + " km per year"); } }
  • 15. continue // A numeric value can be concatenated to a string System.out.println ("Dialing code for Antarctica: " + 672); System.out.println ("Year in which Leonardo da Vinci invented " + "the parachute: " + 1515); System.out.println ("Speed of ketchup: " + 40 + " km per year"); } } Output We present the following facts for your extracurricular edification: Letters in the Hawaiian alphabet: 12 Dialing code for Antarctica: 672 Year in which Leonardo da Vinci invented the parachute: 1515 Speed of ketchup: 40 km per year
  • 16. String Concatenation  The + operator is also used for arithmetic addition  The function that it performs depends on the type of the information on which it operates  If both operands are strings, or if one is a string and one is a number, it performs string concatenation  If both operands are numeric, it adds them  The + operator is evaluated left to right, but parentheses can be used to force the order  See Addition.java
  • 17. //******************************************************************** // Addition.java Author: Lewis/Loftus // // Demonstrates the difference between the addition and string // concatenation operators. //******************************************************************** public class Addition { //----------------------------------------------------------------- // Concatenates and adds two numbers and prints the results. //----------------------------------------------------------------- public static void main (String[] args) { System.out.println ("24 and 45 concatenated: " + 24 + 45); System.out.println ("24 and 45 added: " + (24 + 45)); } }
  • 18. //******************************************************************** // Addition.java Author: Lewis/Loftus // // Demonstrates the difference between the addition and string // concatenation operators. //******************************************************************** public class Addition { //----------------------------------------------------------------- // Concatenates and adds two numbers and prints the results. //----------------------------------------------------------------- public static void main (String[] args) { System.out.println ("24 and 45 concatenated: " + 24 + 45); System.out.println ("24 and 45 added: " + (24 + 45)); } } Output 24 and 45 concatenated: 2445 24 and 45 added: 69
  • 19. Quick Check  What output is produced by the following? System.out.println ("X: " + 25); System.out.println ("Y: " + (15 + 50)); System.out.println ("Z: " + 300 + 50);
  • 20. Quick Check  What output is produced by the following? System.out.println ("X: " + 25); System.out.println ("Y: " + (15 + 50)); System.out.println ("Z: " + 300 + 50); X: 25 Y: 65 Z: 30050