Web Technology for Industrial Engineering 5 September 2002

Similar documents
Information Technology for Industrial Engineers 29 August ISE 582: Information Technology for Industrial Engineers

Introduction To Java. Chapter 1. Origins of the Java Language. Origins of the Java Language. Objects and Methods. Origins of the Java Language

! Widely available. ! Widely used. ! Variety of automatic checks for mistakes in programs. ! Embraces full set of modern abstractions. Caveat.

Introduction to Programming Using Java (98-388)

CS110: PROGRAMMING LANGUAGE I

Course Outline. Introduction to java

Lecture 2: Intro to Java

Information Science 1

Basic Operations jgrasp debugger Writing Programs & Checkstyle

Java Methods. Lecture 8 COP 3252 Summer May 23, 2017

1.1 Your First Program

Exam 1 Prep. Dr. Demetrios Glinos University of Central Florida. COP3330 Object Oriented Programming

COSC 123 Computer Creativity. Introduction to Java. Dr. Ramon Lawrence University of British Columbia Okanagan

Two Types of Types. Primitive Types in Java. Using Primitive Variables. Class #07: Java Primitives. Integer types.

Special Topics: Programming Languages

Programming with Java

Lecture 2: Intro to Java

Object Oriented Methods : Deeper Look Lecture Three

Chapter 3 Syntax, Errors, and Debugging. Fundamentals of Java

CIS133J. Working with Numbers in Java

University of British Columbia CPSC 111, Intro to Computation Jan-Apr 2006 Tamara Munzner

Key Concept: all programs can be broken down to a combination of one of the six instructions Assignment Statements can create variables to represent

1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4. Epic Test Review 5 Epic Test Review 6 Epic Test Review 7 Epic Test Review 8

Introduction to Computer Science Unit 2. Notes

AP CS Unit 3: Control Structures Notes

Full file at

CS11 Java. Fall Lecture 1

Basics of Java Programming

Chapter 2: Basic Elements of Java

AP Computer Science Homework Set 1 Fundamentals

Lecture Set 4: More About Methods and More About Operators

CS 302: Introduction to Programming

Computer Programming I - Unit 2 Lecture 1 of 13

COMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette

Interpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled

Information Technology for Industrial Engineers 27 September 2001

COMP Primitive and Class Types. Yi Hong May 14, 2015

1.1 Your First Program

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

1. [3 pts] What is your section number, the period your discussion meets, and the name of your discussion leader?

1.1 Your First Program

DATA TYPES AND EXPRESSIONS

Introduction to Computer Science and Object-Oriented Programming

Review for Test 1 (Chapter 1-5)

1.1 Your First Program

INDEX. A SIMPLE JAVA PROGRAM Class Declaration The Main Line. The Line Contains Three Keywords The Output Line

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 10: OCT. 6TH INSTRUCTOR: JIAYIN WANG

COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand

Java Bytecode (binary file)

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

Values, Variables, Types & Arithmetic Expressions. Agenda

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Datatypes, Variables, and Operations

1. What type of error produces incorrect results but does not prevent the program from running? a. syntax b. logic c. grammatical d.

Lecture Set 4: More About Methods and More About Operators

1.1 Your First Program

1.1 Your First Program! Naive ideal. Natural language instructions.

To define methods, invoke methods, and pass arguments to a method ( ). To develop reusable code that is modular, easy-toread, easy-to-debug,

4. The is a diagram that graphically depicts the steps that take place in a program. a. Program b. Flowchart c. Algorithm d. Code e.

Information Science 1

Lecture 2. COMP1406/1006 (the Java course) Fall M. Jason Hinek Carleton University

CS-201 Introduction to Programming with Java

Pace University. Fundamental Concepts of CS121 1

Advanced Computer Programming

Programming Language Basics

1.1 Your First Program

CS2141 Software Development using C/C++ C++ Basics

Introduction to Computer Science Unit 2. Notes

Outline. Parts 1 to 3 introduce and sketch out the ideas of OOP. Part 5 deals with these ideas in closer detail.

Lecture 3 Tao Wang 1

Working with JavaScript

PRIMITIVE VARIABLES. CS302 Introduction to Programming University of Wisconsin Madison Lecture 3. By Matthew Bernstein

Inf1-OOP. Textbooks. Who and What. Organizational Issues. Why Java? Course Overview. Hello, World! in Java. Ewan Klein, Perdita Stevens

Reserved Words and Identifiers

Building Java Programs

Inf1-OOP. Textbooks. Who and What. Organisational issues. Why Java? Course Overview. Hello, World! in Java

Section 2.2 Your First Program in Java: Printing a Line of Text

Define a method vs. calling a method. Chapter Goals. Contents 1/21/13

B.V. Patel Institute of BMC & IT, UTU 2014

COMP 110 Introduction to Programming. What did we discuss?

Section 2.2 Your First Program in Java: Printing a Line of Text

Midterms Save the Dates!

Object-Oriented Programming

Chapter 1. Introduction to Computers and Java Objects. Background information. » important regardless of programming language. Introduction to Java

Full file at

Midterm I - CSE11 Fall 2013 CLOSED BOOK, CLOSED NOTES 50 minutes, 100 points Total.

What did we talk about last time? Examples switch statements

Chapter 1 Introduction to java

Chapter 2: Overview of C++

All classes in a package can be imported by using only one import statement. If the postcondition of a method is not met, blame its implementer

COMP-202: Foundations of Programming. Lecture 4: Methods Jackie Cheung, Winter 2016

} Evaluate the following expressions: 1. int x = 5 / 2 + 2; 2. int x = / 2; 3. int x = 5 / ; 4. double x = 5 / 2.

LECTURE 3 C++ Basics Part 2

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

CS 106 Introduction to Computer Science I

Introduction to Java Applications

Motivations. Chapter 3: Selections and Conditionals. Relational Operators 8/31/18. Objectives. Problem: A Simple Math Learning Tool

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

MODULE 02: BASIC COMPUTATION IN JAVA

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Transcription:

ISE 582: Information Technology for Industrial Engineers University of Southern California Department of Industrial and Systems Engineering Lecture 2-2 First cup of JAVA Handouts Lecture 2-1: HTML Forms Lecture 2-2: First Cup of Java Homework 1 READ: Winston & Narasimhan: Chapt 1-5 (pp 1-33) 5 September 2002 Web Technology for IE 2 Announcements Homework 1 is due a week from today Next week, Luca will be teaching class 5 September 2002 Web Technology for IE 3 http://www-classes.usc.edu/engr/ise/582 1

HTML Forms Introduction to Objects Programming in General Getting Started in JAVA The Agenda for Today 5 September 2002 Web Technology for IE 4 Forms Help At USC, http://www.usc.edu/uscweb/authoring/scripting.html Public domain scripts, e.g.: http://www.jsworld.com/scripts/forms/ Example: Feedback Form, Opinion Poll 5 September 2002 Web Technology for IE 5 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 5 September 2002 Web Technology for IE 6 http://www-classes.usc.edu/engr/ise/582 2

Example: Object Class name age house claimtofame WIZARD changename( ) incrementage() calculatedob() Class name Attributes Operations 5 September 2002 Web Technology for IE 7 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 5 September 2002 Web Technology for IE 8 Objects and older constructs Operation/ Method = function/procedure Object Instance = FAT variable containing multiple pieces of data and its own functions 5 September 2002 Web Technology for IE 9 http://www-classes.usc.edu/engr/ise/582 3

Naming Conventions Convention: Attributes/operation names begin with lower-case characters Class and type names are capitalized Common Operations: get*, set*, is* Class name attributes:type Class name operations 5 September 2002 Web Technology for IE 10 Programming in General Algorithms Pseudocode Reusable Components Testing and Debugging 5 September 2002 Web Technology for IE 11 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 5 September 2002 Web Technology for IE 12 http://www-classes.usc.edu/engr/ise/582 4

Reusable Components Most programs combine already existing components Be sure to design classes so that they are reusable 5 September 2002 Web Technology for IE 13 Testing and Debugging Syntax Error: a grammatical mistake Run-time Error: detected when program is run Logic Error: incorrect but legal 5 September 2002 Web Technology for IE 14 Write or edit source code Development Cycle Compile source code Execute program Fix bugs that emerge during compilation Fix bugs that emerge during execution 5 September 2002 Web Technology for IE 15 http://www-classes.usc.edu/engr/ise/582 5

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 5 September 2002 Web Technology for IE 16 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. 5 September 2002 Web Technology for IE 17 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 5 September 2002 Web Technology for IE 18 http://www-classes.usc.edu/engr/ise/582 6

A Little JAVA History 1991: Programming Language for Home Appliances (Gosling) 1994: Coupled with HotJava webbrowser (Naughton and Payne) 1995: Netscape made browsers capable of running Java programs 5 September 2002 Web Technology for IE 19 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 5 September 2002 Web Technology for IE 20 Example: Compute Movie Rating Suppose script(6), acting(9), directing(8) To arrange for these scores to be totaled, define main inside class definition: accessibility public static void main (String argv[]) { class method, not instance method returns no value System.out.print( The rating of the movie is ); System.out.println(6 + 9 + 8); 5 September 2002 Web Technology for IE 21 http://www-classes.usc.edu/engr/ise/582 7

Example continued Embed method in a class definition accessibility class definition public class Demonstrate {... Explicit values are said to be literal Java is blank insensitive, but case sensitive 5 September 2002 Web Technology for IE 22 Example: Compile and 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 5 September 2002 Web Technology for IE 23 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. 5 September 2002 Web Technology for IE 24 http://www-classes.usc.edu/engr/ise/582 8

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 5 September 2002 Web Technology for IE 25 COMMENTING YOUR CODE // This is a one-line comment /* This comment just goes on and on and on */ NOTE: no nesting of comments. 5 September 2002 Web Technology for IE 26 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 5 September 2002 Web Technology for IE 27 http://www-classes.usc.edu/engr/ise/582 9

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()); 5 September 2002 Web Technology for IE 28 Defining a Simple Method ARGUMENTS 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; PARAMETERS 5 September 2002 Web Technology for IE 29 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); 5 September 2002 Web Technology for IE 30 http://www-classes.usc.edu/engr/ise/582 10

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) 5 September 2002 Web Technology for IE 31 http://www-classes.usc.edu/engr/ise/582 11