Presentation is loading. Please wait.

Presentation is loading. Please wait.

ISE 582: Information Technology for Industrial Engineering Instructor: Elaine Chew University of Southern California Department of Industrial and Systems.

Similar presentations


Presentation on theme: "ISE 582: Information Technology for Industrial Engineering Instructor: Elaine Chew University of Southern California Department of Industrial and Systems."— Presentation transcript:

1 ISE 582: Information Technology for Industrial Engineering Instructor: Elaine Chew University of Southern California Department of Industrial and Systems Engineering Lecture 2-2 First cup of JAVA Winston & Narasimhan: Chapt 1-5 (pp 1-33)

2 4 September 2003ISE 582: Web Technology for IE 2 The Agenda for Today HTML Forms Introduction to Objects Programming in General Getting Started in JAVA

3 4 September 2003ISE 582: Web Technology for IE 3 Introduction to Objects Object Instance –Attributes (properties): associated data –Operations: actions that change attributes Methods in JAVA Member functions in C++ Object Class –Category or set of objects –Share same attributes, operations and relationships to other objects

4 4 September 2003ISE 582: Web Technology for IE 4 Example: Object Class WIZARD name age house claimToFame changeName(…) incrementAge() calculateDOB() Class name Attributes Operations

5 4 September 2003ISE 582: Web Technology for IE 5 Example: Object Instances w1: Wizard name = “Albus Dumbledore” age = 161 house = “Gryffindor” claimToFame = “Defeated dark wizard Grindelwald” w2: Wizard name = “Harry Potter” age = 21 house = “Gryffindor” claimToFame = “Survived deadly curse by Voldemort”

6 4 September 2003ISE 582: Web Technology for IE 6 Objects and older constructs Operation/ Method = function/procedure Object Instance = FAT variable containing multiple pieces of data and its own functions

7 4 September 2003ISE 582: Web Technology for IE 7 Convention: –Attributes/operation names begin with lower-case characters –Class and type names are capitalized Common Operations: –get*, set*, is* Naming Conventions Class name attributes:Type operations Class name

8 4 September 2003ISE 582: Web Technology for IE 8 Programming in General Algorithms Pseudocode Reusable Components Testing and Debugging

9 4 September 2003ISE 582: Web Technology for IE 9 Algorithms and Pseudocode Hardest part in designing methods: coming up with a plan or strategy for carrying out the action Algorithm: set of instructions for solving a problem. So precise that even a dumb computer could follow the instructions and get the same results Pseudocode: an algorithm written in a mixture of English and some programming language

10 4 September 2003ISE 582: Web Technology for IE 10 Reusable Components Most programs combine already existing components Be sure to design classes so that they are reusable

11 4 September 2003ISE 582: Web Technology for IE 11 Testing and Debugging Syntax Error: a grammatical mistake Run-time Error: detected when program is run Logic Error: incorrect but legal

12 4 September 2003ISE 582: Web Technology for IE 12 Development Cycle Write or edit source code Compile source code Execute program Fix bugs that emerge during compilation Fix bugs that emerge during execution

13 4 September 2003ISE 582: Web Technology for IE 13 Getting Started in JAVA A Little JAVA History Compile and Execute a Simple Program Declare Variables Arithmetic Expressions, the Math Class Define a Simple Method

14 4 September 2003ISE 582: Web Technology for IE 14 JAVA: Definition 1. An island of Indonesia separated from Borneo by the Java Sea, an arm of the western Pacific Ocean. Center of an early Hindu Javanese civilization, Java was converted to Islam before the arrival of the Europeans (mainly the Dutch) in the late 16th century.

15 4 September 2003ISE 582: Web Technology for IE 15 JAVA: Definition 2. A trademark used for a programming language designed to develop applications, especially ones for the Internet, that can operate on different platforms. 3. n. Informal: Brewed coffee

16 4 September 2003ISE 582: Web Technology for IE 16 A Little JAVA History 1991: Programming Language for Home Appliances (Gosling) 1994: Coupled with HotJava web- browser (Naughton and Payne) 1995: Netscape made browsers capable of running Java programs

17 4 September 2003ISE 582: Web Technology for IE 17 Source to Byte Code The Java compiler translates the class definitions and programs into byte code Byte code is executed by an interpreter, called a Java Virtual Machine

18 4 September 2003ISE 582: Web Technology for IE 18 Demo Step 1 Embed method in a class definition Explicit values are said to be literal Java is blank insensitive, but case sensitive public class Demonstrate {... } accessibility class definition

19 4 September 2003ISE 582: Web Technology for IE 19 public class Demonstrate { } Demo Step 2 public static void main (String argv[]) { System.out.print(“The movie rating is “); System.out.println(6 + 9 + 8); } accessibility class method, not instance method returns no value

20 4 September 2003ISE 582: Web Technology for IE 20 Demo Step 3: Compile & Execute At the command prompt: –Type “javac Demonstrate.java” –(this generates a file Demonstrate.class) –Type “java Demonstrate” What will the output be? Data in this program is said to be –Wired in or hard coded

21 4 September 2003ISE 582: Web Technology for IE 21 Quidditch Quidditch is a game played in mid-air on broomsticks that is a cross between rugby, basketball and the emergency room. Each team consists of seven players; three Chasers, two Beaters, one Seeker and one Keeper. The Keeper acts as a goalie against the other team making a score in one of their three hoops. The Chasers work together to score, using a ball known as the Quaffle. Scoring with the Quaffle is worth ten points. Two other balls known as Bludgers are enchanted to try and knock the players from their brooms. It is up to the Beaters to keep this from happening. Equipped with bats similar to those used in Cricket, Beaters work furiously to keep their teammates from being injured by Bludgers. Last and never least, the Seekers have the important task of catching the Snitch. This ball is the size of a walnut with wings and flies around the Pitch independantly. Capture of the Snitch is worth 150 points, and it automatically ends the game. However, this doesn't mean the team that catches the Snitch automatically wins. The game can also be ended with the mutual consent of both team captains From http://www.pensievemush.org/hogwarts.html The Quaffle The Golden Snitch

22 4 September 2003ISE 582: Web Technology for IE 22 Declaring Variables in JAVA Identifiers are names of variables –E.g. age, claimToFame, many$$$, no_way Variables are reserved chunks of memory that contain values. Type of variable determines how much memory is allocated to it.

23 4 September 2003ISE 582: Web Technology for IE 23 Some Variable Types char:2 bytes: characters byte,short,int,long: increasing:integers float,double: 4,8: floating point number OTHERS: boolean, String, arrays etc public class Demonstrate{ public static void main (String argv[]) { int script, acting, direction …} }

24 4 September 2003ISE 582: Web Technology for IE 24 COMMENTING YOUR CODE // This is a one-line comment /* This comment just goes on and on and on… */ NOTE: no nesting of comments.

25 4 September 2003ISE 582: Web Technology for IE 25 ARITHMETIC EXPRESSIONS The usual operators: +, -, *, / Modulus: % (remainder in division) The usual precedence rules apply Mixing data types in expressions Casting an expression –Original data type remains unchanged Assignment operates from R to L

26 4 September 2003ISE 582: Web Technology for IE 26 The Math Class public class Demonstrate { public static void main (String argv[]) { System.out.println(“natural log of 10:” + Math.log(10)); System.out.println(“abs value of -10:” + Math.abs(-10)); System.out.println(“max of 2 and 3:” + Math.max(2,3)); System.out.println(“5th power of 6:” + Math.pow(6,5)); System.out.println(“sqrt of 7:” + Math.sqrt(7)); System.out.println(“sine of 8 rad:” + Math.sin(8)); System.out.println(“Random no.(0,1):” + Math.random()); }

27 4 September 2003ISE 582: Web Technology for IE 27 Defining a Simple Method public class Demonstrate { public static void main (String argv[]) { int script = 6, acting = 9, direction = 8; System.out.print(“The rating of the movie is”); System.out.println(movieRating(script,acting,direction); } public static int movieRating (int s, int a, int d) { return s + a + d; } ARGUMENTS PARAMETERS

28 4 September 2003ISE 582: Web Technology for IE 28 Defining Methods in Multiple Files public class Movie { public static int movieRating (int s, int a, int d) { return s + a + d; } public class Demonstrate { public static void main (String argv[]) { int s = 6, a = 9, d = 8; System.out.print(“The rating of the movie is”); System.out.println(Movie.movieRating(s,a,d); }

29 4 September 2003ISE 582: Web Technology for IE 29 Other Things to Know You can define more than one class in the same file To call a method in a different class, preface the method name with the class name and join with a dot. You can define multiple methods with the same name in the same class as long as they have different signatures (i.e. arrangement of parameter data types)


Download ppt "ISE 582: Information Technology for Industrial Engineering Instructor: Elaine Chew University of Southern California Department of Industrial and Systems."

Similar presentations


Ads by Google