Download presentation
Published byBailey Carney Modified over 11 years ago
1
Designing a Program & the Java Programming Language
Mrs. Butera
2
What is a Program? A program is a set of instructions a computer follows in order to perform a task. A programming language is a special language used to write computer programs.
3
Machine Language
4
Modern Programming Languages
5
Examples of Programming Languages
BASIC FORTRAN COBOL Pascal C C++ Java JavaScript Perl Python Ruby Visual Basic
6
History of Java Developed by Sun Microsystems in 1991
Goal: Develop a language that could be processed by all the devices it controlled – not dependent upon the processor each with its own machine language Used in: Stand-alone applications Applets for the Internet and devices
7
Security Can Java applets corrupt your computer? NO!
Web browsers run Java applets in a secure environment within your computer's memory and do not allow them to access any of your computer's resources
8
BEFORE you write the Program, you conceive:
The Algorithm & sometimes a Flowchart
9
The algorithm is conceived before the program is written.
What is an Algorithm? The set of well-defined steps that are given to the computer to perform a task or solve a problem. The algorithm is conceived before the program is written.
10
Example: Gross Pay Algorithm
Display: “How many hours did you work?” Allow user to input hours worked – store the number in memory Display: “How much do you get paid per hour?” Allow user to input pay per hour and store the number in memory Calculate Gross pay = Hours_Worked x Pay_Per_Hour Display the Gross Pay
11
Flowchart Symbols
12
Gross Pay Flowchart Start Input Hours Input Pay Per Hour Calculate
Output Gross Pay Start
13
What is a Program Made of?
Vocabulary – the set of all words and symbols in the language. Syntax – rules for combine words into sentences or statements. Semantics – define the rules for interpreting the meaning of statements
14
Program Enhancements White Space and Indentation – for readability
Comments – for maintenance purposes /*comment area */ // entire line
15
Sample First Java Program “Hello World”
// This is the classic first Java program class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } Save As: HelloWorld.java
16
Key Words/Reserved Words
Every programming language has reserved words that cannot be used as variable names When you compile your program, an error will be returned if you use a reserved word incorrectly
17
Key Words/Reserved Words
public class Payroll { public static void main(String[] args) Int hours = 40; double grossPay, payRate = 25.0; grossPay = hours * payRate; System.out.println(“Your gross pay is $” + grossPay); }
18
Some Java Vocabulary Type of Element Examples + - * /
Arithmetic operators + - * / Assignment operator = Numeric literals Programmer defined variable name name, pay_per_hour, gross_pay
19
Invalid Program Syntax
Answer = (F - 32) * / 9; Answer = )F - 32 ( * 5 / 9; Answer = F – 32) * 5 / 9; Answer = (F - 32) * 5.0 / 9.0
20
Semantics Defines the rules for interpreting the meaning of statements
Answer = (F - 32) * 5.0 / 9.0; Means “go into the parentheses first, subtract 32.0 from the variable quantity indicated by F, then multiply the result by 5.0, and finally divide the whole thing by 9.0” & store result in the variable (storage area) Answer
21
Programmer-Defined Names Variable are the names of memory locations that may hold data.
public class Payroll { public static void main(String[] args) Int hours = 40; double grossPay, payRate = 25.0; grossPay = hours * payRate; System.out.println(“Your gross pay is $” + grossPay); }
22
Operators public class Payroll {
public static void main(String[] args) Int hours = 40; double grossPay, payRate = 25.0; grossPay = hours * payRate; System.out.println(“Your gross pay is $” + grossPay); }
23
Syntax/Punctuation Marks the end of a complete sentence/statement.
public class Payroll { public static void main(String[] args) Int hours = 40; double grossPay, payRate = 25.0; grossPay = hours * payRate; System.out.println(“Your gross pay is $” + grossPay); }
24
Programs are made up of lines and statements.
25
Lines A line is just a single line as it appears in the body of a program.
public class Payroll { public static void main(String[] args) Int hours = 40; double grossPay, payRate = 25.0; grossPay = hours * payRate; System.out.println(“Your gross pay is $” + grossPay); }
26
Statements A statement is a complete instruction that causes the computer to perform some action.
public class Payroll { public static void main(String[] args) Int hours = 40; double grossPay, payRate = 25.0; grossPay = hours * payRate; System.out.println(“Your gross pay is $” + grossPay); }
27
Variables A variable is a named storage location in the computer's memory.
public class Payroll { public static void main(String[] args) Int hours = 40; double grossPay, payRate = 25.0; grossPay = hours * payRate; System.out.println(“Your gross pay is $” + grossPay); }
28
The Compiler and the Java Virtual Machine (JVM)
Source Code = the program is typed in a text editor. Source file example: Payroll.java javac Payroll.java – compiles the program - (converts source code to byte code – 3b 00 8h ff ) syntax errors may be returned java Payroll - executes the program
29
The Compiler and the Java Virtual Machine (JVM)
30
Integrated Development Environments (IDE)
Software package including: Text Editor Compiler Debugger Other utilities Examples: NetBeans Eclipse Komodo WinDev
31
The Programming Process
Clearly define what the program is to do (requirements). Visualize the program running on the computer. Use design tools to create a model of the program (algorithm, flowchart). Check the model for logical errors.
32
The Programming Process continued:
5. Enter the code and compile it. 6. Correct any errors found during compilation. Repeat steps 5 & 6 as many times as necessary. 7. Run the program with test data for input (valid & invalid data). Have someone else test it. 8. Correct any runtime errors found while running the program. Repeat steps 5 & 6 as many times as necessary. 9. Validate the results of the program.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.