©2004 Brooks/Cole Chapter 1: Getting Started Sections Covered: 1.1Introduction to Programming 1.2Constructing a Java Program 1.3The print() and println()

Slides:



Advertisements
Similar presentations
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 2 Getting Started with Java Program development.
Advertisements

IT151: Introduction to Programming
Objectives You should be able to describe: Introduction to Programming
Lecture 2 Introduction to C Programming
Chapter 1 Getting Started
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Chapter 1: Introduction
Introduction To Computers and Programming Lecture 2: Your first program Professor: Evan Korth New York University.
©2004 Brooks/Cole Chapter 6 Methods. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Using Methods We've already seen examples of using methods.
Slides prepared by Rose Williams, Binghamton University Chapter 1 Getting Started 1.1 Introduction to Java.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 2 Getting Started with Java Structure of.
Computers: Tools for an Information Age
 2003 Prentice Hall, Inc. All rights reserved. Customized by Sana Odeh for the use of this class. 1 Introduction to Computers and Programming in JAVA.
Chapter 16 Programming and Languages: Telling the Computer What to Do.
1 Programming & Programming Languages Overview l Machine operations and machine language. l Example of machine language. l Different types of processor.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
1. 2 Chapter 1 Introduction to Computers, Programs, and Java.
Copyright 2013 by Pearson Education Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading:
1 Building Java Programs Chapter 1: Introduction to Java Programming These lecture notes are copyright (C) Marty Stepp and Stuart Reges, They may.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Java Programs COMP 102 #3.
Introducing Java.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Chapter 2 How to Compile and Execute a Simple Program.
Chapter 1: Creating Java Programs
Chapter 2 Overview of C Part I J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National Taipei University.
Introduction to Java Thanks to Dan Lunney (SHS). Java Basics File names The “main” method Output to screen Escape Sequence – Special Characters format()
Chapter 1 CSIS-120: Java Intro. What is Programming?  A: It is what makes computer so useful.  The flexibility of a computer is amazing  Write a term.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 2 Input,
Chapter 1: Introduction to Programs, and Java 1. Objectives To review programs (§ ). To understand the relationship between Java and the World Wide.
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
Java Programming, Second Edition Chapter One Creating Your First Java Program.
1 2. Program Construction in Java Programming Fundamentals.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
Chapter 1 Section 1.1 Introduction to Java Slides prepared by Rose Williams, Binghamton University Kenrick Mock, University of Alaska Anchorage.
FIRST JAVA PROGRAM. JAVA PROGRAMS Every program may consist of 1 or more classes. Syntax of a class: Each class can contain 1 or more methods. public.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Introduction to programming in the Java programming language.
8/31: Intro to Java, Languages, and Environments Types of programming languages –machine languages –assembly languages –high-level languages Java environment.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
© 2004 Pearson Addison-Wesley. All rights reserved ComS 207: Programming I Instructor: Alexander Stoytchev
JAVA Practical Creating our first program 2. Source code file 3. Class file 4. Understanding the different parts of our program 5. Escape characters.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
Introducing Java Chapter 3 Review. Why Program in Java? Java, is an object-oriented programming language. OOP languages evolved out of the need to better.
ITP 109 Week 2 Trina Gregory Introduction to Java.
© Peter Andreae Java Programs COMP 102 # T1 Peter Andreae Computer Science Victoria University of Wellington.
1/16: Intro to Java, Languages, and Environments Types of programming languages –machine languages –assembly languages –high-level languages Java environment.
Chapter 3 Introducing Java. Objectives and Goals 1. Define terminology associated with object- oriented programming. 2. Explain why Java is a widely used.
Microsoft Visual Basic 2012: Reloaded Fifth Edition Chapter One An Introduction to Visual Basic 2012.
SUMMARY OF CHAPTER 2: JAVA FUNDAMENTS STARTING OUT WITH JAVA: OBJECTS Parts of a Java Program.
Java Programming Fifth Edition Chapter 1 Creating Your First Java Classes.
Introduction to 1. What is Java ? Sun Microsystems Java is a programming language and computing platform first released by Sun Microsystems in The.
Copyright 2010 by Pearson Education APCS Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading:
STRUCTURED PROGRAMMING Complete C++ Program. Content 2  Main Function  Preprocessor directives  User comments  Escape characters  cout statement.
Topics Designing a Program Input, Processing, and Output
Chapter 6 JavaScript: Introduction to Scripting
Chapter 3 GC 101 Java Fundamentals.
Intro to PHP & Variables
Chapter 1 Introduction to Computers, Programs, and Java
Fundamentals of Programming
Introduction CSC 111.
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Computer Programming-1 CSC 111
Instructor: Alexander Stoytchev
Presentation transcript:

©2004 Brooks/Cole Chapter 1: Getting Started Sections Covered: 1.1Introduction to Programming 1.2Constructing a Java Program 1.3The print() and println() Methods 1.4Programming Style 1.5Creating a Dialog Box

Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Programming Computer hardware by itself doesn't do anything Software in the form of a program tells the computer what to do –Low-level programs are written in the processor's language of 0s and 1s –High-level programming languages are easier for people to understand

Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Programs process data A typical program does three things 1.Get some input data 2.Transform the input data to produce a result 3.Output the result

Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 The Two Distinct Java Environments

Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Sample java Programs DisplayHelloWorld.java –A console application HelloDisplay.java –Graphical (windowed) applications HelloApplet.java –An Applet is a program that is run by a web browser

Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Algorithms Before you can tell the computer what to do, you have to figure out how to do what needs to be done. An algorithm is a step-by-step procedure describing what needs to be done. Two ways to describe an algorithm –Pseudocode - use words to describe the process –Flowcharts

Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Algorithms for Summing the Numbers from 1 through 100

Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Flowchart Symbols

Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Flowchart for Calculating the Average of Three Numbers

Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 A Simple Paint-by-Number Figure

Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Coding an Algorithm Once you have a correct algorithm, writing the program is easy.

Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Object-Oriented Programming Java is an object-oriented language In object-oriented programs we use classes and objects to help organize our program Objects have –Data –Behavior A class defines what the data and behavior should be for a particular kind of object

Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Using UML Diagrams Pictures can be easier to understand than large amounts of text UML is a diagram language for describing object-oriented programs There are many different kinds of diagrams –We'll use only a few of them

Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 The Rectangle Class Suppose we have a class to represent a rectangle. –The properties of a rectangle are the length and width –From these we can determine the area or the perimeter –We should be able to change the properties –We might want to dispplay the properties

Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 A Set of Rectangle Objects Once the Rectangle class is defined, you can create rectangle objects Each Rectangle has its own value of length and width

Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Sending a Message to a Rectangle Object We can send a message to a Rectangle object In this case, the object replies to our message by sending back the area

Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 The Traditional Translation Process From code to executable Program code is written in a high-level language A processor understands binary code (0s and 1s) A program needs to be translated from high-level code to the low- level code that the computer understands

Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Compiling and Executing a Java Program Java works a little differently 1.Convert high-level code to byte-code 2.Use another program to execute the byte-code Under Linux 1.javac converts source code into byte code Result has extension.class 2.java executes the byte-code file

Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Constructing a Java Program Every Java program consists of one or more classes One class must be a main class –The main class must contain a method called main

Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 A Simple Java Program

Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Class Header public class Hello public - modifier specifying visibility of the class class - keyword that is part of the Java syntax for creating a class Hello - an identifier used to name the class

Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Method Header public static void main( String[] args) public - modifier specifying visibility of the method static - modifier specifying class method void - keyword specifying no return value main - an identifier used to name the method (String[] args) - parameter list

Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 A Well-Designed Program Is Built Using Modules

Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Modules We use classes to construct modules in Java Within a class, methods can be used to modularize functionality –If you have some operation that is done in several different places, make a method

Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Keywords and Identifiers Keywords are words that have special meaning in the java language –Keywords are reserved; they can't be used as names –Keywords need to appear in the correct context Identifiers are used for naming things –Objects, classes, methods all need names –Rules for naming First character must be letter or underscore (_) Remaining characters can be letters, digits or underscore

Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Syntax Syntax is the rules that specify how the words in your program can be arranged. Programming language syntax is simpler that natural language syntax. –Because it has to be translated by a program - programs are less flexible than people

Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Output to the Console Most of our programs will be console applications –Output appears on the console The System class has an object called out that you use to send output to the console –out is a PrintStream object –PrintStream has two methods that send text to the console print( text) println( text)

Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 print and println Text output with print starts at the current cursor position and continues until the text ends Text output with println start starts at the current cursor position and continues until the text ends and then appends a newline –Next output will appear at the beginning of the next line.

Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Escape sequences What if you need to make a single String extend over more than one line? –Text enclosed in double quotes needs to fit on a single line in your program. Typing return breaks it onto two lines. The backslash (\) character is used for representing characters that you can't just type. –\n is the newline character –\" allows you to put double quotes in a double-quoted string –\\ allows you to put a backslash in your string

Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Programming Style The java compiler doesn't care how many lines you use for your program statements The people who have to read your code will find it easier if you format it nicely. Look at the examples in the book for one common formatting style Sun has a recommended style for Java programs

Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Comments We often need to put text into a program to help explain the code –We call this kind of text comments –We want the compiler to ignore comments Java has three types of comment 1.// starts a one-line comment 2./* … */ encloses multiline comments 3./** … */ encloses javadoc comments

Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Dialog Boxes The JOptionPane class has several class methods for creating common dialog boxes. showMessageDialog is used for providing information to the user of a GUI program Creating GUI programs entirely out of dialog boxes is rather tedious for the user.

Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 showMessageDialog() Dialog Boxes WARNING_MESSAGEQUESTION_MESSAGE PLAIN_MESSAGE ERROR_MESSAGEINFORMATION_MESSAGE

Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 The Dialog Produced by MultiLineDialog.java