This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
• Integrates editor, javac, java, appletviewer, debugger, other tools: specialized Java editor with syntax highlighting,
autoindent, tab setting, etc. clicking on a compiler error message takes you to
the offending source code line
• Usually JDK is installed separately and an IDE is installed on top of it.
2-18
Types of Programs
• Console applications • GUI applications
• Applets
2-19
Console Applications
C:\javamethods\Ch02> path=%PATH%;C:\Program Files\Java\jdk 1.5.0_07\binC:\javamethods\Ch02> javac Greetings2.javaC:\javamethods\Ch02> java Greetings2Enter your first name: JosephineEnter your last name: JaworskiHello, Josephine JaworskiPress any key to continue...
• Simple text dialog:prompt input, prompt input ... result
public class HelloGui extends JFrame{ < ... other code >
public static void main(String[ ] args) { HelloGui window = new HelloGui( ); // Set this window's location and size: // upper-left corner at 300, 300; width 200, height 100 window.setBounds(300, 300, 200, 100); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.setVisible(true); }}
GUI libraries
2-25
HelloApplet.java
import java.awt.*;import javax.swing.*;
public class HelloApplet extends JApplet{ public void init( ) { ... } < ... other code >}
No main in applets: the init method is called by JDK’s appletviewer or the browser
2-26
OOP —Object-Oriented Programming
• An OOP program models a world of active objects.
• An object may have its own “memory,” which may contain other objects.
• An object has a set of methods that can process messages of certain types.
2-27
OOP (cont’d)
• A method can change the object’s state, send messages to other objects, and create new objects.
• An object belongs to a particular class, and the functionality of each object is determined by its class.
• A programmer creates an OOP application by defining classes.
2-28
The Main OOP Concepts:
• Inheritance: a subclass extends a superclass; the objects of a subclass inherit features of the superclass and can redefine them or add new features.
• Event-driven programs: the program simulates asynchronous handling of events; methods are called automatically in response to events.
2-29
Inheritance
• A programmer can define hierarchies of classes
• More general classes are closer to the top
Person
Child Adult
Baby Toddler Teen
2-30
OOP Benefits
• Facilitates team development
• Easier to reuse software components and write reusable software
• Easier GUI (Graphical User Interface) and multimedia programming
2-31
Review:
• What are some of the current software development concerns?
• What are editor, compiler, debugger used for?
• How is a compiler different from an interpreter?
• Name some of the benefits of Java’s compiler+interpreter approach.
• Define IDE.
2-32
Review (cont’d):
• What is a console application?
• What are command-line arguments?
• What is a GUI application?
• What is the difference between a GUI application and an applet?