©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter 2 - 1 Ch2: Getting Started with Java - Objectives After.

Slides:



Advertisements
Similar presentations
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 6 Repetition Statements.
Advertisements

©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 2 Getting Started with Java.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 5 Selection Statements Animated Version.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 2 Getting Started with Java Animated Version.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Four Defining Your Own Classes.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 2 Getting Started with Java Program development.
Your First Java Program: HelloWorld.java
Dialogs. Displaying Text in a Dialog Box Windows and dialog boxes –Up to this our output has been to the screen –Many Java applications use these to display.
Using JOptionPanes for graphical communication with our programs. Pages Horstmann 139.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 2 Getting Started with Java Structure of.
Mathematical Operators  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming in.
COMP 14 Introduction to Programming Miguel A. Otaduy May 17, 2004.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 2 Getting Started with Java Structure of.
COMPSCI 125 Spring 2005 ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Four: Defining Your Own Classes *Instantiable.
Getting Started with Java
COMPSCI 125 Spring 2005 ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 2: Getting Started with Java *Components.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 29, 2005.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 2 Getting Started with Java.
Chapter Chapter 2 Getting Started with Java.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 4 Defining Your Own Classes.
TCP/IP Protocol Suite 1 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 18 Host Configuration: DHCP.
Programming with Java standard classes. Java API Application Programming Interface Provides hundreds of standard classes that can be incorporated into.
Relational Operators Control structures Decisions using “if” statements  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course.
Chapter 2 Getting Started with Java Part B. Topics Components of a Java Program –classes –methods –comments –import statements Declaring and creating.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 4 Defining Your Own Classes.
CS 180 Recitation 8 / {30, 31} / Announcements Project 1 is out –Due 10:00pm –Start early! –Use the newsgroup for your questions –LWSN B146.
COMP 110 Introduction to Programming Mr. Joshua Stough September 10, 2007.
COMPSCI 125 Spring 2005 ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 3: IO *Standard Output *Formatting Decimal.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Software Engineering Software Development Process.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 2 Image Slides.
Chapter 8 Traffic-Analysis Techniques. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 8-1.
Chapter 6 – Repetition Statements : Objectives After you have read and studied this chapter, you should be able to Implement repetition control in a program.
CS1101: Programming Methodology
Getting Started with Java Recitation – 1/23/2009 CS 180 Department of Computer Science, Purdue University.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 2 Getting Started with Java Animated Version.
CS1101X: Programming Methodology Recitation 1 Java Basics Numerical Data.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 3: Numerical Data Manipulating Numbers Variables.
A First Look at Java Chapter 2 1/29 & 2/2 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
Input/Output in Java. Output To output to the command line, we use either System.out.print () or System.out.println() or System.out.printf() Examples.
Programming Fundamentals 2: Simple/ F II Objectives – –give some simple examples of Java applications and one applet 2. Simple Java.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Sample Slides - 1 Sample Animated Slides for Wu, Intro to OOP.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 4 Defining Your Own Classes.
Creating Windows. How can we use Java to create programs that use windows (GUI applications)? How can we use Java to create programs that use windows.
 GUI – Graphic User Interface  Up to now in the programs we have written all output has been sent to the standard output device i.e.: the DOS console.
Chapter 2 Getting Started with Java. Objectives After you have read and studied this chapter, you should be able to Identify the basic components of Java.
 2005 Pearson Education, Inc. All rights reserved. 1 A class A class is the blueprint from which objects are generated. In other words, if we have six.
Data Types – Reference Types Objective To understand what reference types are The need to study reference types To understand Java standard packages To.
Introduction Chapter 1 8/31 & 9/1 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
GUI Graphical User Interface Each onscreen component and window is an object Object interaction makes communication and scoping challenging Event-driven.
1 Training Lecture 1. 2 Primitive Data Declaration and Assignments Code State of Memory int firstNumber, secondNumber; firstNumber = 234; secondNumber.
Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Getting Started with Java: Object declaration and creation Primitive.
Using classes. One step instantiation, Composition I JFrame myWindow = new JFrame( ); Two step Instantiation, Composition II private JFrame myWindow;
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 1 Introduction to Computers, Programs,
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 2 Getting Started with Java Animated Version.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Three Statics of Structures Reactions.
Strings and I/O. Lotsa String Stuff… There are close to 50 methods defined in the String class. We will introduce several of them here: charAt, substring,
Computer Programming 2 Lab (1) I.Fatimah Alzahrani.
بسم الله الرحمن الرحيم CPCS203: Programming II. ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display., Modifications by Dr.
C OMMON M ISTAKES CSC Java Program Structure  String Methods.
Object Oriented Programming Object and Classes Lecture 3 MBY.
Chapter 13 Transportation Demand Analysis. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 7 ( Book Chapter 14) GUI and Event-Driven Programming.
Chapter 4 : Defining Your Own Classes Part 1 - Objectives After you have read and studied this chapter, you should be able to Define a class with multiple.
Intro to OOP with Java, C. Thomas Wu
Intro to OOP with Java, C. Thomas Wu Getting Started with Java
2.5 Another Java Application: Adding Integers
Getting Started with Java
Computer Programming-1 CSC 111
Presentation transcript:

©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Ch2: Getting Started with Java - Objectives After you have read and studied this chapter, you should be able to Identify the basic components of Java programs Write simple Java programs Describe the difference between object declaration and creation Describe the process of creating and running Java programs Use the Date, SimpleDateFormat, String, and JOptionPane standard classes Develop Java programs, using the incremental development approach

©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Program Ch2Sample1 import javax.swing.*; class Ch2Sample1 { public static void main(String[ ] args) { JFramemyWindow; myWindow = new JFrame( ); myWindow.setSize(300, 200); myWindow.setTitle(“My First Java Program”); myWindow.setVisible(true); } Declare a name Create an object Use an object

©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Program Diagram for Ch2Sample1 myWindow : JFrame Ch2Sample1 setSize(300, 200) setTitle(“My First Java Program”) setVisible(true) myWindow : JFrame Ch2Sample1 Dependency Relationship

©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Object Declaration and Creation JFrame myWindow; myWindow = new JFrame ( ) ; Declaration vs. Creation? Sending a message Program Components –comments, –import statements, and –class declarations.

©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Why Use Standard Classes Don’t reinvent the wheel. When there are existing objects that satisfy our needs, use them. We will introduce four standard classes here: –JOptionPane : showMessageDialog(…), –String : substring(), length(), indexOf() –Date –SimpleDateFormat.

©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter name String is an Object 1. The identifier name is declared and space is allocated in memory. 2. A String object is created and the identifier name is set to refer to it String name; name = new String(“Jon Java”); : String Jon Java name 2

©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Examples: substring String text = “Espresso”; text.substring(6,8) text.substring(0,8) text.substring(1,5) text.substring(3,3) text.substring(4,2) “so” “Espresso” “spre” error “”

©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Examples: length String str1, str2, str3, str4; str1 = “Hello” ; str2 = “Java” ; str3 = “” ; //empty string str4 = “ “ ; //one space str1.length( ) str2.length( ) str3.length( ) str4.length( )

©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Examples: indexOf String str; str = “I Love Java and Java loves me.” ; str.indexOf( “J” ) str2.indexOf( “love” ) str3. indexOf( “ove” ) str4. indexOf( “Me” )

©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Examples: concatenation String str1, str2; str1 = “Jon” ; str2 = “Java” ; str1 + str2 str1 + “ “ + str2 str2 + “, “ + str1 “Are you “ + str1 + “?” “JonJava” “Java, Jon” “Are you Jon?”

©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Date The Date class from the java.util package is used to represent a date. When a Date object is created, it is set to today (the current date set in the computer) The class has toString method that converts the internal format to a string. SimpleDateFormat: for formatting date options JOptionPane for Input: String name; name = JOptionPane.showInputDialog (null, “What is your name?”);

©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Problem Statement Problem statement: Write a program that asks for the user’s first, middle, and last names and replies with their initials. Example: input: Andrew Lloyd Weber output: ALW

©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Overall Plan Identify the major tasks the program has to perform. Tasks: –Get the user’s first, middle, and last names –Extract the initials and create the monogram –Output the monogram This is given in the textbook. Let us do an in-class demo of a program titled “ Parser.java”.