Java 2 Tutorial for Cpp Programmers-Enterprise Application Development-Lecture Slides, Slides of Software Development

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

2011/2012

Uploaded on 07/17/2012

bahula
bahula 🇮🇳

4.6

(10)

41 documents

1 / 156

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
JAVA™ 2
STANDARD EDITION
A Brief Tutorial for C++ Programmers
docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download Java 2 Tutorial for Cpp Programmers-Enterprise Application Development-Lecture Slides and more Slides Software Development in PDF only on Docsity!

JAVA™ 2STANDARD EDITIONA Brief Tutorial for C++ Programmers

Enterprise Application Development

History of Java ^ Java• Originally for intelligent consumer-electronic devices• Then used for creating Web pages with

dynamic content

  • Now also used for:^ ^ Develop large-scale enterprise applications^ ^ Enhance WWW server functionality^ ^ Provide applications for consumer devices (cell phones,etc.)

Enterprise Application Development

Fig. 1.1 Typical Java environment

Program is createdin an editor andEditorDiskstored on disk in afile ending with .java. Compiler createsCompilerbytecodes andDiskstores them on diskin a file ending with .class. PrimaryMemoryClass LoaderClass loaderreads^ .class files containingbytecodesfrom disk andDiskputs those..bytecodes in...memory..

Phase 1Phase 2 Phase 3

PrimaryMemoryBytecodeBytecode verifierVerifier confirms that allbytecodes arevalid and do notviolate Java’ssecurity..restrictions.....

Phase 4

PrimaryMemoryInterpreterInterpreter reads bytecodesand translatesthem into alanguage thatthe computercan understand,..possibly storing..data values as..the programexecutes.

Phase 5

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

Welcome^ to^ Java^ Programming!

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

// program uses OptionPane

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

// terminate application with window

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 " + sum^ ^ Uses the operator + to "add" the string literal

"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 "

sum,

35 "Results", JOptionPane.PLAIN_MESSAGE );

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^

Applets

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

8 public class WelcomeApplet extends JApplet {