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.

Slides:



Advertisements
Similar presentations
CSci 1130 Intro to Programming in Java
Advertisements

Chapter 1: Computer Systems
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.
Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
Constants and Data Types Constants Data Types Reading for this class: L&L,
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
The Java Programming Language
Outline Java program structure Basic program elements
ECE122 L3: Expression Evaluation February 6, 2007 ECE 122 Engineering Problem Solving with Java Lecture 3 Expression Evaluation and Program Interaction.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Chapter 1 Introduction. © 2004 Pearson Addison-Wesley. All rights reserved1-2 Outline Computer Processing Hardware Components Networks The Java Programming.
Chapter 1 Introduction.
String Escape Sequences
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.
Program Elements -- Introduction
Prepared by Uzma Hashmi Instructor Information Uzma Hashmi Office: B# 7/ R# address: Group Addresses Post message:
1 Variables, Constants, and Data Types Primitive Data Types Variables, Initialization, and Assignment Constants Characters Strings Reading for this class:
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
CSCI 1100/1202 January 16, Why do we need variables? To store intermediate results in a long computation. To store a value that is used more than.
1 Program Elements -- Introduction zWe can now examine the core elements of programming zLecture focuses on: ydata types yvariable declaration and use.
© 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.
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.
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.
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.
Assignment An assignment statement changes the value of a variable The assignment operator is the = sign total = 55; Copyright © 2012 Pearson Education,
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.
CSCI 1100/1202 April 1-3, Program Development The creation of software involves four basic activities: –establishing the requirements –creating.
Programming in Java (COP 2250) Lecture 4 Chengyong Yang Fall, 2005.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Java Software Solutions Lewis and Loftus Chapter 2 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Software Concepts -- Introduction.
1 Program Development  The creation of software involves four basic activities: establishing the requirements creating a design implementing the code.
1 b Boolean expressions b truth tables b conditional operator b switch statement b repetition statements: whilewhile do/whiledo/while forfor Lecture 3.
WEEK 2 1 Software Concepts -- Introduction Now we can begin to examine the basic ideas behind writing programs Chapter 2 focuses on: history.
Design A software design specifies how a program will accomplish its requirements A design includes one or more algorithms to accomplish its goal.
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 1: Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science.
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.
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
Working with Java.
Chapter 4 Assignment Statement
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
Multiple variables can be created in one declaration
Variables and Arithmetic Operators in JavaScript
Chapter 3 Assignment Statement
Starting JavaProgramming
Chapter 3: Program Statements
Introduction to Java Programming
An overview of Java, Data types and variables
Chapter 1: Computer Systems
Chapter 3: Program Statements
Units with – James tedder
Units with – James tedder
Focus of the Course Object-Oriented Software Development
Chap 2. Identifiers, Keywords, and Types
Chap 1. Getting Started Objectives
Chap 4. Programming Fundamentals
3.0 - Design A software design specifies how a program will accomplish its requirements A design includes one or more algorithms to accomplish its goal.
Presentation transcript:

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 is ignored A valid Java program can be formatted many different ways Programs should be formatted to enhance readability, using consistent indentation

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 */

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 TotalJava is case sensitive, therefore Total and total are different identifiers

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

Literals A literal is an explicit data value used in a program Integer literals: Floating point literals: String literals: "The result is: " "To thine own self be true."

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

Errors A program can have three types of errors The compiler will find problems with syntax and other basic issues (compile- time errors) If compile-time errors exist, an executable version of the program is not created A problem can occur during program execution, such as trying to divide by zero, which causes a program to terminate abnormally (run-time errors) A program may run, but produce incorrect results (logical errors)

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

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

Object-Oriented Programming A class represents a concept and an object represents the realization of that concept Car Class Objects

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

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

The Java API Packages Some packages in the Java API: java.applet java.awt java.beans java.io java.security java.sql java.lang java.math java.net java.rmi java.text java.util java.lang package: free gift

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

Primitive Data Types A data type is defined by a set of values and the operators you can perform on them Each value stored in memory is associated with a particular data type The Java language has several predefined types, called primitive data types. The following reserved words represent eight different primitive types: –byte, short, int, long, float, double, boolean, char

Integers There are four separate integer primitive data types They differ by the amount of memory used to store them Type byte short int long Storage 8 bits 16 bits 32 bits 64 bits Min Value ,768 -2,147,483,648 9 x 1018

Boolean A boolean value represents a true or false condition They can also be used to represent any two states, such as a light bulb being on or off The reserved words true and false are the only valid values for a boolean type

Characters The ASCII character set is still the basis for many other programming languages ASCII is a subset of Unicode, including: –uppercase letters –lowercase letters –punctuation digits special symbols control characters A, B, C, … a, b, c, … period, semi-colon, … 0, 1, 2, … &, |, \, … carriage return, tab,...

Wrappers For each primitive data type there is a corresponding wrapper class. For example: Wrapper classes are useful in situations where you need an object instead of a primitive type They also contain some useful methods Primitive Type int double char boolean Wrapper Class Integer Double Character Boolean

Numeric Input Converting a string that holds an integer into the integer value can be done with a method in the Integer wrapper class: value=Integer.parseInt(my_string); A value can be read and converted in one line: num= Integer.parseInt (stdin.readLine());

Expressions An expression is a combination of operators and operands – The arithmetic operators include addition (+), subtraction (-),multiplication (*), and division (/) – Operands can be literal values, variables, or other sources of data –The programmer determines what is done with the result of an expression (stored, printed, etc.)

Operator Precedence The order in which operands are evaluated in an expression is determined by a well-defined precedence hierarchy Operators at the same level of precedence are evaluated according to their associativity (right to left or left to right) Parentheses can be used to force precedence Appendix D contains a complete operator precedence chart for all Java operators

The if Statement The Java if statement has the following syntax: if (condition) statement; If the boolean condition is true, the statement is executed; if it is false, the statement is skipped This provides basic decision making capabilities

Block Statements Several statements can be grouped together into a block statement – Blocks are delimited by braces – A block statement can be used wherever a statement is called for in the Java syntax

The if-else Statement An else clause can be added to an if statement to make it an if-else statement: if (condition) statement1; else statement2; If the condition is true, statement1 is executed; if the condition is false, statement2 is executed See Temperature3.java and Right_Triangle.java

Nested if Statements The body of an if statement or else clause can be another if statement These are called nested if statements See Football_Choice.java Note: an else clause is matched to the last unmatched if (no matter what the indentation implies)

The while Statement A while statement has the following syntax: while (condition) statement; If the condition is true, the statement is executed; then the condition is evaluated again The statement is executed over and over until the condition becomes false

The while Statement If the condition of a while statement is false initially, the statement is never executed Therefore, we say that a while statement executes zero or more times

Infinite Loops The body of a while loop must eventually make the condition false If not, it is an infinite loop, which will execute until the user interrupts the program This is a common type of logical error -- always double check that your loops will terminate normally See Forever.java

Program Development The creation of software involves four basic activities: – establishing the requirements – creating a design – implementing the code – testing the implementation The development process is much more involved that this, but these basic steps are a good starting point

Requirements Requirements specify the tasks a program must accomplish (what to do, not how to do it) –They often address the user interface –An initial set of requirements are often provided, but usually must be critiqued, modified, and expanded –It is often difficult to establish detailed, unambiguous, complete requirements –Careful attention to the requirements can save significant time and money in the overall project

Design A program follows an algorithm, which is a step-by-step process for solving a problem The design specifies the algorithms and data needed In object-oriented development, it establishes the classes, objects, and methods that are required The details of a method may be expressed in pseudo-code, which is code-like, but does not necessarily follow any specific syntax

Implementation Implementation is the process of translating a design into source code Most novice programmers think that writing code is the heart of software development, but it actually should be the least creative Almost all important decisions are made during requirements analysis and design Implementation should focus on coding details, including style guidelines and documentation

Testing A program should be executed multiple times with various input in an attempt to find errors Debugging is the process of discovering the cause of a problem and fixing it Programmers often erroneously think that there is "only one more bug" to fix Tests should focus on design details as well as overall requirements