




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Dr. Sahastrajit Adarsh delivered this lecture at Birla Institute of Technology and Science for Enterprise Application Development. It includes: Java, Standard, Editions, Tutorial, Programmers, Intelligent, Consumer-electronics, Devices, Dyamic, Content, Applications, Environment
Typology: Slides
1 / 156
This page cannot be seen from the preview
Don't miss anything!





























































































Enterprise Application Development
History of Java ^ Java• Originally for intelligent consumer-electronic devices• Then used for creating Web pages with
dynamic content
Enterprise Application Development
Fig. 1.1 Typical Java environment
Enterprise Application Development
First Java Application 1 //^ Welcome1.java 2 //^ Text-printing
program. 3 4 public^ class^ Welcome
{ 5 6 //^ main^ method
begins^ execution^ of^
Java^ application 7 public^ static
void^ main(^ String^ args[]
) 8 { 9 System.out.println(
"Welcome^ to^ Java^ Programming!"
);
1011 }^ //^ end^ method
main 1213 }^ //^ end^ class
Welcome
Enterprise Application Development
Execution... ^ Executing a program• Type^ java Welcome1^ ^ Interpreter loads
.class^ file for class
Welcome ^ .class^ extension omitted from command• Interpreter calls method
main Fig. 2.2^ Executing Welcome1 in a Microsoft Windows 2000 Command Prompt
Enterprise Application Development
Displaying Text in a Dialog Box ^ Display• Most Java applications use windows or a dialog box^ ^ Earlier, we used command window• Class^ JOptionPane
allows us to use dialog boxes ^ Packages• Set of predefined classes for us to use• Groups of related classes called
packages ^ Group of all packages known as Java class library or Javaapplications programming interface (Java API) • JOptionPane^ is in the
javax.swing^ package ^ Package has classes for using Graphical User Interfaces(GUIs)
Enterprise Application Development
Displaying Text in a Dialog Box^ • Two groups of packages in Java API• Core packages^ ^ Begin with
java Included with Java 2 Software Development Kit• Extension packages Begin with javax New Java packages • import declarations Used by compiler to identify and locate classes used inJava programs Tells compiler to load class^ JOptionPane
from 4 // Java packages^5 import javax.swing.JOptionPane;^ javax.swing^ package
Enterprise Application Development
Displaying Text in a Dialog Box^ • Calls^ static
method^ exit^ of class
System ^ Terminates application• Use with any application displaying a GUI ^ Because method is
static, needs class name and dot (
.)
^ Identifiers starting with capital letters usually class names• Argument of^0 means application ended successfully ^ Non-zero usually means an error occurred• Class^ System^ part of package
java.lang 15 System.exit( 0^ );^ ^ No^ import^ declaration needed^ ^ java.lang^ automatically imported in every Java program
Enterprise Application Development
33 //^ display^ result 34 JOptionPane.showMessageDialog( null,
"The^ sum^ is^ " +^ sum, 35 "Results",^ JOptionPane.PLAIN_MESSAGE ); 3637 System.exit( 0^
);^ //^ terminate^ application
with^ window 3839 }^ //^ end^ method^ main 4041 }^ //^ end^ class^ Addition
Enterprise Application Development
Adding Integers^ • Use^ showMessageDialog
to display results
"The sum is" and^ sum Concatenation of a^
String^ and another type• Results in a new string ^ If^ sum^ contains^117
, then^ "The sum is " + sum
results in the 34 JOptionPane.showMessageDialog( null, "The sum is " +new string^ "The sum is 117"^ ^ Note the space in^ "The sum is "
Enterprise Application Development
Adding Integers^ Messa g e d ia lo g typ e^
Ic o n^ Desc rip tio n JOptionPane.ERROR_MESSAGE
Displays a dialog that indicates an errorto the user. JOptionPane.INFORMATION_MESSAGE
Displays a dialog with an informationalmessage to the user. The user can simplydismiss the dialog. JOptionPane.WARNING_MESSAGE
Displays a dialog that warns the user of apotential problem. JOptionPane.QUESTION_MESSAGE
Displays a dialog that poses a question tothe user. This dialog normally requires aresponse, such as clicking on a
Yes^ or a No^ button. JOptionPane.PLAIN_MESSAGE
no icon^ Displays a dialog that simply contains amessage, with no icon. Fig. 2.12^ c o nsta nts for m essa g e d ia log s.JOptionPane^
Enterprise Application Development
1 //^ WelcomeApplet.java 2 //^ A^ first^ applet^ in
Java. 3 4 //^ Java^ packages 5 import^ java.awt.Graphics;
//^ import^ class^ Graphics 6 import^ javax.swing.JApplet;
//^ import^ class^ JApplet 7 8 public^ class WelcomeApplet extends
JApplet^ { 910 //^ draw^ text^ on^ applet
’ s^ background 11 public^ void paint(
Graphics^ g^ ) 12 { 13 //^ call^ superclass
version^ of^ method^ paint 14 super.paint(^ g
1516 //^ draw^ a^ String
at^ x-coordinate^25 and^ y-coordinate
17 g.drawString( "Welcome
to^ Java^ Programming!",^ 25,
1819 }^ //^ end^ method^ paint 2021 }^ //^ end^ class^ WelcomeApplet
JApplet + init(void):void+ start(void)+ paint(:Graphics)docsity.com
Enterprise Application Development
Java Applet: Drawing a String^ • Class^ WelcomeApplet
is a blueprint ^ appletviewer^ or browser creates an object of class^ WelcomeApplet^ • Keyword^ public
required• File can only have one^ public^ class • public class name must be file name