Download presentation
Presentation is loading. Please wait.
Published byPreston Sharp Modified over 9 years ago
1
CSE 1340 Class 3
2
Class 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
3
Evolution 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
4
What Is Java? High-level language Object-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
5
What Is Java? Parsimonious –Compatible with older versions Robust –Strongly typed and incorruptible data Secure –Protection against misuse of code Portable –Platform-independent
6
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
7
Features 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
8
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
9
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.
10
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.
11
Editor Compiler Class Loader Byte Code Verifier... Interpreter......
12
Editor Disk Program1.java
13
Compiler Disk Program1.java Program1.class
14
Class Loader...... PrimaryMemory Program1.class Disk Program1.class Program1.html
15
Java Virtual Machine JVM Java Source code.java Java byte-code.class Environment Java VM javac java
16
Byte Code Verifier...... PrimaryMemory Program1.class
17
JIT Compiler JIT- takes byte-codes and change it to machine code. JVM Running Applet or Application J.I.T. Compiler.class file machine code
18
Interpreter...... PrimaryMemory Program1.class
19
Editor Compiler Class Loader Byte Code Verifier... Interpreter......
20
Java Program Types Console and Windowed applications Applets Servlets Web Services JavaBeans
21
Console Applications Stand-alone programs using a command-line interface
22
Windowed Applications Stand-alone programs using a graphical user interface (GUI)
23
Applets Client-side programs executed as part of a displayed Web page
24
Servlets 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)
25
Servlets
26
Web Services Services receive information requests over the Web and return the requested data
27
JavaBeans Reusable software components
28
Sample Problem A programmer needs an algorithm to determine an employee’s weekly wages. How would the calculations be done by hand?
29
One 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
30
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 General RECALL EXAMPLE ( 40 x $ 24.75 ) + ( 12 x 1.5 x $ 24.75 ) = $1435.50
31
An Algorithm is... a step-by-step procedure for solving a problem in a finite amount of time.
32
Algorithm to Determine an Employee’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
33
Translating your algorithm into a programming language is called CODING The “code” or “program” for this algorithm is on the next screen
34
// 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); } }
35
Introduction to Object-oriented Programming and Design
36
Key concepts in beginning to understand object-oriented programming A specific approach to programming Data and operations on the data are packaged together into a single unit called an object. Models real-world problems
37
OBJECT ORIENTED PROGRAMMING What is an object? A noun A person A bank account A rectangle A grade book
38
What is an object’s data members? Person A name An address A phone number A social security number
39
What is an object’s behavior? Person Eats Drinks Walks Exercises
40
In order to eat, does the person object need anything? Food Utensils
41
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.
42
The person class class Person { // data members name; address; phonenumber; socialno; hand; mouth; // methods (behaviors) void eat(good food, fork utensils) { hand = utensils; mouth = food; }
43
Create many objects of type Person: Person Judy; Person John; Person Ann;
44
Creating a new class from an existing 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 }
45
Test your understanding on an airline reservation system What would some of the objects be? What data would the object contain? What operations would be performed on that data?
46
Conclusion of Class 3
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.