Java Software Solutions Lewis and Loftus Chapter 2 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Software Concepts -- Introduction.

Slides:



Advertisements
Similar presentations
Chapter 1: Computer Systems
Advertisements

Programming Languages
Programming with Java. Problem Solving The purpose of writing a program is to solve a problem The general steps in problem solving are: –Understand the.
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
1 Kursusform  13 uger med: Undervisning i klassen 1,5-2 timer Opgave ”regning” i databar (løsninger på hjemmeside) En midtvejsopgave der afleveres og.
The Java Programming Language
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Outline Java program structure Basic program elements
Introduction to Java CS 331. Introduction Present the syntax of Java Introduce the Java API Demonstrate how to build –stand-alone Java programs –Java.
Chapter 1 Introduction. © 2004 Pearson Addison-Wesley. All rights reserved1-2 Outline Computer Processing Hardware Components Networks The Java Programming.
COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis.
Chapter 1 Introduction.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Chapter 1 Introduction.
Prepared by Uzma Hashmi Instructor Information Uzma Hashmi Office: B# 7/ R# address: Group Addresses Post message:
Chapter 1 Programming Languages. Application Development: Top 10 Programming Languages to Keep You Employed 1. Java 2. C# 3. C++ 4. JavaScript 5. Visual.
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley John Lewis, Peter DePasquale, and Joseph Chase Chapter 1: Introduction.
© 2006 Pearson Education Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science A 2nd Edition.
Java: Chapter 1 Computer Systems Computer Programming II.
Java Language and SW Dev’t
© 2006 Pearson Education 1 Obj: cont 1.3 and 1.4, to become familiar with identifiers and to understand how programming languages work HW: p.51 #1.8 –
1 Introduction zNow we can begin to examine the basic ideas behind writing programs zLecture 1 focuses on: ythe structure of a Java application ybasic.
1 Computer Systems -- Introduction  Chapter 1 focuses on:  the structure of a Java application  basic program elements  preparing and executing a program.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
The Java Programming Language
CSC204 – Programming I Lecture 4 August 28, 2002.
Introduction. Objectives An overview of object-oriented concepts. Programming and programming languages An introduction to Java 1-2.
Lecture 2 Object Oriented Programming Basics of Java Language MBY.
Introduction to Computer Systems and the Java Programming Language.
C Derived Languages C is the base upon which many build C++ conventions also influence others *SmallTalk is where most OOP comes Java and Javascript have.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Chapter 2: Java Fundamentals
Chapter 1: Introduction Java Programming Language How the Java Virtual Machine Works (compiling, etc…) Update by: Dan Fleck Coming up: The Java Programming.
Java The Java programming language was created by Sun Microsystems, Inc. It was introduced in 1995 and it's popularity has grown quickly since A programming.
Introduction to Java Java Translation Program Structure
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
© 2004 Pearson Addison-Wesley. All rights reserved ComS 207: Programming I Instructor: Alexander Stoytchev
Lecture 2 Software Concepts Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung Institute of Technology.
1 Problem Solving b The purpose of writing a program is to solve a problem b The general steps in problem solving are: Understand the problemUnderstand.
White Space Spaces, blank lines, and tabs are collectively called white space and are used to separate words and symbols in a program Extra white space.
Intro to Programming  Chapter 1 Part 2  Problem Solving.
Java Software Solutions Lewis and Loftus Chapter 9 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Enhanced Class Design -- Introduction.
Java Software Solutions Lewis and Loftus Chapter 2 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Software Concepts -- Introduction.
Chapter 1 Introduction. 2 Focus of the Course Object-Oriented Software Development problem solving program design, implementation, and testing object-oriented.
WEEK 2 1 Software Concepts -- Introduction Now we can begin to examine the basic ideas behind writing programs Chapter 2 focuses on: history.
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 1: Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science.
Introduction to Java Programming by Laurie Murphy Revised 09/08/2016.
Copyright 2010 by Pearson Education APCS Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading:
1 Problem Solving  The purpose of writing a program is to solve a problem  The general steps in problem solving are: Understand the problem Dissect the.
JAVA MULTIPLE CHOICE QUESTION.
Working with Java.
University of Central Florida COP 3330 Object Oriented Programming
1.3 Problem Solving The purpose of writing a program is to solve a problem The general steps in problem solving are: Understand the problem Dissect the.
Unit 41 – Programing in Java
Starting JavaProgramming
null, true, and false are also reserved.
Introduction to Java Programming
An overview of Java, Data types and variables
Chapter 1: Computer Systems
Units with – James tedder
Units with – James tedder
JavaScript Reserved Words
Java Software Solutions Foundations of Program Design 9th Edition
Focus of the Course Object-Oriented Software Development
Chap 2. Identifiers, Keywords, and Types
Chap 1. Getting Started Objectives
Chap 4. Programming Fundamentals
Agenda Types and identifiers Practice Assignment Keywords in Java
Presentation transcript:

Java Software Solutions Lewis and Loftus Chapter 2 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Software Concepts -- Introduction Now we can begin to examine the basic ideas behind writing programs Chapter 2 focuses on: –the structure of a Java application –basic program elements –preparing and executing a program –basic object-oriented programming concepts –helpful support for writing software –Java applets

Java Software Solutions Lewis and Loftus Chapter 2 2 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Java Program Structure See Lincoln.java A program is made up of one or more classes A class contains one or more methods A method contains program statements A Java application always executes the main method

Java Software Solutions Lewis and Loftus Chapter 2 4 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Comments Comments in a program are also called inline documentation They should be included to explain the purpose of the program and describe processing steps Java comments can take two forms: // comment runs to the end of the line /* comment runs to terminating symbol, even across line breaks */

Java Software Solutions Lewis and Loftus Chapter 2 5 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Identifiers Identifiers are the words a programmer uses in a program Most identifiers have no predefined meaning except as specified by the programmer An identifier can be made up of letters, digits, the underscore character (_), and the dollar sign They cannot begin with a digit Java is case sensitive, therefore Total and total are different identifiers

Java Software Solutions Lewis and Loftus Chapter 2 6 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Reserved Words Some identifiers, called reserved words, have specific meanings in Java and cannot be used in other ways abstract boolean break byte byvalue case cast catch char class const continue default do double else extends false final finally float for future generic goto if implements import inner instanceof int interface long native new null operator outer package private protected public rest return short static super switch synchronized this throw throws transient true try var void volatile while

Java Software Solutions Lewis and Loftus Chapter 2 8 Copyright 1997 by John Lewis and William Loftus. All rights reserved. The Java API The Java Application Programmer Interface (API) is a collection of classes that can be used as needed The println and print methods are part of the Java API; they are not part of the Java language itself Both methods print information to the screen; the difference is that println moves to the next line when done, but print does not See Countdown.java

Java Software Solutions Lewis and Loftus Chapter 2 9 Copyright 1997 by John Lewis and William Loftus. All rights reserved. String Concatenation and Addition The + operator serves two purposes When applied to two strings, they are combined into one (string concatenation) When applied to a string and some other value (like a number), that value is converted to a string and they are concatenated When applied to two numeric types, they are added together arithmetically See Antarctica.java and Sum.java

Java Software Solutions Lewis and Loftus Chapter 2 10 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Programming Languages There are four basic programming language levels: –machine language –assembly language –high-level language –fourth-generation language Each CPU has its own specific machine language The other levels were created to make programming easier

Java Software Solutions Lewis and Loftus Chapter 2 11 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Programming Languages A program must be translated into machine language before it can be executed on a particular type of CPU This can be accomplished in several ways A compiler is a software tool which translates source code into a specific target language Often, that target language is the machine language for a particular CPU type The Java approach is somewhat different

Java Software Solutions Lewis and Loftus Chapter 2 12 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Java Translation and Execution The Java compiler translates Java source code into a special representation called bytecode Java bytecode is not the machine language for any traditional CPU Another software tool, called an interpreter, translates bytecode into machine language and executes it Therefore the Java compiler is not tied to any particular machine Java is considered to be architecture-neutral

Java Software Solutions Lewis and Loftus Chapter 2 13 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Java Translation and Execution Java source code Machine code Java bytecode Java interpreter Bytecode compiler Java compiler

Java Software Solutions Lewis and Loftus Chapter 2 14 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Java Translation and Execution Executing the compiler in a command line environment: > javac Lincoln.java This creates a file called Lincoln.class, which is submitted to the interpreter to be executed: > java Lincoln The.java extension is used at compile time, but the.class extension is not used with the interpreter Other environments do this processing in a different way

Java Software Solutions Lewis and Loftus Chapter 2 17 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Command Line Arguments See Name_Tag.java The main method accepts extra information on the command line when a program is executed > java Name_Tag John Each extra value is called command line argument In Java, command line arguments are always read as a list of character strings

Java Software Solutions Lewis and Loftus Chapter 2 18 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Software Engineering We should always strive to engineer our software to make it reliable and maintainable As the complexity of a program increases, its cost to develop and revise grows exponentially cost complexity

Java Software Solutions Lewis and Loftus Chapter 2 19 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Software Components Programs are easier to construct and modify when they are made up of separate components A software component can be thought of as any program element that transforms input into output Input Output Component Compute average

Java Software Solutions Lewis and Loftus Chapter 2 20 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Software Components Components can be combined to make larger components

Java Software Solutions Lewis and Loftus Chapter 2 21 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Object-Oriented Programming Java is object-oriented language Programs are made from software components called objects An object contains data and methods An object is defined by a class Multiple objects can be created from the same class

Java Software Solutions Lewis and Loftus Chapter 2 22 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Object-Oriented Programming A class represents a concept and an object represents the realization of that concept Car My first car John's car Dad's car Class Objects

Java Software Solutions Lewis and Loftus Chapter 2 23 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Object-Oriented Programming Objects can also be derived from each other using a process called inheritance Objects, classes, and inheritance will be discussed in greater detail later Vehicle TrainCarAirplane

Java Software Solutions Lewis and Loftus Chapter 2 24 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Class Libraries The Java API is a class library, a group of classes that support program development Classes in a class hierarchy are often related by inheritance The classes in the Java API is separated into packages The System class, for example, is in package java.lang Each package contains a set of classes that relate in some way

Java Software Solutions Lewis and Loftus Chapter 2 25 Copyright 1997 by John Lewis and William Loftus. All rights reserved. The Java API Packages Some packages in the Java API: java.applet java.awt java.beans java.io java.lang java.math java.net java.rmi java.security java.sql java.text java.util

Java Software Solutions Lewis and Loftus Chapter 2 26 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Importing Packages Using a class from the Java API can be accomplished by using its fully qualified name: java.lang.System.out.println (); Or, the package can be imported using an import statement, which has two forms: import java.applet.*; import java.util.Random; The java.lang package is automatically imported into every Java program

Java Software Solutions Lewis and Loftus Chapter 2 27 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Java Applets A Java applet is a Java program that is intended to be sent across a network and executed using a Web browser A Java application is a stand alone program Applications have a main method, but applets do not Applets are derived from the java.applet.Applet class See Confucius.java and No_Parking.java Links to applets can be embedded in HTML documents

Java Software Solutions Lewis and Loftus Chapter 2 28 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Java Applets Java source code Java bytecode Java compiler Java interpreter Web browser local computer remote computer