Lecture 2 Software Concepts Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung Institute of Technology.

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
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.
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.
Prepared by Uzma Hashmi Instructor Information Uzma Hashmi Office: B# 7/ R# address: Group Addresses Post message:
1 Course Lectures Available on line:
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 (
Java Building Elements Lecture 2 Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung University
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
System development with Java Lecture 2. Rina Errors A program can have three types of errors: Syntax and semantic errors – called.
© 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.
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
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 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
Chapter 2: Java Fundamentals
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
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.
© 2004 Pearson Addison-Wesley. All rights reserved ComS 207: Programming I Instructor: Alexander Stoytchev
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.
ZObject-Oriented Software Development yproblem solving yprogram design and implementation yobject-oriented concepts xobjects xclasses xinterfaces xinheritance.
Intro to Programming  Chapter 1 Part 2  Problem Solving.
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.
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.
Lecture 2: Data Types, Variables, Operators, and Expressions
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
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
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
Instructor: Alexander Stoytchev
Presentation transcript:

Lecture 2 Software Concepts Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung Institute of Technology

Outline Structure of Java standalone applications Basic program elements Executing a program Helpful support for writing software Java applets

Java Program Structure 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 class Lincoln { public static void main (String[] args) { System.out.println ("Whatever you are, be a good one."); } // method main } // class Lincoln

Java Program Structure White Space white space: Spaces, blank lines, and tabs. White space is used to separate words and symbols (tokens) in a program Extra white space is ignored. A valid Java program can be formatted many different ways: class Lincoln2 { public static void main (String[] args) { System.out.println ("Whatever you are, be a good one."); } } Readability: consistent indentation

Java Program Structure: Comments Comments: same syntax as C/C++. One-line comment: // // comment runs to the end of the line Multiple-line comment: /* comment runs to terminating * symbol, even across line breaks */

Java Program Structure: Indentifiers Identifiers: class name, method name, variables, key words. 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 Program Structure: Indentifiers Identifiers in Lincoln.java: class name: Lincoln method name: main, System.out.println variables: args key words: String

Good Programming Practice Naming Conventions: Classes: first word capitalized Methods and variables: first word lower case Intermediate words capitalized Words run together, no underscores class IntegerList (X Integer_List) int listItem (X list_Item) Constant: all caps with underscores to separate words MAX_INTEGER_ARRAY

Java Program Structure: Reserved words 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 Program Structure: Literals Integer literals: Floating point literals: String literals: "The result is: " "To thine own self be true."

Java Program Structure Java API The Java Application Programmer Interface (API) is a collection of classes that can be used as needed Java API: print and println; Java APIs are not part of the Java language itself. 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 Program Structure Operator overloading (+ ) String concatenation: String + String String concatenation: String + numeric data addition: numeric data + numeric data class Sum { public static void main (String[] args) { System.out.println ("6 + 9 = " + (6+9)); System.out.print (" Java " + " Programming"); System.out.println ("for Antarctica is " + 672); } // method main } // class Sum

Program Languages Traditional programming languages: A. high-level languages ==> machine languages B. Each CPU has its own specific machine language The Java compiler translates Java source code into a special representation called bytecode Java bytecode is not the machine language for any traditional CPU Java interpreter translates bytecode into machine language and executes it.

Java Translation and Execution Standalone applications: Java source code Machine code Java bytecode Java interpreter Bytecode compiler Java compiler

Java Translation and Execution Applet Java source code Java bytecode Java compiler Java interpreter Web browser local computer remote computer

Java Translation and Execution compiling Java programs into bytecodes: > javac Lincoln.java The bytecode of Lincoln.java is Lincoln.class Java interpreter (Java Virtual Machines): > java Lincoln

Errors: A program can have three types of errors: A. compile-time errors: syntax errors. B. run-time errors: divide by zero C. logical errors: incorrect results.

Object-Oriented Programming: Everything is an object. Programs are made from objects Each object has its own memory made up of other objects. Objects communication: send messages (requests). An object contains data and methods An object is defined by a class (type) Multiple objects can be created from the same class

Object-Oriented Programming: A class (type) represents a concept and An object (instance) represents the realization of that concept. Car My first car John's car Dad's car Class Objects

Object-Oriented Programming: An object contains data and methods. Composition: (reuse objects): Ex, A car has a engine. Car drive(); start(); etc... engine wheel[4] door[2] etc... Class Methods Data

Object-Oriented Programming: Objects communication: send messages. Object1 Object2 Object3 message

Object-Oriented Programming: Inheritance: reuse the interface. Shape draw(); erase(); Line draw(); erase(); Circle draw(); erase(); Square draw(); erase();

Object-Oriented Programming: Polymorphism (dynamic binding). shape.draw() will call the right draw function of circle line or square. ShapeLine Circle draw(); erase(); Square

Dynamic Binding void doStuff(Shape s) { s.erase(); //... s.draw(); } / /... Circle c = new Circle(); Triangle t = new Triangle(); Line l = new Line(); doStuff(c); doStuff(t); doStuff(l);

Importing Packages Using a class from the Java API: fully qualified name: java.lang.System.out.println(); import statement:: import java.applet.*; import java.util.Random; …. Random coin = new Random(); The java.lang package: automatically imported into every Java program

Conclusions Simple Structure of Java: classes Object-oriented concepts Import statement 完成 Lecture 2 休息十分鐘!