Chap2 - Chapter 2 Getting Started with Java Topics...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
Chapter 2 Getting Started with Java
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Topics Components of a Java Program classes methods comments import statements Declaring and creating objects Java identifiers Standard Java classes
Background image of page 2
The First Java Program This first program displays a window on the screen. The size of the window is 300 x 200 pixels The title is My First Java Program . The fundamental OOP concept illustrated by the program: An object-oriented program uses objects.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
The First Java Program /* Chapter 2 Sample Program: Displaying a Window File: Ch2Sample1.java */ import javax.swing.*; class Ch2Sample1 { public static void main(String[ ] args){ JFrame myWindow; myWindow = new JFrame(); myWindow.setSize(300, 200); myWindow.setTitle(“My First Java Program”); myWindow.setVisible(true); } }
Background image of page 4
UML diagram for Ch2Sample1 This diagram shows the messages sent to myWindow
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Class diagram for Ch2Sample1 This diagram shows the dependency relationship between the classes in the program. The Ch2Sample1 class uses a JFrame object. To use an object in a program, first we declare and create and object. Then we send messages to it.
Background image of page 6
Declaring Objects When we declare an object, we must give it a name and say what class it belongs to. syntax: the name must be a valid Java identifier the class must be defined and available if multiple objects are declared, the names are separated by commas
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Java Identifiers A Java identifier is a sequence of letters, digits, underscores, and dollar signs used to
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 08/18/2011 for the course COMPUTER S CSC113 taught by Professor Shah during the Spring '09 term at King Saud University.

Page1 / 26

Chap2 - Chapter 2 Getting Started with Java Topics...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online