CSE 1340 Class 3. Class 03 objectives State the difference between Machine Language vs. High Level...
-
Upload
preston-sharp -
Category
Documents
-
view
216 -
download
0
Transcript of CSE 1340 Class 3. Class 03 objectives State the difference between Machine Language vs. High Level...
Class 03 objectivesClass 03 objectives State the difference between Machine Language vs. High
Level Languages Discuss some characteristics of the Java language Write an algorithm Differentiate between the compilation and execution
processes of a program Understand the purpose of using a compiler Gain an elementary understanding of object-oriented
programming
Evolution of computer languagesEvolution of computer languages Machine language
– Characterized by binary ones and zeroes Low-level assembly languages
– Characterized by mnemonic codes High-level languages
– English-like Very-high level languages
– Results instead of procedural oriented Natural languages
– Conversational
What Is Java?What Is Java?
High-level languageObject-oriented
– Data and operations are packaged into a single unit called an object
Basic syntax derived from C, C++, and Smalltalk– Designed by a team from Sun
Microsystems led by James Gosling in the early 1990’s
What Is Java?What Is Java?
Parsimonious– Compatible with older versions
Robust– Strongly typed and incorruptible data
Secure– Protection against misuse of code
Portable– Platform-independent
What Is the Java SDK?What Is the Java SDK?
The Java Software Development Kit (SDK) is a programming package to develop Java applications
The Java Runtime Environment (JRE) provides the tools to deploy Java applications
Features of the J2SEFeatures of the J2SE
The Java Compiler– Converts code into bytecode
The Java Virtual Machine – Contains an interpreter to execute the
bytecode
The Java API– The standard set of packages available in Java
The Java Applet Viewer– Mini browser to display Java applets
Any Java Compiler that is compatible with the
Java 2 Platform 6.0 (J2SE 6.0)
Please see your Blackboard homepage for link to free download of Sun Microsystems J2SE 6.0
If you use J2SE 6.0, it is a command line interface. In other words, there is no User Interface to work with. Programs have to be entered into a text editor, saved and then compiled through commands at a command prompt. Instructions for doing so are in a link on your Blackboard homepage.
Your textbook also comes with a CD that includes Textpad that make coding a little easier. See textbook for installation.
See also the link on your Blackboard homepage for instructions on using the NetBeans platform as another option.
Java Virtual MachineJava Virtual Machine
JVM
Java Source code .java
Java byte-code .class
Environment
Java VMjavac java
JIT CompilerJIT Compiler
JIT- takes byte-codes and change it to machine code.
JVMRunning
Applet or Application
J.I.T.Compiler
.class file
machine code
Java Program TypesJava Program Types
Console and Windowed applicationsAppletsServletsWeb ServicesJavaBeans
Windowed ApplicationsWindowed Applications
Stand-alone programs using a graphical user interface (GUI)
ServletsServlets
Server-side programs hosted and run on a Web server
Used in conjunction with Java Server Pages (JSP) to provide sophisticated server-side logic
Enable connections to server databases through Java Database Connectivity (JDBC)
Web ServicesWeb ServicesServices receive information
requests over the Web and return the requested data
Sample ProblemSample Problem
A programmer needs an algorithm to determine an employee’s weekly wages. How would the calculations be done by hand?
One Employee’s WagesOne Employee’s Wages
In one week an employee works 52 hours at the hourly pay rate of $24.75. Assume a 40.0 hour normal work week and an overtime pay rate factor of 1.5
What are the employee’s wages?40 x $ 24.75 = $ 990.00
12 x 1.5 x $ 24.75 = $ 445.50___________
$ 1435.50
If hours are more than 40.0, then
wages = (40.0 * payRate) + (hours - 40.0) * 1.5 *payRate
otherwise,
wages = hours * payRate
Weekly Wages, in GeneralWeekly Wages, in General
RECALL EXAMPLE
( 40 x $ 24.75 ) + ( 12 x 1.5 x $ 24.75 ) = $1435.50
An Algorithm is . . .An Algorithm is . . .
a step-by-step procedure for solving a problem in a finite amount of time.
Algorithm to Determine an Algorithm to Determine an Employee’s Weekly WagesEmployee’s Weekly Wages
1. Display to the screen “how many hours did you work?” 2. Input hours 3. Display to the screen “what is your rate of pay?” 4. Input rate 5. Calculate this week’s regular wages 6. Calculate this week’s overtime wages (if any) (Fill in details of how to do steps 5 and 6) 7. Add the regular wages to overtime wages (if any) to determine
total wages for the week
Translating your algorithm into a programming language is called CODING
The “code” or “program” for this algorithm is on the next screen
// A payroll program public class Payroll{ public static void main(String [] args) { double hours, rate, regularPay, overtimePay,grossPay; Scanner keyboard = new Scanner(System.in); System.out.print( "How many hours did you work?“) ; hours = keyboard.nextInt(); System.out.print( "how much were you paid per hour?“); rate = keyboard,nextInt(); if (hours <= 40) { regularPay = hours * rate; overtimePay = 0.0; } else { regularPay = 40 * rate; overtimePay = (hours - 40 ) * (rate * 1.5 ); } grossPay = regularPay + overtimePay; System.out.println(“Your gross pay is” + grossPay);
} }
Introduction to Object-oriented Introduction to Object-oriented Programming and DesignProgramming and Design
Key concepts in beginning to Key concepts in beginning to understand object-oriented understand object-oriented programmingprogramming
A specific approach to programmingData and operations on the data are
packaged together into a single unit called an object.
Models real-world problems
OBJECT ORIENTED OBJECT ORIENTED PROGRAMMINGPROGRAMMING
What is an object?
A noun
A person
A bank account
A rectangle
A grade book
What is an object’s data members?What is an object’s data members?
Person
A name
An address
A phone number
A social security number
Rather than describing every single person, in object-oriented programming, the programmer describes a general type of an object and then creates many of the objects of that same type.
The person classThe person classclass Person{ // data members name; address; phonenumber; socialno; hand; mouth; // methods (behaviors) void eat(good food, fork utensils) { hand = utensils; mouth = food; }
Creating a new class from an Creating a new class from an existing classexisting class
class Instructor extends Person{ // Instructor gets to use all of Person data members // and methods // Instructor’s data members textbooks; computer; // Instructor’s methods void teach(….. ) { ……. };// other stuff }
Test your understanding on an Test your understanding on an airline reservation systemairline reservation system
What would some of the objects be?What data would the object contain?What operations would be performed
on that data?