Computer Science. ESC 120 Introduction to Engineering Design

Size: px
Start display at page:

Download "Computer Science. ESC 120 Introduction to Engineering Design"

Transcription

1 Computer Science ESC 120 Introduction to Engineering Design Dr. Sunnie Chung Dept. of Electrical Engineering and Computer Science Cleveland State University

2 What is Engineering? Application of Scientific and Mathematical Knowledge to Design and Buildstructures, machines, devices, systems, materials and processes, and Services.

3 Engineering vs. Science Science: To know To understand and describe the nature E.g., Planetary system: movement and interaction of Sun, Earth, and Moon Engineering: To create Create new things within what nature allows us E.g., Communication satellites, Web Services

4 What is Computer Engineering Computer Engineering Design and Analyze digital hardwareand software systems Involve Computers Systems that contain computers

5 What is Computer Science? Computer Science is Study of Computer Software Study of Software Design and BuildSoftware Systems (Programs) to Create Computing Systems, Services, or any Innovations Involve Computers Systems that contain computers or can be connected to computers

6 What is Software Systems? Programsthat build Computing Systems, Services, Applications, or any Creations that are written in Computer Programming Languages Examples of Software Systems: Services: Online Library Systems, Amazon Web Services, CSU CampusNet Google Search Systems: Google Search, Google Map Social Network Systems: Facebook, Twitter, LinkedIn Innovation: IPhone, Mobil Phone Apps Computer Applications: Computer Games

7 Computer systems based on its usage General-purpose computer system by Computer Science, Software Engineering The computer is the end-product It allow users to load their own programs do various tasks It can run any number of software applications Special-purpose computer system Computer Engineering (Embedded computer system) The computer is part of a larger system

8 Embedded Computer System Computer integrated (i.e., embedded) within other system The computer performs a specific function The computer may not be visible and its program cannotbe altered by users Complexity of computer varies significantly; e.g., Microwave oven Digital camera Airplane navigation control

9 General Purpose Computers Any Types of general-purpose Computer Systems User Created Applications are infinite Required Software Systemsthat are complex and multilayered structure Smart phone Tablet/Laptop Desktop computer Server Super computer

10

11 A General Purposed Computer System Hardware : CPU (Intel Processor), Memory (RAM), Hard Disk, Monitor, Printer Software: Developed by Computer Science or Software Engineering Programs that written in a programming language to perform specific tasks

12 Software Systems Programsthat build Computing Systems, Services, Applications, or any Creations that are written in Computer Programming Languages Examples of Software Systems: Services: Online Library Systems, Amazon Web Services, CSU CampusNet Google Search Systems: Google Search, Google Map Social Network Systems: Facebook, Twitter, LinkedIn Innovation: IPhone, Smart Phone Apps Computer Applications: Computer Games

13 Search Engine Systems : Google Map

14 Social Network System: Facebook

15 Web Service System : Class Search of CSU CampusNet

16 Amazon Webserver

17 Database System

18 Mobile Phone, Tablet Applications

19 Computer Graphics: CGI in Movie

20 What are the Jobs in Computer Science Programmers Software Engineers System Programmers System Administrators Test Engineers Software Developers Web Designer Web Developers Database Administrators Database Developers System Architects Software Architects Data Analysts Data Scientists Computer Scientists

21 Brief History of Computers Hardware of Computers

22 Origin of Computer Compute(verb) To determine the outcomes (for examples, calculated numbers, amounts) by mathematics or by algorithmic procedures Computer(noun) A device that performs computation

23 Before Electronic Computer: Mechanical Computer E.g., Babbage difference machine (mid 19 century ) To tabulate polynomial functions Basic building block: gears

24 This image cannot currently be displayed. Before Electronic Computer: Human Computer Person manually performing math calculations Computer room at NASA High Speed Flight Station (1940s)

25 Electronic Computer (Hardware) Basic building blocks Vacuum tube Transistor IC (Integrated Circuit) VLSI (Very Large-Scale Integrated circuit)

26 First Vacuum Tube Based Computer ENIAC (Electronic Numerical Integrator And Computer) First general-purpose electronic computer Contained 17,000 (0.017 million) vacuum tubes Weigh 30 tons and consume 150 K Watts Completed in 1946 Originally designed to calculate artillery firing tables

27

28 First Computer Bug A moth found trapped between relays Must debug the machine to remove the error

29 Origin of Computer Software Turing Machine by Alan Turing at Punch Card: 1940 s Punch Card

30 Modern Computer Based on similar concept The size of transistor is continuously reduced Size is measured in 0.03 micron (10-6 meter) range in today s processor In comparison, the diameter of human hair is around 100 micron A chip (size of a finger nail) contains billions of transistors

31

32 Intel Core-i7

33 Overview of Computer Systems Computers, Programs, and Program Languages

34 What is a Computer System? Hardware of a computer consists of a CPU, memory, hard disk, USB driver, monitor, printer, and communication devices. Bus Storage Devices Memory CPU Communication Devices Input Devices Output Devices e.g., Disk, CD, and Tape e.g., Modem, and NIC e.g., Keyboard, Mouse e.g., Monitor, Printer

35 CPU The central processing unit (CPU) is the brain of a computer. It retrieves instructions from memory and executes them. The CPU speed is measured in megahertz (MHz), with 1 megahertz equaling 1 million pulses per second. The speed of the CPU has been improved continuously. If you buy a PC now, you can get an Intel Pentium 4 Processor at 3 gigahertz (1 gigahertz is 1000 megahertz). Bus Storage Devices Memory CPU Communication Devices Input Devices Output Devices e.g., Disk, CD, and Tape e.g., Modem, and NIC e.g., Keyboard, Mouse e.g., Monitor, Printer

36 Memory (Random Access Memory) Memory is to store data and program instructions for CPU to execute. A memory unit is an ordered sequence of bytes, each holds eight bits. A program and its data must be brought to memory before they can be executed. A memory byte is never empty, but its initial content may be meaningless to your program. The current content of a memory byte is lost whenever new information is placed in it. Bus Storage Devices Memory CPU Communication Devices Input Devices Output Devices e.g., Disk, CD, and Tape e.g., Modem, and NIC e.g., Keyboard, Mouse e.g., Monitor, Printer

37 How Data is Stored? Data of various kinds, such as numbers, characters, and strings, are encoded as a series of bits (zeros and ones). Computers use zeros and ones because digital devices have two stable states, which are referred to as zeroand oneby convention. The programmers need not to be concerned about the encoding and decoding of data, which is performed automatically by the system based on the encoding scheme. The encoding scheme varies. For example, character J is represented by in one byte. A small number such as three can be stored in a single byte. If computer needs to store a large number that cannot fit into a single byte, it uses a number of adjacent bytes. No two data can share or split a same byte. A byte is the minimum storage unit. Memory address Memory content Encoding for character J Encoding for character a Encoding for character v Encoding for character a Encoding for number 3

38 Data Representation in a Computer Use digital signals in electronic computer Us two voltage levels for two values: e.g., +5V for logic 1 and 0V for logic 0 Bit (short for binary digit): Two discrete logic values : 0 and 1 Since we only have two values, a bit alone can only represent two status: (won, lost) or (yes, no) or (true, false)

39 Combine Bits into Patterns If we group multiple bits, we can represent a very large number of different status Arranging bits into n-length sequences, we can create 2 n symbols 2 bits: 4 (= 2 2 ) possible symbols: 00, 01, 10, 11 Byte ( = 8 bits) 256 (=2 8 ) possible symbols: , ,, , Word (32 bits) About 4 billion (i.e., 2 32 ) possible symbols Word (64 bits) Current Computer How many possible symbols?? 2 64!

40 Size of Disk Storage to Store Data I Byte = 8 bits 1 KiloByte= 1024 (2 10 ) Bytes 1 MegaByte= 1024 (2 10 ) KBytes~= 1 million Bytes 1 GigaByte= 1024 (2 10 ) MBytes 1 TeraByte= 1024 (2 10 ) Gbytes~= 1 million MegaBytes 1 PetaByte= 1024 (2 10 ) Tbytes 1 ExaByte= 1024 (2 10 ) Pbytes~= 1 million TeraBytes

41 Storage Devices Memory is volatile, because information is lost when the power is off. Programs and data are permanently stored on storage devices and are moved to memory when the computer actually uses them. There are three main types of storage devices:disk drives (hard disks and floppy disks), CD drives (CD-R and CD-RW), and Tape drives. Bus Storage Devices Memory CPU Communication Devices Input Devices Output Devices e.g., Disk, CD, and Tape e.g., Modem, and NIC e.g., Keyboard, Mouse e.g., Monitor, Printer

42 Output Devices: Monitor The monitor displays information (text and graphics). The resolution and dot pitch determine the quality of the display. Bus Storage Devices Memory CPU Communication Devices Input Devices Output Devices e.g., Disk, CD, and Tape e.g., Modem, and NIC e.g., Keyboard, Mouse e.g., Monitor, Printer

43 Monitor Resolution and Dot Pitch resolution The screen resolution specifies the number of pixels in horizontal and vertical dimensions of the display device. Pixels (short for picture elements ) are tiny dots that form an image on the screen. A common resolution for a 17-inch screen, for example, is 1,024 pixels wide and 768 pixels high. The resolution can be set manually. The higher the resolution, the sharper and clearer the image is. dot pitch The dot pitch is the amount of space between pixels, measured in millimeters. The smaller the dot pitch, the sharper the display.

44 Communication Devices A regular modem uses a phone line and can transfer data in a speed up to 56,000 bps (bits per second). A DSL (digital subscriber line) also uses a phone line and can transfer data in a speed 20 times faster than a regular modem. A cable modem uses the TV cable line maintained by the cable company. A cable modem is as fast as a DSL. Network interface card (NIC) is a device to connect a computer to a local area network (LAN). The LAN is commonly used in business, universities, and government organizations. A typical type of NIC, called 10BaseT, can transfer data at 10 mbps (million bits per second). Wireless Network! Bus Storage Devices Memory CPU Communication Devices Input Devices Output Devices e.g., Disk, CD, and Tape e.g., Modem, and NIC e.g., Keyboard, Mouse e.g., Monitor, Printer

45 Programs Computer programs, known as software, are instructions to the computer. You tell a computer what to do through programs. Without programs, a computer is an empty machine. Computers do not understand human languages, so you need to use computer languages to communicate with them. Programs are written using Programming Languages.

46 Programming Languages Machine Language Assembly Language High-Level Language Machine language is a set of primitive instructions built into every computer. The instructions are in the form of binary code, so you have to enter binary codes for various instructions. Program with native machine language is a tedious process. Moreover the programs are highly difficult to read and modify. For example, to add two numbers, you might write an instruction in binary like this:

47 Programming Languages Machine Language Assembly Language High-Level Language Assembly languages were developed to make programming easy. Since the computer cannot understand assembly language, however, a program called assembler is used to convert assembly language programs into machine code. For example, to add two numbers, you might write an instruction in assembly code like this: ADDF3 R1, R2, R3

48 Programming Languages Machine Language Assembly Language High-Level Language The high-level languages are English-like and easy to learn and program. For example, the following is a high-level language statement that computes the area of a circle with radius 5: area = 5 * 5 * ;

49 Interpreting/Compiling Source Code A program written in a high-level language is called a source program orsource code. Because a computer cannot understand a source program, a source program must be translated into machine code for execution. The translationcan be done using another programming tool called an interpreter or a compiler.

50 Interpreting Source Code An interpreter reads one statement from the source code, translates it to the machine code or virtual machine code, and then executes it right away, as shown in the following figure. Note that a statement from the source code may be translated into several machine instructions.

51 Compiling Source Code A compiler translates the entire source code into a machine-code file, and the machine-code file is then executed, as shown in the following figure.

52 Operating Systems (OS) The operating system(os) is a program that manages and controls a computer s activities. The popular operating systems for general-purpose computers are Microsoft Windows, Mac OS, and Linux. Application programs, such as a Web browser or a word processor, cannot run unless an operating system is installed and running on the computer.

53 Popular High-Level Languages Language Description Ada BASIC C C++ C# COBOL FORTRAN Java Pascal Python Visual Basic Named for Ada Lovelace, who worked on mechanical general-purpose computers. The Ada language was developed for the Department of Defense and is used mainly in defense projects. Beginner s All-purpose Symbolic Instruction Code. It was designed to be learned and used easily by beginners. Developed at Bell Laboratories. C combines the power of an assembly language with the ease of use and portability of a high-level language. C++ is an object-oriented language, based on C. Pronounced C Sharp. It is a hybrid of Java and C++ and was developed by Microsoft. COmmon Business Oriented Language. Used for business applications. FORmula TRANslation. Popular for scientific and mathematical applications. Developed by Sun Microsystems, now part of Oracle. It is widely used for developing platformindependent Internet applications. Named for Blaise Pascal, who pioneered calculating machines in the seventeenth century. It is a simple, structured, general-purpose language primarily for teaching programming. A simple general-purpose scripting language good for writing short programs. Visual Basic was developed by Microsoft and it enables the programmers to rapidly develop graphical user interfaces.

54 High Level Programming Language: Source Code in Java import java.util.scanner; public class CalculateCircleArea{ public static void main(string[] args) { Scanner input = new Scanner(System.in); // Enter radius of the circle System.out.print("Enter the radius circle: "); double radius = input.nextdouble(); double area = radius * radius * ; } System.out.println("The area is " + area); }

55 High Level Programming Language: Source Code in C #include<stdio.h> intmain() { float radius, area; printf("\nenter the radius of Circle : "); scanf_s("%f", &radius); area = 3.14 * radius * radius; printf("\narea of Circle : %f", area); getchar(); //just to make the console output to wait } return (0);

56 Hyper Text Mark Up Programming Language: Webpage in HTML (Source Code)

57 Hyper Text Mark Up Programming Language: Webpage in HTML (Source Code)

58 High Level Programming Language : Java Java enables users to develop and deploy applications on the Internet for servers, desktop computers, and small hand-held devices. The future of computing is being profoundly influenced by the Internet, and Java promises to remain a big part of that future. Java is the Internet programming language. Java is a general purpose programming language. Java is the Internet programming language. 58

59 JDK Editions Java Standard Edition (J2SE) J2SE can be used to develop client-side standalone applications or applets. Java Enterprise Edition (J2EE) J2EE can be used to develop server-side applications such as Java servlets, Java ServerPages, and Java ServerFaces. Java Micro Edition (J2ME). J2ME can be used to develop applications for mobile devices such as cell phones. This book uses J2SE to introduce Java programming. 59

60 Popular IDE (Integrated Development Environment) Java: NetBeans Eclipse C/C++ MS Visual Studio 60

61 Algorithms The procedures for strategies that define how a program should organized and be executed to achieve the required tasks. Many different algorithms for a same task so the most efficient and optimized one should be selected to program.

62 Data Structures Structures hold data that belong togetherin a program that are used to compute or execute the tasks Examples: Student record: id, name, major, gender, start year, gpa Bank account: account number, name, currency, balance Address book: name, address, telephone number In database applications, structures are called records.

63 Different types of data in each row structure in Table Employee Employee ID Name DeptID Salary Project 10 Nemo Company Picnic 20 Dory Big data Project 40 Gill Factory Sensor Project 52 Ray Cloud Project

64 A Simple Java Program Listing 1.1 // This program prints Welcome to Java! public class Welcome { public static void main(string[] args) { System.out.println("Welcome to Java!"); } } Animation Welcome IMPORTANT NOTE: If you cannot run the buttons, see Run 64

65 Creating and Editing Using NotePad To use NotePad, type notepad Welcome.java from the DOS prompt. 65

66 Creating and Editing Using WordPad To use WordPad, type write Welcome.java from the DOS prompt. 66

67 Creating, Compiling, and Running Programs 67

68 Compiling Java Source Code You can port a source program to any machine with appropriate compilers. The source program must be recompiled, however, because the object program can only run on a specific machine. Nowadays computers are networked to work together. Java was designed to run object programs on any platform. With Java, you write the program once, and compile the source program into a special type of object code, known as bytecode. The bytecode can then run on any computer with a Java Virtual Machine, as shown below. Java Virtual Machine is a software that interprets Java bytecode. 68

69 Compiling and Running Java from the Command Window Set path to JDK bin directory set path=c:\program Files\java\jdk1.8.0\bin Set classpath to include the current directory set classpath=. Compile javac Welcome.java Run java Welcome 69

70 Compiling and Running Java from TextPad Save the file as Welcome.java File name matches with the class name in the source code with extension.java 70

71 Anatomy of a Programming Language Program name (Class name) Function (Method) Statements Statement terminator Reserved words Comments Blocks

72 Class Name Every Java program must have at least one class. Each class has a name. By convention, class names start with an uppercase letter. In this example, the class name is Welcome. // This program prints Welcome to Java! public class Welcome { public static void main(string[] args) { System.out.println("Welcome to Java!"); } }

73 Main Method Line 2 defines the main method. In order to run a class, the class must contain a method named main. The program is executed from the main method. // This program prints Welcome to Java! public class Welcome { public static void main(string[] args) { System.out.println("Welcome to Java!"); } }

74 Statement A statement represents an action or a sequence of actions. The statement System.out.println("Welcome to Java!") in the program in Listing 1.1 is a statement to display the greeting "Welcome to Java!. // This program prints Welcome to Java! public class Welcome { public static void main(string[] args) { System.out.println("Welcome to Java!"); } }

75 Statement Terminator Every statement in Java ends with a semicolon (;). // This program prints Welcome to Java! public class Welcome { public static void main(string[] args) { System.out.println("Welcome to Java!"); } }

76 Reserved words Reserved words or keywords are words that have a specific meaning to the compiler and cannot be used for other purposes in the program. For example, when the compiler sees the word class, it understands that the word after class is the name for the class. // This program prints Welcome to Java! public class Welcome { public static void main(string[] args) { System.out.println("Welcome to Java!"); } }

77 Blocks A pair of braces in a program forms a block that groups components of a program. public class Test { public static void main(string[] args) { System.out.println("Welcome to Java!"); } } Method block Class block

78 Basic elements // (single line comment): anything after it until end of line will be ignored /* */(multi line comment): anything in between will be ignored { } (curly brackets): define when a block of code starts and ends ;(semicolon): each line of code must be ended with a semicolon

79 Special Symbols Character Name Description {} () [] // " " ; Opening and closing braces Opening and closing parentheses Opening and closing brackets Double slashes Opening and closing quotation marks Semicolon Denotes a block to enclose statements. Used with methods. Denotes an array. Precedes a comment line. Enclosing a string (i.e., sequence of characters). Marks the end of a statement.

80 { } // This program prints Welcome to Java! public class Welcome { public static void main(string[] args) { System.out.println("Welcome to Java!"); } }

81 ( ) // This program prints Welcome to Java! public class Welcome { public static void main(string[] args) { System.out.println("Welcome to Java!"); } }

82 ; // This program prints Welcome to Java! public class Welcome { public static void main(string[] args) { System.out.println("Welcome to Java!"); } }

83 // // This program prints Welcome to Java! public class Welcome { public static void main(string[] args) { System.out.println("Welcome to Java!"); } }

84 " " // This program prints Welcome to Java! public class Welcome { public static void main(string[] args) { System.out.println("Welcome to Java!"); } }

85 animation Trace a Program Execution Enter main method // This program prints Welcome to Java! public class Welcome { public static void main(string[] args) { System.out.println("Welcome to Java!"); } }

86 animation Trace a Program Execution Execute statement // This program prints Welcome to Java! public class Welcome { public static void main(string[] args) { System.out.println("Welcome to Java!"); } }

87 animation Trace a Program Execution // This program prints Welcome to Java! public class Welcome { public static void main(string[] args) { System.out.println("Welcome to Java!"); } } print a message to the console

88 Introducing Programming with an Example Listing 2.1 Computing the Area of a Circle This program computes the area of the circle. ComputeArea Animation Run IMPORTANT NOTE: If you cannot run the buttons, see

89 animation Trace a Program Execution public class ComputeArea{ /** Main method */ public static void main(string[] args) { double radius; double area; radius allocate memory for radius no value // Assign a radius radius = 20; // Compute area area = radius * radius * ; // Display results System.out.println("The area for the circle of radius " + radius + " is " + area); } }

90 animation Trace a Program Execution public class ComputeArea{ /** Main method */ public static void main(string[] args) { double radius; double area; // Assign a radius radius = 20; // Compute area area = radius * radius * ; // Display results System.out.println("The area for the circle of radius " + radius + " is " + area); } } radius area memory no value no value allocate memory for area

91 animation Trace a Program Execution public class ComputeArea{ /** Main method */ public static void main(string[] args) { double radius; double area; radius area assign 20 to radius 20 no value // Assign a radius radius = 20; // Compute area area = radius * radius * ; // Display results System.out.println("The area for the circle of radius " + radius + " is " + area); } }

92 animation Trace a Program Execution public class ComputeArea{ /** Main method */ public static void main(string[] args) { double radius; double area; // Assign a radius radius = 20; radius area memory // Compute area area = radius * radius * ; compute area and assign it to variable area // Display results System.out.println("The area for the circle of radius " + radius + " is " + area); } }

93 animation Trace a Program Execution public class ComputeArea{ /** Main method */ public static void main(string[] args) { double radius; double area; // Assign a radius radius = 20; radius area memory // Compute area area = radius * radius * ; // Display results System.out.println("The area for the circle of radius " + radius + " is " + area); } } print a message to the console

94 Reading Input from the Console 1. Create a Scanner object Scanner input = new Scanner(System.in); 2. Use the method nextdouble() to obtain to a double value. For example, System.out.print("Enter a double value: "); Scanner input = new Scanner(System.in); double d = input.nextdouble(); Animation ComputeAreaWithConsoleInput ComputeAverage Run Run

95 Identifiers An identifier is a sequence of characters that consist of letters, digits, underscores (_), and dollar signs ($). An identifier must start with a letter, an underscore (_), or a dollar sign ($). It cannot start with a digit. An identifier cannot be a reserved word. (See Appendix A, Java Keywords, for a list of reserved words). An identifier cannot be true, false, or null. An identifier can be of any length.

96 Variables A place to store data Must be declared first Must with a data type Most commonly used data type: integer int E.g., int a, b, index; // no initial value int PIN_LED=13; // with initial value

97 Variables // Compute the first area radius = 1.0; area = radius * radius * ; System.out.println("The area is + area + " for radius "+radius); // Compute the second area radius = 2.0; area = radius * radius * ; System.out.println("The area is + area + " for radius "+radius);

98 Declaring Variables int x; // Declare x to be an // integer variable; double radius; // Declare radius to // be a double variable; char a; // Declare a to be a // character variable;

99 Assignment Statements x = 1; // Assign 1 to x; radius = 1.0; // Assign 1.0 to radius; a = 'A'; // Assign 'A' to a;

100 Declaring and Initializing in One Step int x = 1; double d = 1.4;

101 Named Constants final datatype CONSTANTNAME = VALUE; final double PI = ; final int SIZE = 3;

102 Numerical Data Types Name Range Storage Size byte 2 7 to (-128 to 127) 8-bit signed short 2 15 to ( to 32767) 16-bit signed int 2 31 to ( to ) 32-bit signed long 2 63 to bit signed (i.e., to ) float Negative range: 32-bit IEEE E+38 to -1.4E-45 Positive range: 1.4E-45 to E+38 double Negative range: 64-bit IEEE E+308 to -4.9E-324 Positive range: 4.9E-324 to E+308

103 Reading Numbers from the Keyboard Scanner input = new Scanner(System.in); int value = input.nextint(); Method Description nextbyte() reads an integer of the byte type. nextshort() reads an integer of the short type. nextint() reads an integer of the int type. nextlong() reads an integer of the long type. nextfloat() reads a number of the float type. nextdouble() reads a number of the double type.

104 Numeric Operators Name Meaning Example Result + Addition Subtraction * Multiplication 300 * / Division 1.0 / % Remainder 20 % 3 2

105 Integer Division +,-,*,/,and% 5/2yieldsaninteger2. 5.0/2yieldsadoublevalue2.5 5%2yields1(theremainderofthedivision)

106 Calculating Area of Circle: Reading Input from a Console import java.util.scanner; public class CalculateCircleArea{ public static void main(string[] args) { double radius; double area; // Prompt Users to Enter radius of the circle Scanner input = new Scanner(System.in); System.out.print("Enter the radius circle: "); //Read the input from a console to the radius variable radius = input.nextdouble(); //Calculate the area of the circle using radius then store it to the Variable area area = radius * radius* ; } } //Display the result to the console (Standard Output) System.out.println("The area is " + area);

107 import javax.swing.joptionpane; public class CalculateAreaCircle { public static void main(string[] args) { double radius; double area; // Enter radius of the cylinder String radiusstring = JOptionPane.showInputDialog(null, "Enter radius of the circle", "Circle Area Calculator", JOptionPane.QUESTION_MESSAGE); // Convert string to double radius = Double.parseDouble(radiusString); area = radius * radius * ; JOptionPane.showMessageDialog ( null, "Area of Circle is " + area ); } } System.out.println("The Area of the Circle is " + area);

108

109 Foot Meter Converter import javax.swing.joptionpane; public class FootToMeterConverter{ public static void main(string[] args) { double foot; double meter; // Enter in Foot to Convert String footstring = JOptionPane.showInputDialog(null, "Enter the length in Foot to Convert", "FootToMeterConverter", JOptionPane.QUESTION_MESSAGE); // Convert string to double foot = Double.parseDouble(footString); meter = * foot; JOptionPane.showMessageDialog(null, "The Length in Meter is " + meter ); System.out.println("The Length in Meter is " + meter); }

110

111 Programming: Selections

112 Lab3: A Simple Math Learning Tool This example creates a program to let a first grader practice additions. The program randomly generates two single-digit integers number1 and number2 and displays a question such as What is 7 + 9? to the student. After the student types the answer, the program displays a message to indicate whether the answer is true or false. IMPORTANT NOTE: If you cannot run the buttons, see Animation AdditionQuiz Run 112

113 The boolean Type and Operators Often in a program you need to compare two values, such as whether iis greater than j. Java provides six comparison operators (also known as relational operators) that can be used to compare two values. The result of the comparison is a Boolean value: true or false. // b = 1 for true or 0 for false boolean b; b = (1 > 2); // b = 0 for false

114 Relational Operators Java Mathematics Name Example Result Operator Symbol (radius is 5) < < less than radius < 0 false <= less than or equal to radius <= 0 false > > greater than radius > 0 true >= greater than or equal to radius >= 0 true == = equal to radius == 0 false!= not equal to radius!= 0 true

115 Control structure: if-else Basic format: if (condition) { } // do something if condition is true else { // do something if condition is false (not true) }

116 Comparison Operators Simple Boolean expression is obtained from comparison operators: X == Y (x is equal to y) X!= Y (x is not equal to y) X < Y (x is less than y) X > Y (x is greater than y) X <= Y (x is less than or equal to y) X >= Y (x is greater than or equal to y)

117 Boolean Operators Complicated Boolean expression can be obtained by combining simpler expressions with Boolean operators: e1 && e2 ( logical and operator, returning true when both e1 and e2 are true) e1 e2 ( logical or operator, returning true when either e1 or e2 are true)!e1 ( logical not operator, returning true when e1 is false)

118 One-way if Statements if (boolean-expression) { statement(s); } if (radius >= 0) { area = radius * radius * PI; System.out.println("The area" + " for the circle of radius " + radius + " is " + area); }

119 Note if i > 0 { System.out.println("i is positive"); } (a) Wrong if (i > 0) { System.out.println("i is positive"); } (b) Correct if (i > 0) { System.out.println("i is positive"); } (a) Equivalent if (i > 0) System.out.println("i is positive"); (b)

120 The Two-way ifstatement if (boolean-expression) { statement(s)-for-the-true-case; } else { statement(s)-for-the-false-case; }

121 if-elseexample if (radius >= 0) { area = radius * radius * ; System.out.println("The area for the + circle of radius " + radius + " is " + area); } else { System.out.println("Negative input"); }

122 Multiple Alternative if Statements if (score >= 90.0) System.out.print("A"); else if (score >= 80.0) System.out.print("B"); else if (score >= 70.0) System.out.print("C"); else if (score >= 60.0) System.out.print("D"); else System.out.print("F"); Equivalent This is better if (score >= 90.0) System.out.print("A"); else if (score >= 80.0) System.out.print("B"); else if (score >= 70.0) System.out.print("C"); else if (score >= 60.0) System.out.print("D"); else System.out.print("F"); (a) (b)

123 Multi-Way if-else Statements

124 animation Trace if-else statement Suppose score is 70.0 The condition is false if (score >= 90.0) System.out.print("A"); else if (score >= 80.0) System.out.print("B"); else if (score >= 70.0) System.out.print("C"); else if (score >= 60.0) System.out.print("D"); else System.out.print("F");

125 animation Trace if-else statement Suppose score is 70.0 The condition is false if (score >= 90.0) System.out.print("A"); else if (score >= 80.0) System.out.print("B"); else if (score >= 70.0) System.out.print("C"); else if (score >= 60.0) System.out.print("D"); else System.out.print("F");

126 animation Trace if-else statement Suppose score is 70.0 The condition is true if (score >= 90.0) System.out.print("A"); else if (score >= 80.0) System.out.print("B"); else if (score >= 70.0) System.out.print("C"); else if (score >= 60.0) System.out.print("D"); else System.out.print("F");

127 animation Trace if-else statement Suppose score is 70.0 grade is C if (score >= 90.0) System.out.print("A"); else if (score >= 80.0) System.out.print("B"); else if (score >= 70.0) System.out.print("C"); else if (score >= 60.0) System.out.print("D"); else System.out.print("F");

128 animation Trace if-else statement Suppose score is 70.0 Exit the if statement if (score >= 90.0) System.out.print("A"); else if (score >= 80.0) System.out.print("B"); else if (score >= 70.0) System.out.print("C"); else if (score >= 60.0) System.out.print("D"); else System.out.print("F");

129 Lab3: A Simple Math Learning Tool This example creates a program to let a first grader practice additions. The program randomly generates two single-digit integers number1 and number2 and displays a question such as What is 7 + 9? to the student. After the student types the answer, the program displays a message to indicate whether the answer is true or false. IMPORTANT NOTE: If you cannot run the buttons, see Animation AdditionQuiz Run 129

130 Generating a Random Number import java.util.scanner; public class AdditionQuiz{ public static void main(string[] args) { int number1, number2, answer; // Generate Two Random Numbers from 1-10 number1 = (int)(math.random() * ); number2 = (int)(math.random() * ); System.out.print( "What is " + number1 +" + " + number2 + "? "); } }

131 Algorithm for A Simple Math Learning Tool AdditionQuiz{ 1. Generate two random numbers, save them to the variable number1, number2 2. Prompt user to answer what is number 1 + number 2 3. Read the user s answer from a console, save it to the variable answer 4. if (number1+ number2 == answer) Printout Correct! else Printout Wrong! }

132 import java.util.scanner; public class AdditionQuiz { public static void main(string[] args) { int number1; int number2; int answer; number1 = (int )(Math.random() * ); number2 = (int )(Math.random() * ); // Create a Scanner Scanner input = new Scanner(System.in); System.out.print( "What is " + number1 + " + " + number2 + "? "); answer = input.nextint(); } if ((number1 + number2) == answer) System.out.println("Correct, Hi Five!"); else System.out.println("Wrong, Try Again!"); }

133 Computer Science Labs and Projects Dept. of Electrical Engineering and Computer Science Cleveland State University

134 Engineering Design Process 1. Specify Identify a problem to be solved or an idea 2. Analyze and design Research and create a potential design solution 3. Implement Construct the prototyping system, process etc. 4. Test Verify and evaluate the design/implementation 5. Repeat steps 2 to 4 until testing is successful

135 Algorithms The procedures for strategies that define how a program should organized and be executed to achieve the required tasks. Many different algorithms for a same task so the most efficient and optimized one should be selected to program.

136 Data Structures Structures hold data that belong togetherin a program that are used to compute or execute the tasks Examples: Student record: id, name, major, gender, start year, gpa Bank account: account number, name, currency, balance Address book: name, address, telephone number In database applications, structures are called records.

137 Different types of data in each row structure in Table Employee Employee ID Name DeptID Salary Project 10 Nemo Company Picnic 20 Dory Big data Project 40 Gill Factory Sensor Project 52 Ray Cloud Project

138 Computer Science Lab 1 Installing a Programming Language Java in a Computer Learn How to Run a software (Program) in a Computer System

139 Computer Science Program Lab 2 Writing a Program that Calculates the Volume of a Cylinder 1. Read two inputs Radius of a Circle and Height of a Cylinder 2. Calculate the Volume of a Cylinder 3. Display the Calculated Volume of Cylinder

140 import java.util.scanner; public class CalculateCylinderVolume { public static void main(string[] args) { Scanner input = new Scanner(System.in); // Enter radius of the cylinder System.out.print("Enter the radius and length of a cylinder: "); double radius = input.nextdouble(); double length = input.nextdouble(); double area = radius * radius * ; double volume = area * length; } System.out.println("The area is " + area); System.out.println("The volume of the cylinder is " + volume); }

141 import javax.swing.joptionpane; public class UsingJOptionPane { public static void main(string[] args) { double radius; double length; double volume; // Enter radius of the cylinder String radiusstring = JOptionPane.showInputDialog(null, "Enter radius of the cylinder", "Cylinder Volume Calculator", JOptionPane.QUESTION_MESSAGE); // Convert string to double radius = Double.parseDouble(radiusString); // Enter length of the cylinder String lengthstring = JOptionPane.showInputDialog(null, "Enter length of the cylinder", "Cylinder Volume Calculator", JOptionPane.QUESTION_MESSAGE); // Convert string to double length = Double.parseDouble(lengthString); volume = radius * radius * *length; JOptionPane.showMessageDialog ( null, "Volume of Cylinder is " + volume ); } } System.out.println("The volume of the cylinder is " + volume);

142

143 Lab3: A Simple Math Learning Tool This example creates a program to let a first grader practice additions. The program randomly generates two single-digit integers number1 and number2 and displays a question such as What is 7 + 9? to the student. After the student types the answer, the program displays a message to indicate whether the answer is true or false. IMPORTANT NOTE: If you cannot run the buttons, see Animation AdditionQuiz Run 143

144 Generating a Random Number import java.util.scanner; public class AdditionQuiz{ public static void main(string[] args) { int number1, number2, answer; // Generate Two Random Numbers from 1-10 number1 = (int)(math.random() * ); number2 = (int)(math.random() * ); System.out.print( "What is " + number1 +" + " + number2 + "? "); } }

145 Algorithm for A Simple Math Learning Tool AdditionQuiz{ 1. Generate two random numbers, save them to the variable number1, number2 2. Prompt user to answer what is number 1 + number 2 3. Read the user s answer from a console, save it to the variable answer 4. if (number1+ number2 == answer) Printout Correct! else Printout Wrong! }

146 import java.util.scanner; public class AdditionQuiz { public static void main(string[] args) { int number1; int number2; int answer; number1 = (int )(Math.random() * ); number2 = (int )(Math.random() * ); // Create a Scanner Scanner input = new Scanner(System.in); System.out.print( "What is " + number1 + " + " + number2 + "? "); answer = input.nextint(); } if ((number1 + number2) == answer) System.out.println("Correct, Hi Five!"); else System.out.println("Wrong, Try Again!"); }

147 Computer Science Lab 4 Creating a Webpage

Chapter 1 Introduction to Computers, Programs, and Java

Chapter 1 Introduction to Computers, Programs, and Java Chapter 1 Introduction to Computers, Programs, and Java 1 Objectives To understand computer basics, programs, and operating systems ( 1.2 1.4). To describe the relationship between Java and the World Wide

More information

Chapter 1 Introduction to Computers, Programs, and Java

Chapter 1 Introduction to Computers, Programs, and Java Chapter 1 Introduction to Computers, Programs, and Java 1 Objectives To understand computer basics, programs, and operating systems ( 1.2 1.4). To describe the relationship between Java and the World Wide

More information

Java Language. Programs. Computer programs, known as software, are instructions to the computer. You tell a computer what to do through programs.

Java Language. Programs. Computer programs, known as software, are instructions to the computer. You tell a computer what to do through programs. Introduction to Programming Java Language Programs Computer programs, known as software, are instructions to the computer. You tell a computer what to do through programs. Programs are written using programming

More information

Chapter 1: Introduction to Computers, Programs, and Java

Chapter 1: Introduction to Computers, Programs, and Java Chapter 1: Introduction to Computers, Programs, and Java CS1: Java Programming Colorado State University Original slides by Daniel Liang Modified slides by Chris Wilcox 1 Objectives To understand computer

More information

Chapter 1 Introduction to Computers, Programs, and Java

Chapter 1 Introduction to Computers, Programs, and Java Chapter 1 Introduction to Computers, Programs, and Java 1 Objectives To review computer basics, programs, and operating systems ( 1.2-1.4). To explore the relationship between Java and the World Wide Web

More information

Introduction to Java. Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved.

Introduction to Java. Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. Introduction to Java 1 Programs Computer programs, known as software, are instructions to the computer. You tell a computer what to do through programs. Programs are written using programming languages.

More information

Chapter 1 Introduction to Computers, Programs, and Java

Chapter 1 Introduction to Computers, Programs, and Java Chapter 1 Introduction to Computers, Programs, and Java 1 Objectives To understand computer basics, programs, and operating systems ( 1.2 1.4). To describe the relationship between Java and the World Wide

More information

Programming: detailed instructions which tell the computer hardware what to do aka software Computer Science: the study NOT of computers, but of what

Programming: detailed instructions which tell the computer hardware what to do aka software Computer Science: the study NOT of computers, but of what Programming: detailed instructions which tell the computer hardware what to do aka software Computer Science: the study NOT of computers, but of what can be computed what processes a computer can execute

More information

Objectives. Chapter 1 Introduction to Computers, Programs, and Java. What is a Computer?

Objectives. Chapter 1 Introduction to Computers, Programs, and Java. What is a Computer? Chapter 1 Introduction to Computers, Programs, and Java Objectives To review computer basics, programs, and operating systems ( 12-14) To explore the relationship between Java and the World Wide Web (

More information

Chapter 1 Introduction to Computers, Programs, and Java

Chapter 1 Introduction to Computers, Programs, and Java Chapter 1 Introduction to Computers, Programs, and Java 1 Programs Computer programs, known as software, are instructions to the computer. You tell a computer what to do through programs. Without programs,

More information

Elements of Computers and Programming Dr. William C. Bulko. What is a Computer?

Elements of Computers and Programming Dr. William C. Bulko. What is a Computer? Elements of Computers and Programming Dr. William C. Bulko What is a Computer? 2017 What is a Computer? A typical computer consists of: a CPU memory a hard disk a monitor and one or more communication

More information

Module 1: Introduction to Computers, Programs, and Java

Module 1: Introduction to Computers, Programs, and Java Module 1: Introduction to Computers, Programs, and Java Module 1: Introduction to Java page 1 Objectives To review Program Design and Problem-Solving Techniques To describe the relationship between Java

More information

Chapter 1 Introduction to Computers, Programs, and Java

Chapter 1 Introduction to Computers, Programs, and Java Chapter 1 Introduction to Computers, Programs, and Java 1.1 Introduction The central theme of this book is to learn how to solve problems by writing a program. This book teaches you how to create programs

More information

Getting Started. Chapter 1. Java Programming FROM THE BEGINNING. Chapter 1: Getting Started

Getting Started. Chapter 1. Java Programming FROM THE BEGINNING. Chapter 1: Getting Started Chapter 1 Getting Started 1 1.1 What Do Computers Do? A computer system is an integrated collection of hardware and software components. Hardware refers to the electronics inside a computer. Software consists

More information

Lecture 1: Introduction to Java

Lecture 1: Introduction to Java Lecture 1: Introduction to Java 1 Programs Computer programs, known as software, are instructions to the computer. You tell a computer what to do through programs. Without programs, a computer is an empty

More information

Introduction to Computers, Programs, and Java. CSE 114, Computer Science 1 Stony Brook University

Introduction to Computers, Programs, and Java. CSE 114, Computer Science 1 Stony Brook University Introduction to Computers, Programs, and Java CSE 114, Computer Science 1 Stony Brook University http://www.cs.stonybrook.edu/~cse114 What is a Computer? A computer consists of a CPU, memory, hard disk,

More information

Chapter 1 Introduction to Computers, Programs, and Java. What is a Computer? A Bit of History

Chapter 1 Introduction to Computers, Programs, and Java. What is a Computer? A Bit of History Chapter 1 Introduction to Computers, Programs, and Java CS170 Introduction to Computer Science 1 What is a Computer? A machine that manipulates data according to a list of instructions Consists of hardware

More information

Chapter 1 Introduction to Computers, Programs, and Java

Chapter 1 Introduction to Computers, Programs, and Java Chapter Introduction to Computers, Programs, and Java. Introduction Java is the Internet program language Why Java? The answer is that Java enables user to deploy applications on the Internet for servers,

More information

Networks Programming Engr. Abdul-Rahman Mahmood MS, PMP, MCP, QMR(ISO9001:2000)

Networks Programming Engr. Abdul-Rahman Mahmood MS, PMP, MCP, QMR(ISO9001:2000) Networks Programming Engr. Abdul-Rahman Mahmood MS, PMP, MCP, QMR(ISO9001:2000) armahmood786@yahoo.com alphasecure@gmail.com alphapeeler.sf.net/pubkeys/pkey.htm http://alphapeeler.sourceforge.net pk.linkedin.com/in/armahmood

More information

Chapter 1 Introduction to Java

Chapter 1 Introduction to Java Chapter 1 Introduction to Java 1 Why Java? The answer is that Java enables users to develop and deploy applications on the Internet for servers, desktop computers, and small hand-held devices. The future

More information

Introduction. Introduction to OOP with Java. Lecture 01: Introduction to OOP with Java - AKF Sep AbuKhleiF -

Introduction. Introduction to OOP with Java. Lecture 01: Introduction to OOP with Java - AKF Sep AbuKhleiF - Introduction to OOP with Java Instructor: AbuKhleif, Mohammad Noor Sep 2017 www.abukhleif.com Lecture 01: Introduction Instructor: AbuKhleif, Mohammad Noor Sep 2017 www.abukhleif.com AbuKhleiF - www.abukhleif.com

More information

Introduction to OOP with Java. Instructor: AbuKhleif, Mohammad Noor Sep 2017

Introduction to OOP with Java. Instructor: AbuKhleif, Mohammad Noor Sep 2017 Introduction to OOP with Java Instructor: AbuKhleif, Mohammad Noor Sep 2017 Lecture 01: Introduction Instructor: AbuKhleif, Mohammad Noor Sep 2017 Instructor AbuKhleif, Mohammad Noor Studied Computer Engineer

More information

Chapter 2 Elementary Programming

Chapter 2 Elementary Programming Chapter 2 Elementary Programming Part I 1 Motivations In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from this chapter, you will learn how to solve practical

More information

Chapter 1 Introduction to Computers, Programs, and Java

Chapter 1 Introduction to Computers, Programs, and Java Chapter 1 Introduction to Computers, Programs, and Java 1.1 What are hardware and software? 1. A computer is an electronic device that stores and processes data. A computer includes both hardware and software.

More information

CMSC 1513 Lecture 1.2

CMSC 1513 Lecture 1.2 Key Point: A computer is an electronic device that stores and processes data. Hardware Software Hardware comprises the visible, physical elements of the computer. Software provides the invisible instructions

More information

Chapter 2 ELEMENTARY PROGRAMMING

Chapter 2 ELEMENTARY PROGRAMMING Chapter 2 ELEMENTARY PROGRAMMING Lecture notes for computer programming 1 Faculty of Engineering and Information Technology Prepared by: Iyad Albayouk ١ Objectives To write Java programs to perform simple

More information

Chapter 3 Selections. Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved.

Chapter 3 Selections. Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved. Chapter 3 Selections Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved. 0132130807 1 Motivations If you assigned a negative value for radius

More information

Programming with Java

Programming with Java Programming with Java Data Types & Input Statement Lecture 04 First stage Software Engineering Dep. Saman M. Omer 2017-2018 Objectives q By the end of this lecture you should be able to : ü Know rules

More information

Computer Programming, I. Laboratory Manual. Experiment #2. Elementary Programming

Computer Programming, I. Laboratory Manual. Experiment #2. Elementary Programming Think Twice Code Once The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2005 Khaleel I. Shaheen Computer Programming, I Laboratory Manual Experiment #2

More information

CHAPTER 1 INTRODUCTION TO COMPUTERS, PROGRAMS, AND JAVA. Objectives

CHAPTER 1 INTRODUCTION TO COMPUTERS, PROGRAMS, AND JAVA. Objectives CHAPTER 1 INTRODUCTION TO COMPUTERS, PROGRAMS, AND JAVA Objectives To review computer basics, programs, and operating systems ( 1.2 1.4). To explore the relationship between Java and the World Wide Web

More information

Chapter 2 Elementary Programming. Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved.

Chapter 2 Elementary Programming. Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. Chapter 2 Elementary Programming 1 Motivations In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from this chapter, you will learn how to solve practical problems

More information

CEN 414 Java Programming

CEN 414 Java Programming CEN 414 Java Programming Instructor: H. Esin ÜNAL SPRING 2017 Slides are modified from original slides of Y. Daniel Liang WEEK 2 ELEMENTARY PROGRAMMING 2 Computing the Area of a Circle public class ComputeArea

More information

Motivations. Chapter 2: Elementary Programming 8/24/18. Introducing Programming with an Example. Trace a Program Execution. Trace a Program Execution

Motivations. Chapter 2: Elementary Programming 8/24/18. Introducing Programming with an Example. Trace a Program Execution. Trace a Program Execution Chapter 2: Elementary Programming CS1: Java Programming Colorado State University Original slides by Daniel Liang Modified slides by Chris Wilcox Motivations In the preceding chapter, you learned how to

More information

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments. Java How to Program, 9/e Education, Inc. All Rights Reserved. } Java application programming } Use tools from the JDK to compile and run programs. } Videos at www.deitel.com/books/jhtp9/ Help you get started

More information

Computer Programming, I. Laboratory Manual. Experiment #3. Selections

Computer Programming, I. Laboratory Manual. Experiment #3. Selections Think Twice Code Once The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2005 Khaleel I. Shaheen Computer Programming, I Laboratory Manual Experiment #3

More information

Tester vs. Controller. Elementary Programming. Learning Outcomes. Compile Time vs. Run Time

Tester vs. Controller. Elementary Programming. Learning Outcomes. Compile Time vs. Run Time Tester vs. Controller Elementary Programming EECS1022: Programming for Mobile Computing Winter 2018 CHEN-WEI WANG For effective illustrations, code examples will mostly be written in the form of a tester

More information

Chapter 2. Elementary Programming

Chapter 2. Elementary Programming Chapter 2 Elementary Programming 1 Objectives To write Java programs to perform simple calculations To obtain input from the console using the Scanner class To use identifiers to name variables, constants,

More information

Elementary Programming

Elementary Programming Elementary Programming EECS1022: Programming for Mobile Computing Winter 2018 CHEN-WEI WANG Learning Outcomes Learn ingredients of elementary programming: data types [numbers, characters, strings] literal

More information

Lecture 1: Introduction to Java

Lecture 1: Introduction to Java CC316: Object Oriented Programming Lecture 1: Introduction to Java Dr. Manal Helal, Spring 2016 http://moodle.manalhelal.com rights reserved. Course Description This course introduces JAVA to students

More information

Course Outline. Introduction to java

Course Outline. Introduction to java Course Outline 1. Introduction to OO programming 2. Language Basics Syntax and Semantics 3. Algorithms, stepwise refinements. 4. Quiz/Assignment ( 5. Repetitions (for loops) 6. Writing simple classes 7.

More information

Entry Point of Execution: the main Method. Elementary Programming. Learning Outcomes. Development Process

Entry Point of Execution: the main Method. Elementary Programming. Learning Outcomes. Development Process Entry Point of Execution: the main Method Elementary Programming EECS1021: Object Oriented Programming: from Sensors to Actuators Winter 2019 CHEN-WEI WANG For now, all your programming exercises will

More information

II. Compiling and launching from Command-Line, IDE A simple JAVA program

II. Compiling and launching from Command-Line, IDE A simple JAVA program Contents Topic 01 - Java Fundamentals I. Introducing JAVA II. Compiling and launching from Command-Line, IDE A simple JAVA program III. How does JAVA work IV. Review - Programming Style, Documentation,

More information

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved. Assoc. Prof. Dr. Marenglen Biba (C) 2010 Pearson Education, Inc. All rights reserved. Java application A computer program that executes when you use the java command to launch the Java Virtual Machine

More information

Chapter. Focus of the Course. Object-Oriented Software Development. program design, implementation, and testing

Chapter. Focus of the Course. Object-Oriented Software Development. program design, implementation, and testing Introduction 1 Chapter 5 TH EDITION Lewis & Loftus java Software Solutions Foundations of Program Design 2007 Pearson Addison-Wesley. All rights reserved Focus of the Course Object-Oriented Software Development

More information

Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word. Chapter 1 Introduction to Computers, Programs, and Java

Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word. Chapter 1 Introduction to Computers, Programs, and Java Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word Chapter 1 Introduction to Computers, Programs, and Java Chapter 2 Primitive Data Types and Operations Chapter 3 Selection

More information

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

Motivations. Chapter 3: Selections and Conditionals. Relational Operators 8/31/18. Objectives. Problem: A Simple Math Learning Tool Chapter 3: Selections and Conditionals CS1: Java Programming Colorado State University Motivations If you assigned a negative value for radius in Listing 2.2, ComputeAreaWithConsoleInput.java, the program

More information

Full file at

Full file at Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class

More information

Eng. Mohammed Alokshiya

Eng. Mohammed Alokshiya Islamic University of Gaza Faculty of Engineering Computer Engineering Dept. Computer Programming Lab (ECOM 2114) Lab 1 Introduction to Java Eng. Mohammed Alokshiya September 28, 2014 Java Programming

More information

Lecture Notes. System.out.println( Circle radius: + radius + area: + area); radius radius area area value

Lecture Notes. System.out.println( Circle radius: + radius + area: + area); radius radius area area value Lecture Notes 1. Comments a. /* */ b. // 2. Program Structures a. public class ComputeArea { public static void main(string[ ] args) { // input radius // compute area algorithm // output area Actions to

More information

Entry Point of Execution: the main Method. Elementary Programming. Compile Time vs. Run Time. Learning Outcomes

Entry Point of Execution: the main Method. Elementary Programming. Compile Time vs. Run Time. Learning Outcomes Entry Point of Execution: the main Method Elementary Programming EECS2030: Advanced Object Oriented Programming Fall 2017 CHEN-WEI WANG For now, all your programming exercises will be defined within the

More information

Chapter 1: Introduction to Computers and Java

Chapter 1: Introduction to Computers and Java Chapter 1: Introduction to Computers and Java Starting Out with Java: From Control Structures through Objects Fifth Edition by Tony Gaddis Chapter Topics Chapter 1 discusses the following main topics:

More information

Chapter 2 Primitive Data Types and Operations. Objectives

Chapter 2 Primitive Data Types and Operations. Objectives Chapter 2 Primitive Data Types and Operations Prerequisites for Part I Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word Chapter 1 Introduction to Computers, Programs,

More information

8/23/2014. Chapter Topics. Introduction. Java History. Why Program? Java Applications and Applets. Chapter 1: Introduction to Computers and Java

8/23/2014. Chapter Topics. Introduction. Java History. Why Program? Java Applications and Applets. Chapter 1: Introduction to Computers and Java Chapter 1: Introduction to Computers and Java Starting Out with Java: From Control Structures through Objects Fifth Edition by Tony Gaddis Chapter Topics Chapter 1 discusses the following main topics:

More information

Chapter 1. Introduction to Computers and Programming. M hiwa ahmad aziz

Chapter 1. Introduction to Computers and Programming.   M hiwa ahmad aziz . Chapter 1 Introduction to Computers and Programming www.raparinweb.com M hiwa ahmad aziz 1 Ch 1 - Introduction to Computers and Programming Hardware Terminology Main Memory Auxiliary Memory Drives Writing

More information

CHAPTER 1 Introduction to Computers and Java

CHAPTER 1 Introduction to Computers and Java CHAPTER 1 Introduction to Computers and Java Copyright 2016 Pearson Education, Inc., Hoboken NJ Chapter Topics Chapter 1 discusses the following main topics: Why Program? Computer Systems: Hardware and

More information

CIS260 Summer Exam 1 First Name Last Name: 2) is the brain of a computer. 2) A) Memory B) Hardware C) Disk D) CPU

CIS260 Summer Exam 1 First Name Last Name: 2) is the brain of a computer. 2) A) Memory B) Hardware C) Disk D) CPU CIS260 Summer 2012 - Exam 1 First Name Last Name: MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) is the physical aspect of the computer that can

More information

Chapter 3. Selections

Chapter 3. Selections Chapter 3 Selections 1 Outline 1. Flow of Control 2. Conditional Statements 3. The if Statement 4. The if-else Statement 5. The Conditional operator 6. The Switch Statement 7. Useful Hints 2 1. Flow of

More information

Pace University. Fundamental Concepts of CS121 1

Pace University. Fundamental Concepts of CS121 1 Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction

More information

What did we talk about last time? Examples switch statements

What did we talk about last time? Examples switch statements Week 4 - Friday What did we talk about last time? Examples switch statements History of computers Hardware Software development Basic Java syntax Output with System.out.print() Mechanical Calculation

More information

Lecture Set 2: Starting Java

Lecture Set 2: Starting Java Lecture Set 2: Starting Java 1. Java Concepts 2. Java Programming Basics 3. User output 4. Variables and types 5. Expressions 6. User input 7. Uninitialized Variables 0 This Course: Intro to Procedural

More information

Intentionally Blank 0

Intentionally Blank 0 Intentionally Blank 0 Technology in Action Chapter 2 Looking at Computers: Understanding the Parts 1 Understanding Your Computer: Computers are Data Processing Devices Perform four major functions Input:

More information

Lecture Set 2: Starting Java

Lecture Set 2: Starting Java Lecture Set 2: Starting Java 1. Java Concepts 2. Java Programming Basics 3. User output 4. Variables and types 5. Expressions 6. User input 7. Uninitialized Variables 0 This Course: Intro to Procedural

More information

Introduction to Java Applications; Input/Output and Operators

Introduction to Java Applications; Input/Output and Operators www.thestudycampus.com Introduction to Java Applications; Input/Output and Operators 2.1 Introduction 2.2 Your First Program in Java: Printing a Line of Text 2.3 Modifying Your First Java Program 2.4 Displaying

More information

Chapter 2 Elementary Programming

Chapter 2 Elementary Programming Chapter 2 Elementary Programming 1 Motivations In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from this chapter, you will learn how to solve practical problems

More information

Lesson 01 Introduction

Lesson 01 Introduction Lesson 01 Introduction MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz Lecturer in Management & IT M.Sc. In IS (SLIIT), PGD in IS (SLIIT), BBA (Hons.) Spl. in IS (SEUSL), MCP Programs Computer

More information

Computer is an electronic machine that can receive, store, transform and output data of all kinds (image, text, numeric, graphics and sound).

Computer is an electronic machine that can receive, store, transform and output data of all kinds (image, text, numeric, graphics and sound). ELECTRONIC COMPUTERS THEN AND NOW Computer is an electronic machine that can receive, store, transform and output data of all kinds (image, text, numeric, graphics and sound). In the Past (i.e., during

More information

COMP Computer Basics. Yi Hong May 13, 2015

COMP Computer Basics. Yi Hong May 13, 2015 COMP 110-001 Computer Basics Yi Hong May 13, 2015 Today Hardware and memory Programs and compiling Your first program 2 Before Programming Need to know basics of a computer Understand what your program

More information

Università degli Studi di Bologna Facoltà di Ingegneria. Principles, Models, and Applications for Distributed Systems M

Università degli Studi di Bologna Facoltà di Ingegneria. Principles, Models, and Applications for Distributed Systems M Università degli Studi di Bologna Facoltà di Ingegneria Principles, Models, and Applications for Distributed Systems M tutor Isam M. Al Jawarneh, PhD student isam.aljawarneh3@unibo.it Mobile Middleware

More information

Introduction to Computers and Java

Introduction to Computers and Java Introduction to Computers and Java Harald Gall, Prof. Dr. Institut für Informatik Universität Zürich http://seal.ifi.uzh.ch 2008 W. Savitch, F.M. Carrano, Pearson Prentice Hall Objectives Overview computer

More information

Introduction to Computers and Java. Objectives. Outline. Harald Gall, Prof. Dr. Institut für Informatik Universität Zürich.

Introduction to Computers and Java. Objectives. Outline. Harald Gall, Prof. Dr. Institut für Informatik Universität Zürich. Introduction to Computers and Java Harald Gall, Prof. Dr. Institut für Informatik Universität Zürich http://seal.ifi.uzh.ch 2008 W. Savitch, F.M. Carrano, Pearson Prentice Hall Objectives! Overview computer

More information

Introduction to Computers and Java

Introduction to Computers and Java Introduction to Computers and Java Harald Gall, Prof. Dr. Institut für Informatik Universität Zürich http://seal.ifi.uzh.ch 2008 W. Savitch, F.M. Carrano, Pearson Prentice Hall Objectives! Overview computer

More information

CS1150 Principles of Computer Science Boolean, Selection Statements

CS1150 Principles of Computer Science Boolean, Selection Statements CS1150 Principles of Computer Science Boolean, Selection Statements Yanyan Zhuang Department of Computer Science http://www.cs.uccs.edu/~yzhuang CS1150 Math Center https://www.uccs.edu/mathcenter/schedules

More information

IQTIDAR ALI Lecturer IBMS Agriculture University Peshawar

IQTIDAR ALI Lecturer IBMS Agriculture University Peshawar IQTIDAR ALI Lecturer IBMS Agriculture University Peshawar Upon completing the course, you will understand Create, compile, and run Java programs Primitive data types Java control flow Operator Methods

More information

Chapter 2 Primitive Data Types and Operations

Chapter 2 Primitive Data Types and Operations Chapter 2 Primitive Data Types and Operations 2.1 Introduction You will be introduced to Java primitive data types and related subjects, such as variables constants, data types, operators, and expressions.

More information

Elementary Programming. CSE 114, Computer Science 1 Stony Brook University

Elementary Programming. CSE 114, Computer Science 1 Stony Brook University Elementary Programming CSE 114, Computer Science 1 Stony Brook University http://www.cs.stonybrook.edu/~cse114 1 Variables In a program, the variables store data Primitive type variables store single pieces

More information

Introduction to Computers and Java. Objectives. Outline. Harald Gall, Prof. Dr. Institut für Informatik Universität Zürich.

Introduction to Computers and Java. Objectives. Outline. Harald Gall, Prof. Dr. Institut für Informatik Universität Zürich. Introduction to Computers and Java Harald Gall, Prof. Dr. Institut für Informatik Universität Zürich http://seal.ifi.uzh.ch 2008 W. Savitch, F.M. Carrano, Pearson Prentice Hall Objectives Overview computer

More information

CONDITIONAL EXECUTION

CONDITIONAL EXECUTION CONDITIONAL EXECUTION yes x > y? no max = x; max = y; logical AND logical OR logical NOT &&! Fundamentals of Computer Science I Outline Conditional Execution if then if then Nested if then statements Comparisons

More information

Motivations 9/14/2010. Introducing Programming with an Example. Chapter 2 Elementary Programming. Objectives

Motivations 9/14/2010. Introducing Programming with an Example. Chapter 2 Elementary Programming. Objectives Chapter 2 Elementary Programming Motivations In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from this chapter, you will learn how to solve practical problems

More information

C H A P T E R 1. Introduction to Computers and Programming

C H A P T E R 1. Introduction to Computers and Programming C H A P T E R 1 Introduction to Computers and Programming Topics Introduction Hardware and Software How Computers Store Data How a Program Works Using Python Computer Uses What do students use computers

More information

Introduction to Java Applications

Introduction to Java Applications 2 Introduction to Java Applications OBJECTIVES In this chapter you will learn: To write simple Java applications. To use input and output statements. Java s primitive types. Basic memory concepts. To use

More information

Date: Dr. Essam Halim

Date: Dr. Essam Halim Assignment (1) Date: 11-2-2013 Dr. Essam Halim Part 1: Chapter 2 Elementary Programming 1 Suppose a Scanner object is created as follows: Scanner input = new Scanner(System.in); What method do you use

More information

Datatypes, Variables, and Operations

Datatypes, Variables, and Operations Datatypes, Variables, and Operations 1 Primitive Type Classification 2 Numerical Data Types Name Range Storage Size byte 2 7 to 2 7 1 (-128 to 127) 8-bit signed short 2 15 to 2 15 1 (-32768 to 32767) 16-bit

More information

Topics. Hardware and Software. Introduction. Main Memory. The CPU 9/21/2014. Introduction to Computers and Programming

Topics. Hardware and Software. Introduction. Main Memory. The CPU 9/21/2014. Introduction to Computers and Programming Topics C H A P T E R 1 Introduction to Computers and Programming Introduction Hardware and Software How Computers Store Data Using Python Introduction Computers can be programmed Designed to do any job

More information

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Java Basics

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Java Basics WIT COMP1000 Java Basics Java Origins Java was developed by James Gosling at Sun Microsystems in the early 1990s It was derived largely from the C++ programming language with several enhancements Java

More information

Chapter 3 Selection Statements

Chapter 3 Selection Statements Chapter 3 Selection Statements 3.1 Introduction Java provides selection statements that let you choose actions with two or more alternative courses. Selection statements use conditions. Conditions are

More information

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

Section 2.2 Your First Program in Java: Printing a Line of Text Chapter 2 Introduction to Java Applications Section 2.2 Your First Program in Java: Printing a Line of Text 2.2 Q1: End-of-line comments that should be ignored by the compiler are denoted using a. Two

More information

4 WORKING WITH DATA TYPES AND OPERATIONS

4 WORKING WITH DATA TYPES AND OPERATIONS WORKING WITH NUMERIC VALUES 27 4 WORKING WITH DATA TYPES AND OPERATIONS WORKING WITH NUMERIC VALUES This application will declare and display numeric values. To declare and display an integer value in

More information

JAVA Programming Concepts

JAVA Programming Concepts JAVA Programming Concepts M. G. Abbas Malik Assistant Professor Faculty of Computing and Information Technology University of Jeddah, Jeddah, KSA mgmalik@uj.edu.sa Programming is the art of Problem Solving

More information

Lecture 1 Java SE Programming

Lecture 1 Java SE Programming Lecture 1 Java SE Programming presentation Java Programming Software App Development Assoc. Prof. Cristian Toma Ph.D. D.I.C.E/D.E.I.C Department of Economic Informatics & Cybernetics www.dice.ase.ro cristian.toma@ie.ase.ro

More information

Fundamentals of Programming Data Types & Methods

Fundamentals of Programming Data Types & Methods Fundamentals of Programming Data Types & Methods By Budditha Hettige Overview Summary (Previous Lesson) Java Data types Default values Variables Input data from keyboard Display results Methods Operators

More information

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

Interpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled Interpreted vs Compiled Python 1 Java Interpreted Easy to run and test Quicker prototyping Program runs slower Compiled Execution time faster Virtual Machine compiled code portable Java Compile > javac

More information

Terminology, Types of Computers & Computer Hardware

Terminology, Types of Computers & Computer Hardware Terminology, Types of Computers & Computer Hardware Basic Terminology 1.Computer A device that accepts input, processes data, stores data, and produces output, all according to a series of stored instructions.

More information

History of Java. Java was originally developed by Sun Microsystems star:ng in This language was ini:ally called Oak Renamed Java in 1995

History of Java. Java was originally developed by Sun Microsystems star:ng in This language was ini:ally called Oak Renamed Java in 1995 Java Introduc)on History of Java Java was originally developed by Sun Microsystems star:ng in 1991 James Gosling Patrick Naughton Chris Warth Ed Frank Mike Sheridan This language was ini:ally called Oak

More information

Computer ANAMIKA ACADEMY. Mo Which function has the ability to move from one web page to another Hyper link

Computer ANAMIKA ACADEMY. Mo Which function has the ability to move from one web page to another Hyper link 1. Which function has the ability to move from one web page to another Hyper link web page? 2. What is the full name of GUI? GRAPHICAL USER INTERFACE 3. Which function keys are used to make spell and mild

More information

9/11/08 (c) 2008 Matthew J. Rutherford Class (c) 2008 Matthew J. Rutherford Class

9/11/08 (c) 2008 Matthew J. Rutherford Class (c) 2008 Matthew J. Rutherford Class 1 2 3 4 5 6 Walter Savitch Frank M. Carrano Introduction to Computers and Java Chapter 1 ISBN 0136130887 2007 Pearson Education, Inc., Upper Saddle River, NJ. All Rights Reserved 7 Hardware and Software

More information

Outline. Overview. Control statements. Classes and methods. history and advantage how to: program, compile and execute 8 data types 3 types of errors

Outline. Overview. Control statements. Classes and methods. history and advantage how to: program, compile and execute 8 data types 3 types of errors Outline Overview history and advantage how to: program, compile and execute 8 data types 3 types of errors Control statements Selection and repetition statements Classes and methods methods... 2 Oak A

More information

The Computer System. Hardware = Physical Computer. Software = Computer Programs. People = End Users & Programmers. people

The Computer System. Hardware = Physical Computer. Software = Computer Programs. People = End Users & Programmers. people The Computer System Hardware = Physical Computer The equipment associated with a computer system. hardware software people The set of instructions that tell a computer what to do. Use the power of the

More information

false, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4

false, import, new 1 class Lecture2 { 2 3 Data types, Variables, and Operators 4 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4 5 } 6 7 // Keywords: 8 byte, short, int, long, char, float, double, boolean, true, false, import, new Zheng-Liang Lu Java Programming 45

More information

Eng. Mohammed S. Abdualal

Eng. Mohammed S. Abdualal Islamic University of Gaza Faculty of Engineering Computer Engineering Department Computer Programming Lab (ECOM 2124) Created by Eng: Mohammed Alokshiya Modified by Eng: Mohammed Abdualal Lab 1 Introduction

More information

Oct Decision Structures cont d

Oct Decision Structures cont d Oct. 29 - Decision Structures cont d Programming Style and the if Statement Even though an if statement usually spans more than one line, it is really one statement. For instance, the following if statements

More information