{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

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

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

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

View Full Document Right Arrow Icon
Topics Components of a Java Program classes methods comments import statements Declaring and creating objects Java identifiers Standard Java classes
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.
Image of page 3

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

View Full Document Right 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); } }
Image of page 4
UML diagram for Ch2Sample1 This diagram shows the messages sent to myWindow
Image of page 5

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

View Full Document Right 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.
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
Image of page 7

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

View Full Document Right Arrow Icon
Java Identifiers A Java identifier is a sequence of letters, digits, underscores, and dollar signs used to name a class, object, method, etc.
Image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern