Fundamentals of Programming. Budditha Hettige Department of Computer Science
|
|
- Patricia Skinner
- 5 years ago
- Views:
Transcription
1 Fundamentals of Programming Budditha Hettige Department of Computer Science
2 Fundamentals of Programming Course Structure Lectures 30 Hours Practical /Tutorials 30 hours Assignment (30%) Practical Test (10 marks) Quizzes 4 (Get maximum 2 ) (10 x2 = 20 marks ) Total 30% Final Examination (70 %) 4 Questions (3 hours) (70%) Reference: 7/11/2015 Budditha Hettige (budditha@yahoo.com) 2
3 Course Structure Introduction Steps to Computer Programming Introduction to Java Input and output Variables Selections (if, switch) Loops (for, while, do-while) Methods To-Down Design Arrays Console application Menu driven application development Budditha Hettige 3
4 Introduction to Programming 7/11/2015 Budditha Hettige 4
5 Why people use machines? 7/11/2015 Budditha Hettige 5
6 Machines Café Machine ATM machine Calculator make a tea money transaction solve equation Each Machine has Input Output Process input Process Output Budditha Hettige (budditha@yahoo.com) 6
7 Café Machine Input Sugar Water Coffee Milk Output Tea Process???? Input Process Output Budditha Hettige 7
8 ATM machine Input??? Output??? Process??? Budditha Hettige 8
9 Calculator Input??? Output??? Process??? Budditha Hettige 9
10 Process of a Machine Work through the instructions given to it Read Write Do some calculations Go to next instruction The sequence of instructions is call a Program Program is a story to tell some task to others Budditha Hettige (budditha@yahoo.com) 10
11 What is a Programming? Programming is the way to give instructions Each program has Start Some work End Program is given/execute through the machine understood language Budditha Hettige (budditha@yahoo.com) 11
12 A Computer Machine that can solve problems for people by carrying out instructions given to it The sequence of instructions is called Program The language machine can understand is called machine language Budditha Hettige 12
13 Machine Language Machine language is a set of instructions executed directly by a computer's central processing unit (CPU) Budditha Hettige (budditha@yahoo.com) 13
14 Machine Language contd.. Advantages Machine can directly access (Electronic circuit) High Speed Disadvantages Human cannot identify Machine depended (Hardware depended) Budditha Hettige 14
15 Computer Language(s) Artificial Languages Human readable Ex: C/C++, Java Programming Language(L n ) Translator/ Interpreter Machine Language (L 0 ) Program ming Language (Ln) Machine Language (L 0 ) Machine Budditha Hettige (budditha@yahoo.com) 15
16 Interpretation Each instruction in L1 can execute through the relevant L0 instructions directly Program is call interpreter Two languages are needed to closely related Example: Sinhala English Sinhala - Pali Budditha Hettige (budditha@yahoo.com) 16
17 Translator (L 1 L 0 ) 1. Replace each instruction written in L1 in to LO 2. Program now execute new program 3. Program is called compiler/ translator Budditha Hettige (budditha@yahoo.com) 17
18 Compilers Translate high-level language to machine language Input (Source code) The original program in a high level language Output (Object code/ Machine Code) The translated version in machine language Example C++ compiler, JAVA Compiler etc. Budditha Hettige (budditha@yahoo.com) 18
19 Programming steps Compilers. A compiler translates the source code to target code Preprocessor adds to or modifies the contents of the source file before the compiler begins processing the code Linker combines the compilergenerated machine code with precompiled library code or compiled code from other sources to make a complete executable program 7/11/2015 Budditha Hettige (budditha@yahoo.com) 19
20 Programming language generations This classification is used to indicate increasing power of programming styles 1. First-generation programming languages 2. Second-generation programming languages 3. Third-generation programming languages 4. Fourth-generation programming languages 5. Fifth-generation programming languages Budditha Hettige 20
21 First-generation programming language (1GL) Is a machine-level programming language Translator isn t used to compile The instructions in 1GL are made of binary numbers, represented by 1s and 0s Advantage The code can run very fast and very efficiently because the instructions are executed directly by the CPU Disadvantage When an error occurs, the code is not as easy to fix Budditha Hettige (budditha@yahoo.com) 21
22 Second-generation programming language(2gl) Assembly language. Properties The code can be read and written by a programmer The language is specific to a particular processor family and environment Used in kernels and device drivers Budditha Hettige (budditha@yahoo.com) 22
23 Third-generation programming languages (3GL) Languages are more programmer-friendly Example C, C++, C#, Java, BASIC and Pascal Support structured programming. Must be translated into machine language by a compiler or interpreter Advantages Easier to read, write, and maintain Budditha Hettige (budditha@yahoo.com) 23
24 Fourth-generation programming languages(4gl) Designed to reduce programming effort Consist of Set of libraries CRUD generators Report generators DBMS Visual design tool and integration API Different types of 4GLs Table-driven (codeless) programming PowerBuilder Data management SAS, SPSS Report-generator programming languages Oracle Developer Suite Budditha Hettige 24
25 Fifth-generation programming language(5gl) Based on solving problems using constraints given to the program, rather than using an algorithm written by a programmer Use mainly in Artificial Intelligence research Example Prolog, OPS5, and Mercury Budditha Hettige (budditha@yahoo.com) 25
26 Selecting a suitable Computer Language Readability How easy to write the program in this particular language? Reliability How much would it cost to develop using a given language? How complicated the syntax going to be? Does the language have standards for greater readability? Budditha Hettige (budditha@yahoo.com) 26
27 Example Assembly Language Program Device drivers, Virus C / C++ Program Device drivers, DLLs JAVA / Visual C++ Program Desktop applications, Web Applications Prolog AI based applications, Games, Translators Budditha Hettige (budditha@yahoo.com) 27
28 Exercise To solve the following problems, identify the input, output and the process Find the area of a room Search a place of a city Calculate grade for the given mark Get some amount from ATM machine input Process Output Budditha Hettige (budditha@yahoo.com) 28
29 Stages of Computer Programming 1. Planning 2. Analysis 3. Design 4. Implementation 5. Testing 6. Maintenance and update Budditha Hettige 29
30 Planning Identify scope of the project Estimate the work involved Create a project schedule Begins with requirements that define the software to be developed. The project plan can be used to describe the task Budditha Hettige (budditha@yahoo.com) 30
31 Analysis Is a complete description of the behavior of a system Consist of Functional requirements Non-functional requirements Methods Interview Questionnaires Observation etc. Budditha Hettige (budditha@yahoo.com) 31
32 Software Design Software design is a process of problemsolving and planning for a software solution Types Top down Bottom up Module design Use to describe Algorithm Flowchart Pseudo code Budditha Hettige (budditha@yahoo.com) 32
33 Design process Budditha Hettige 33
34 Design cont. Flowchart: is a type of diagram that represents an algorithm or process Gives diagrammatic representation solution to a given problem Use in analyzing, designing, documenting or managing a process or program Budditha Hettige (budditha@yahoo.com) 34
35 Flowchart- building blocks Budditha Hettige 35
36 Flowchart-building blocks contd... Budditha Hettige 36
37 Example Budditha Hettige 37
38 Example Draw a flow chart to display total of the two numbers Budditha Hettige (budditha@yahoo.com) 38
39 Example Draw a flow chart to identify correct login for the following interface Budditha Hettige (budditha@yahoo.com) 39
40 Implementation Is a realization of a technical specification or algorithm as a program, software component through computer programming May exist for a given specification or standard Example World Wide Web Consortium-recommended specifications After implement Source code, together with documentation to make the code more readable. Budditha Hettige (budditha@yahoo.com) 40
41 Program Testing is an investigation conducted to provide information about the quality of the product A primary purpose of testing is to detect software failures Test White box test Black box test Budditha Hettige (budditha@yahoo.com) 41
42 Program Maintenance and Update Is the modification of a software product after delivery to correct faults Maintenance may span for 20 years, whereas development may be 1-2 year User guide, Maintenance manual need to provides Example Windows XP (Development few years, Maintenance.) Provides set of software updates patches etc. Budditha Hettige (budditha@yahoo.com) 42
43 The Characteristics of a Good Computer Program Reliability: The program should provide correct results at all times and should be free from errors. Maintainability: The existing program should be able to change or modify to meet new requirements. Portability: The program should be able to transfer to a different computer system. Readability: The program must be readable and understandable with the help of documentation. Performance: The program should handle the task more quickly and efficiently. Storage saving: The program should be written with the least number of instructions Budditha Hettige (budditha@yahoo.com) 43
44 Steps to Computer programming Identify Input, Output and process Make a design Use suitable programming language and implement your system Test your program Budditha Hettige (budditha@yahoo.com) 44
45 Activity You are required to design a software solution for a small library explain each steps of the software development 1. Identify requirements 2. Write project proposal 3. Make Complete Design 4. Implement a solution 5. Test solution 7/11/2015 Budditha Hettige (budditha@yahoo.com) 45
46 Design 7/11/2015 Budditha Hettige 46
47 Another Approach 7/11/2015 Budditha Hettige 47
48 Software Quality 7/11/2015 Budditha Hettige 48
49 Questions 7/11/2015 Budditha Hettige 49
50 Tools & Tips for Computer programming Source code Editor TextPad, Notepad Compiler JAVA Compiler, C++ compiler Language Knowledge Logical thinking ability Budditha Hettige 50
51 Programming with IDE IDE : integrated design environment consists of source code editor compiler and/or an interpreter build automation tools Debugger Construction of a GUI Class browser Object inspector Etc. Budditha Hettige (budditha@yahoo.com) 51
52 Programming IDEs Eclipse Eclipse is a multi-language software development environment Code:blocks Netbeans Microsoft Visual Studio Budditha Hettige (budditha@yahoo.com) 52
53 Exercise Download Netbeans IDE and install it Download: Budditha Hettige 53
54 INTRODUCTION TO JAVA PROGRAMMING LANGUAGE 7/11/2015 Budditha Hettige 54
55 Introduction to Java Is a programming language created by James Gosling from Sun Microsystems in 1991 Is a general-purpose, class-based, object-oriented Programming language is intended to let application developers write once, run anywhere. URL : 7/11/2015 Budditha Hettige (budditha@yahoo.com) 55
56 Java cont Java programming language consists Java compiler: Java compiler translates Java coding into byte-code Java virtual machine(jvm) Java virtual machine interprets this byte-code and runs the program Java class libraries Java Class Library is a set of dynamically loadable libraries that Java applications can call at run time 7/11/2015 Budditha Hettige (budditha@yahoo.com) 56
57 Java Virtual Machine (JVM) Architecture JAVA Source File (.java) Java Virtual Machine Java Compiler JAVA Bite code (.class) Memory Manager Java API Byte code Verifier Interpreter 7/11/2015 Budditha Hettige 57
58 JAVA Vs C++ JAVA Source File (.java) C++ Source File (.cpp) Java Compiler C++ Compiler JAVA Bite code (.class) Executable program (.exe) Java VM JAVA VM can directly execute Operating system can directly execute 7/11/2015 Budditha Hettige 58
59 Programming Task Design Implement Compile and RUN 7/11/2015 Budditha Hettige 59
60 Characteristics Java has the following properties Platform independent Object-orientated programming language Strongly-typed programming language Interpreted and compiled language Automatic memory management 7/11/2015 Budditha Hettige 60
61 Platform independent Can Run on any Platform Windows Linux MaC OS JAVA Source File (.java) Java Compiler JAVA Bite code (.class) Java VM 7/11/2015 Budditha Hettige 61
62 Object-orientated programming language Object-oriented programming (OOP) is a programming paradigm that represents concepts as "objects" that have data fields (State) and methods (Behavior) What is an Objects? Object is a software bundle of related state and behavior Characteristics: state and behavior Example (Person) State (Name, NIC, height) Behavior (Speech, Sleep, eat) Object is an instance of a class (instance is a specific realization of any object) 7/11/2015 Budditha Hettige (budditha@yahoo.com) 62
63 What is a class? A Java class is a group of Java methods and variables Example (Person) State (Name, NIC, height) Behavior (Speech, Sleep, eat) class Person { } 7/11/2015 Budditha Hettige (budditha@yahoo.com) 63
64 Requirements for Class name Class name must begin with letter of the alphabet Contains only letters, digits, underscores or dollar sign Cannot be a language reserved keywords (public, class etc) Name cannot be following values (true, false or null) 7/11/2015 Budditha Hettige (budditha@yahoo.com) 64
65 Java Class name standard Begin with uppercase letter No spaces Emphasizes new word with an initial uppercase letter Example EmployeRecords Student FirstExample SampleProgram 7/11/2015 Budditha Hettige 65
66 Java Keywords 7/11/2015 Budditha Hettige 66
67 Install JAVA Download Java Development Kit (JDK) RUN Installation setup SET PATH for the JAVA Test JAVA is working 7/11/2015 Budditha Hettige 67
68 Simple Java Program A class with a main Method public class FirstProgram { public static void main(string[] args) { System.out.println("Hello"); } } FirstProgram Operating System Output Main Method 7/11/2015 Budditha Hettige (budditha@yahoo.com) 68
69 A class without a main Method public class FirstProgram { } Operating System Can not Execute the program FirstProgram Operating System 7/11/2015 Budditha Hettige (budditha@yahoo.com) 69
70 Your first Java program Open a text editor (text pad, Notepad etc.) Type the following sample Save program as FirstProgram.java public class FirstProgram { public static void main(string[] args) { System.out.println("Hello World"); } } 7/11/2015 Budditha Hettige (budditha@yahoo.com) 70
71 Compile and RUN Using command prompt go to the place where in your java file To Compile: type javac <space><filename> Javac FirstProgram.java To Run: type java<space><filename> Java FirstProgram 7/11/2015 Budditha Hettige 71
72 First Java program public class FirstProgram { public static void main(string[] args) { System.out.println("Hello World"); } } Flow chart Start Display Hello World End 7/11/2015 Budditha Hettige (budditha@yahoo.com) 72
73 Print Output on Command window Function System.out.println( Some Text ); System.out.print( Some Text ); Example public class FirstProgram { public static void main(string[] args) { System.out.println("Hello World"); } } 7/11/2015 Budditha Hettige (budditha@yahoo.com) 73
74 Escape Sequences A character preceded by a backslash (\) is an escape sequence has special meaning to the compiler Escape Sequence Description \t Insert a tab in the text at this point. \b Insert a backspace in the text at this point. \n Insert a newline in the text at this point. \r Insert a carriage return in the text at this point. \f Insert a formfeed in the text at this point. \' Insert a single quote character in the text at this point. \" Insert a double quote character in the text at this point. \\ Insert a backslash character in the text at this point. 7/11/2015 Budditha Hettige (budditha@yahoo.com) 74
75 ASCII art with JAVA ASCII art is a graphic design technique that uses computers for presentation and consists of pictures pieced together from the 95 printable (from a total of 128) characters defined by the ASCII Standard @ @ "); System.out.println(" \\ / "); System.out.println(" "); System.out.println(" "); System.out.println(" "); System.out.println(" "); System.out.println(" ( ) "); System.out.println(" ^^^^^ "); 7/11/2015 Budditha Hettige (budditha@yahoo.com) 75
76 Exercise 1. Why JAVA is Platform independent? 2. What is a class? 3. What is JAVA Runtime Environment (JRE)? 4. What is JAVA Class file? 5. Create a JAVA Program to display the following output EMPLOYEE DETAILS Employee NO : HIT Name : Mr. A. B. Gamage 3. Age : Salary : Married : Y 6. Car (Y/N) : N /11/2015 Budditha Hettige (budditha@yahoo.com) 76
77 Exercise Write a Java program to display the following output. budditha@yahoo.com
78 Exercise Write a Java program to calculate and display total amount of the given unit price and quantity of an item. budditha@yahoo.com
79 Data Types Use various variables to store various information Variables are reserved memory locations to store values When you create a variable you reserve some space in memory Based on the data type of a variable, the operating system allocates memory and decides what can be stored in the reserved memory budditha@yahoo.com
80 Activity How to change items in the two bottle 7/11/2015 Budditha Hettige 80
81 Java Data types The eight primitive data types supported by the Java programming language 7/11/2015 Budditha Hettige 81
82 Data types 7/11/2015 Budditha Hettige 82
83 Limits of integer in java 7/11/2015 Budditha Hettige 83
84 Default values The default values for the above data type Data Type Default Value (for fields) byte 0 short 0 int 0 long 0L float 0.0f double 0.0d char '\u0000' String (or any object) null boolean false 7/11/2015 Budditha Hettige (budditha@yahoo.com) 84
85 ASCII Code for the characters 7/11/2015 Budditha Hettige 85
86 Data type selection
87 Memory Allocation
88 Java Variables Declaration DataType <space> VaribaleName Example: Int count; Int studentage = 0; float GPA = /11/2015 Budditha Hettige (budditha@yahoo.com) 88
89 Variable name( rules) Can use only letters, digits and underscore The first character must be a simple letter Case sensitive Cannot use keywords No limits on length budditha@yahoo.com
90 Local, Instance & Class Variables classdata age localage
91 Variables in a program budditha@yahoo.com
92 Exercise Write a Java program to calculate and display total amount of the given unit price and quantity of an item. Solution What are the input(s) What are the output(s) How many variable are required What is the process budditha@yahoo.com
93 Answer 7/11/2015 Budditha Hettige 93
94 Constant variables Constants are declared like variables with the addition of the static final keywords static final double PI = ; Once declared and initialized, a constant can be used like a variable A constant may not be reassigned 7/11/2015 Budditha Hettige (budditha@yahoo.com) 94
95 Type Casting A way to convert a variable from one data type to another data type Use cast operator (type_name) expression (int) float_value budditha@yahoo.com
96 Java Memory concept Variable names correspond to location in the computer s memory Every variable has a name, a type, a size and a value A memory cell is never empty. But its initial contents may be meaningless to your program. The current contents of a memory cell are destroyed whenever new information is placed in that cell. Java has Total control about variables Programmer s No need to think much budditha@yahoo.com
97 Input / Output
98 Input from Keyboard Use Scanner import java.util.scanner; Create a Scanner object to Scan input from command window Scanner input = new Scanner(System.in); Read value from keyboard nextint() interger nextline () String nextfloat() float nextdouble ()double Example value = input.nextint(); 7/11/2015 Budditha Hettige (budditha@yahoo.com) 98
99 Example Create a JAVA Program that read data from key bard and display the result as follows EMPLOYEE DETAILS Employee NO : HIT Name : Mr. A. B. Gamage 2. Age : Salary : Married : Y 5. Car (Y/N) : N /11/2015 Budditha Hettige (budditha@yahoo.com) 99
100 Exercise Write a Java program to read two numbers from keyboard and display the Average. budditha@yahoo.com
101 Solution import java.util.scanner; public class FundamantalApp { public static void main(string[] args) { Scanner input = new Scanner(System.in); int value1, value2; float avg; System.out.println("Enter value1 :"); value1 = input.nextint(); System.out.println("Enter value1 :"); value2 = input.nextint(); avg = (value1 + value2)/2; System.out.println("Average is "+ avg); } } 7/11/2015 Budditha Hettige (budditha@yahoo.com) 101
102 Examples: Create a java program to calculate area of a room. 7/11/2015 Budditha Hettige (budditha@yahoo.com) 102
103 Answer 7/11/2015 Budditha Hettige 103
104 Example Create a java program to calculate area of the following figure c a 7/11/2015 Budditha Hettige (budditha@yahoo.com) b 104
105 Answer 7/11/2015 Budditha Hettige 105
106 Exercise Create a Java program to calculate and display total amount of given unit price and quantity of the some item. budditha@yahoo.com
107 Answer
108 Java Formatting System.out.format("%f, %1$ f %n", Math.PI); 7/11/2015 Budditha Hettige 108
109 Example Write a C++ program which will convert a weight in KG to pounds and ounces. ( 1 Kg = pounds) budditha@yahoo.com
110 Example Write a C++ program which will convert a Celsius temperature into Fahrenheit budditha@yahoo.com
111 Operators
112 Example What is the output of the Variable y Budditha Hettige (budditha@yahoo.com)
113 Java Operators Assignment operator (=) Arithmetic operators ( +, -, *, /, % ) Compound assignment (+=, -=, *=, /=, %=, >>=, <<=, &=, ^=, =) Increment and decrement (++, --) Relational and comparison operators ( ==,!=, >, <, >=, <= ) Logical operators (!, &&, ) Conditional ternary operator (? ) Comma operator (, ) Budditha Hettige (budditha@yahoo.com)
114 Java Operators Budditha Hettige
115 Binary Operators The binary operators take two arguments as operands Left Operand Right Operand Operator Budditha Hettige
116 Unary Operators The unary operators take one arguments as operand Operand Operator Budditha Hettige
117 Assignment operator (=) The assignment operator assigns a value to a variable. Budditha Hettige (budditha@yahoo.com)
118 Arithmetic operators( +, -, *, /, % ) The five arithmetical operations supported by C++ are Budditha Hettige (budditha@yahoo.com)
119 Compound assignment (+=, -=, *=, /=, %=, >>=, <<=, &=, ^=, =) Budditha Hettige
120 Combined assignment operators Each arithmetic operator has a corresponding assignment operator. Operator Effect L = Left Operator R = Right Operator += Assign (L + R) to L -= Assign (L - R) to L *= Assign (L * R) to L /= Assign (L / R) to L %= Assign (L % R) to L Budditha Hettige (budditha@yahoo.com)
121 Example Budditha Hettige
122 Unary Operators The unary operators take one arguments - unary minus (negation) + unary plus -- decrement ++ increment Budditha Hettige (budditha@yahoo.com)
123 Unary Operators The unary minus (-) makes a positive number into a negative number and a negative number into a positive number. The unary plus (+) does not change the number. The decrement operator (--) decrements the value of its operand by 1. The increment operator (++) increments the value of its operand by 1. Budditha Hettige (budditha@yahoo.com)
124 The prefix version (++x or --x) Comes before the operand, as in ++x First increments or decrements the variable by 1 and then uses the value of the variable. means Change x Then assign to y y = 6, x = 6. Budditha Hettige (budditha@yahoo.com)
125 The postfix version (x++ or x--) Comes after the operand, as in x++ Uses the current value of the variable and then increment or decrements the variable by 1. means Assign z to y. Then change z. y is 5, z is 6. Budditha Hettige (budditha@yahoo.com)
126 Relational and comparison operators The result of such an operation is either true or false (i.e., a Boolean value) Budditha Hettige (budditha@yahoo.com)
127 Example Budditha Hettige
128 Logical Operators To combine or modify existing expressions.! NOT && AND OR Example a > 5 && b > 5 ch == y ch == Y!valid!(x > 5) Budditha Hettige (budditha@yahoo.com)
129 Conditional ternary operator (? ) The conditional operator evaluates an expression, returning one value if that expression evaluates to true, and a different one if the expression evaluates as false. Syntax is: condition? result1 : result2 Budditha Hettige (budditha@yahoo.com)
130 Bitwise operators ( &,, ^, ~, <<, >> ) Bitwise operators modify variables considering the bit patterns that represent the values they store. Budditha Hettige (budditha@yahoo.com)
131 Precedence of operators Budditha Hettige
132 Selections
133 Exercise Write a Java program to read an examination mark from keyboard and print pass if mark >= 40. Budditha Hettige (buditha@yahoo.com)
134 Java Selection (if Statement) One-Way (if) Selection Syntax if (expression) { statement(s) } If m>=40 PASS Statement executed if value of expression true Budditha Hettige (buditha@yahoo.com)
135 Java Selection (if Statement) Two-Way (if...else) if (expression) { statement1; } else { statement2; } If expression true, statement1 executed, otherwise statement2 executed Budditha Hettige (buditha@yahoo.com)
136 if-then-else Statement Syntax if (Condition) { statement(s) } else { statement(s) } Example Budditha Hettige (buditha@yahoo.com)
137 Exercise Write a C++ program to print the biggest number of the two given numbers Budditha Hettige (buditha@yahoo.com)
138 Exercise Write a C++ program to print the biggest number of the three given numbers Budditha Hettige (buditha@yahoo.com)
139 Exercise Write a C++ program to print the grade for a given mark Budditha Hettige (buditha@yahoo.com)
140 Solution 1 Budditha Hettige (buditha@yahoo.com)
141 Nested if and if...else Statements Nesting: one control statement in another Syntax of nested if...else statements: if (condition1) statement1; else if (condition2) statement2;... else if (condition-n) statement-n; else statement-z; Budditha Hettige
142 Answer with Nested if 7/11/2015 Budditha Hettige 142
143 Exercise Write a Java program to print the grade for a given marks Budditha Hettige (buditha@yahoo.com)
144 Debug Debugging is a methodical process of finding and reducing the number of bugs, or defects
145 Debug Programming errors are called bugs Programming errors may be Compiler errors Runtime errors Logical errors Going through the code, examining it and looking for something wrong in the implementation (bugs) and correcting them is called debugging Budditha Hettige
146 Debugging Options Make break points Right click on statement and add break point Add watches to see the values of the variables Click Debug Debugging window - Watches Budditha Hettige (buditha@yahoo.com)
147 Debugging cont. Start debugging (Press F8) Debug Commands F8 Start / Continue F7 Next Line Shift+F8 Stop Budditha Hettige (buditha@yahoo.com)
148 Exercise Write a C++ program that reads month as an integer and print the name of the month Draw a flowchart to describe your solution Debug your code and find execution path for the following Month = 1; Month = 12; Month = 6; Budditha Hettige (buditha@yahoo.com)
149 Switch Run with number of possible execution paths A switch works with the byte, short, char, and int primitive data types
150 Switch switch structure: alternate to if...else Example 1: switch(x) { case x1: case x2: default: } statements1; break; statements2; break; statements4; break; Budditha Hettige (buditha@yahoo.com)
151 Exercise 5.6 Write a C++ program that reads month as an integer and print the name of a month. (Use Switch) Budditha Hettige (buditha@yahoo.com)
152 Exercise 5.7 Draw a flowchart to above program Budditha Hettige (buditha@yahoo.com)
153 Exercise Write a Java program that reads day as an integer (1-7)and print the name Use only if-else statement and implement your solution Use switch statement and implement your solution Draw flowcharts to above two programs Compare performance of the two methods (if and Switch) Use debug and find the execution path Budditha Hettige (buditha@yahoo.com)
154 Exercise Write a JAVA program that reads day as an integer (1-7)and print the name 7/11/2015 Budditha Hettige (budditha@yahoo.com) 154
155 Exercise Write a Java program to display a given date as the following formats. Your program should read date as the three inputs (day, month and year) and generates the output forms. Option 1: Option 2: Option 3: 21 st May 2001 Budditha Hettige (buditha@yahoo.com)
156 Answer 7/11/2015 Budditha Hettige 156
157 Answer 1. Print a day 2. Print (st/nd/rd/th) 3. Print month 4. Print year Budditha Hettige (buditha@yahoo.com)
158 Exercise Write a Java program to print the bill for an item bought by a customer from a shop. The program should ask unit price and quantity of an item and calculate the total cost If item quantity greater than 10 give one item free Add 3.5 % discount for the total if total cost grater than The bill should contain all the above information and amount of money tendered and the correct amount of change. Budditha Hettige (buditha@yahoo.com)
159 Exercise Write a JAVA program to find the roots of the quadratic equation ax 2 + bx + c = 0 where x represents a variable or an unknown, and a, b, and c are constants. Hint: The following equation shows the solutions of the quadratic equation Read more on quadratic equation: 7/11/2015 Budditha Hettige (budditha@yahoo.com) 159
160 Loops Loops have as purpose to repeat a statement a certain number of times or while a condition is fulfilled.
161 Repetitions: Loops A loop is a sequence of instruction s that is continually repeated until a certain condition is reached. The statement may be repeated For a specific number of items For an indeterminate number of times, depending on the truth or falsity of some condition. Budditha Hettige (budditha@yahoo.com)
162 Loops C++ provides three types of loops for loops (1- n times) Repeat a section of code known number of times while loops (0 more times) Loop is used to repeat a specific block of code an unknown number of times do while loops (1 more times) A do while loop is a control flow statement that executes a block of code at least once, and then repeatedly executes the block Budditha Hettige (budditha@yahoo.com)
163 Repeat some work Do some repeated work Initialization (Start number) Condition (do repeat action until satisfy some condition) Update (Next Value) Example Initialization Start with 1 Condition Count up to 50 Update Count 1 by 1 Budditha Hettige (budditha@yahoo.com)
164 For Loop Syntax for (initialization; condition; update) { statement(s) } Initialization Example Condition Update Budditha Hettige (budditha@yahoo.com)
165 Exercise Write a Java program to find the factorial of a given number Example: Budditha Hettige (budditha@yahoo.com)
166 Nested for Loops A loop can be nested inside of another loop Syntax for ( init; condition; increment ) { for ( init; condition; increment ) { statement(s); } statement(s); } Budditha Hettige (budditha@yahoo.com)
167 Exercise Write a Java program to display the following Multiplication table Budditha Hettige (budditha@yahoo.com)
168 Exercise 1. Write a Java program to print the following figure a) * b) 1 ** 12 *** 123 **** 1234 ***** Budditha Hettige (budditha@yahoo.com)
169 While Loop Allows the repetition of a statement based on the truth value of a condition Can run 0 to infinite times Budditha Hettige (budditha@yahoo.com)
170 While Loop Syntax while (Condition) { statement(s) } Example Initialization Condition Update Budditha Hettige (budditha@yahoo.com)
171 Exercise Write a Java program to find the factorial of a given number (Use While loop) Budditha Hettige (budditha@yahoo.com)
172 Exercise Write a Java program to accept numbers until the user enters a 999 and output the sum of the given numbers Budditha Hettige (budditha@yahoo.com)
173 Exercise Create a java program to identify the given number is Palindrome number or not. Read number as an integer Find the number is Palindrome or not Print the results Hint: A palindromic number or numeral palindrome is a number that remains the same when its digits are reversed. Like Budditha Hettige (budditha@yahoo.com)
174 Answers Budditha Hettige
175 Do-while Loop do while loop also depends on a condition, but unlike while loop, its condition is evaluated at the bottom of the loop, after the body has already executed. Budditha Hettige (budditha@yahoo.com)
176 Do-while Loop Syntax do { statement(s) } while (condition); Example Initialization Update Condition Budditha Hettige (budditha@yahoo.com)
177 Loops comparison For while do-while Budditha Hettige
178 Exercise Accept numbers until the user enters a 999 and output the average of the given numbers Budditha Hettige (budditha@yahoo.com)
179 Exercise Using do-while loop, create a java program to display the selected option in the following menu; [1] Enter data [2] Print data [3] Exit the program do-while Switch Budditha Hettige (budditha@yahoo.com)
180 Answer Budditha Hettige
181 Exercise Write a Java program to read N number of integers and find the total and average. N is an input 1, 2, 3.. N Use for, while and do-while loops Draw 3 flow chart for the above 3 programs Budditha Hettige (budditha@yahoo.com)
182 Exercise Write a Java program to compute the gross pay for an employee. An employee is paid at hourly rate for the first 40 hours worked in a week. Any hours worked in excess of 40 hours are paid at the overtime rate of one and half times that. Your program should print the pay sheets of all the employees. Budditha Hettige (budditha@yahoo.com)
183 Functions and Methods
184 Exercise Create a Java program to display the following wordart.(mam) Budditha Hettige (budditha@yahoo.com) 184
185 Functions Functions are a basic building block for writing Java programs. Breaking a program up into separate functions, each of which performs a particular task, makes it easier to develop and debug a program Solution for code reuse Functions allow for breaking down the program into discrete units Use to modular Programing Budditha Hettige (budditha@yahoo.com) 185
186 Methods Is a group of statements that is executed when it is called from some point of the program. Types Built-in: Build-in methods are part of the compiler package, such as System.out.println( ) User-defined: User-defined methods are created by you Format Return type MethodName (Argument..) { } 7/11/2015 Budditha Hettige (budditha@yahoo.com) 186
187 Method Example 1 PrintMe Main printme 7/11/2015 Budditha Hettige (budditha@yahoo.com) 187
188 Method Example 2 PrintMe Main printme 7/11/2015 Budditha Hettige (budditha@yahoo.com) 188
189 Method Example 3 7/11/2015 Budditha Hettige (budditha@yahoo.com) 189
190 Scope of a variable /11/2015 Budditha Hettige (budditha@yahoo.com) 190
191 Example Create a Java Programs to do to the following 1. Read Celsius temperature and calculate the Fahrenheit temperature Hint: Celsius to Fahrenheit: ( C 9 / 5 ) + 32 = F A Method to read data from keyboard A Method to Calculate data A Method to Print Data 7/11/2015 Budditha Hettige (budditha@yahoo.com) 191
192 Methods 7/11/2015 Budditha Hettige 192
193 Methods 7/11/2015 Budditha Hettige 193
194 Complete Program getvalue Main getvalue Claculate calculate printdata printdata 7/11/2015 Budditha Hettige 194
195 Top-Down Design Main getvalue claculate printdata 7/11/2015 Budditha Hettige 195
196 Bottom-up Design Main getvalue claculate printdata 7/11/2015 Budditha Hettige 196
197 Modular Design getvalue printdata claculate Main 7/11/2015 Budditha Hettige 197
198 Example Create a JAVA Program that reads 3 integer values from keyboard and print total and average values. Hint: Draw a top down design Implement your solution 7/11/2015 Budditha Hettige (budditha@yahoo.com) 198
199 Arrays
200 What is Array An array, is a data structure consisting of a collection of elements Each identified by at least one array index or key simplest type of data structure is a linear array, also called one-dimensional array 7/11/2015 Budditha Hettige (budditha@yahoo.com) 200
201 Arrays An array is a container object that holds a fixed number of values of a single type 7/11/2015 Budditha Hettige (budditha@yahoo.com) 201
202 Arrays contd. Declares an array of integers int[] anarray; Allocates memory for 10 integers anarray = new int[10]; Initialize first element anarray[0] = 100; Display Values System.out.println( E0 + anarray[0]); 7/11/2015 Budditha Hettige (budditha@yahoo.com) 202
203 Example Write a Java program to store marks of 10 students and print average mark? Output of your program is as follows Student Marks Average ===================== 7/11/2015 Budditha Hettige (budditha@yahoo.com) 203
204 Write a Java program that read 10 integer marks (Range 0 to 100) form keyboard and print the result sheet as shown below. Exercise Write a Java program that read 10 integer marks (Range 0 to 100) form keyboard and print the result sheet as shown below. ICT Introduction to Computer Programming ####### RESULT SHEET ###### Index NO Marks ================================================ /11/2015 Budditha Hettige (budditha@yahoo.com) 204
205 Find elements Find the largest and small mark of the above marks array 7/11/2015 Budditha Hettige 205
206 Example (several arrays) Create 2 Arrays to store Student name and GPA values of the 25 students in a class Enter all values and print results in the following format Student summary Saman Kumara 2.56 Ruwan Silva /11/2015 Budditha Hettige (budditha@yahoo.com) 206
207 Multiple Arrays Write a C++ program to store 10 student information in class with considering name, age, height. Your program should read 10 students information from keyboard and display results as given below name age height saman kamal /11/2015 Budditha Hettige (budditha@yahoo.com) 207
208 Console Applications
209 Console Application Runs only console screen(command window) NO GUI Use Low resources Use only key board action 7/11/2015 Budditha Hettige 209
210 Example 7/11/2015 Budditha Hettige 210
211 Example user interface 7/11/2015 Budditha Hettige 211
212 Example Main Menu 7/11/2015 Budditha Hettige 212
213 Example 3 (contd.) Action 7/11/2015 Budditha Hettige (budditha@yahoo.com) 213
214 Example 3 (contd.) Summary 7/11/2015 Budditha Hettige (budditha@yahoo.com) 214
215 Example 4 Create Java Application to calculate total price for the sold items. Your program should run as a menu driven application User can add items (any ) and print total, number of items and discount User can total sales price for a day This program should run until user exit 7/11/2015 Budditha Hettige (budditha@yahoo.com) 215
216 Run Application Without Netbeans 7/11/2015 Budditha Hettige 216
217 RUN Application 7/11/2015 Budditha Hettige 217
218 Model Questions
219 7/11/2015 Budditha Hettige 219
220 END. 7/11/2015 Budditha Hettige 220
Fundamentals of Programming
Fundamentals of Programming Budditha Hettige Department of Computer Science Fundamentals of Programming Course Structure Lectures 30 Hours Practical /Tutorials 30 hours Assignment (30%) Practical Test
More informationFundamentals of Programming INTRODUCTION
Fundamentals of Programming INTRODUCTION Budditha Hettige Why Machines? Café Machine can be used to make a tea? ATM machine can be used to money transaction? Calculator can be used to solve equation? Each
More informationFundamentals of Programming. By Budditha Hettige
Fundamentals of Programming By Budditha Hettige Overview Exercises (Previous Lesson) The JAVA Programming Languages Java Virtual Machine Characteristics What is a class? JAVA Standards JAVA Keywords How
More informationFundamentals 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 informationFundamentals of Programming. By Budditha Hettige
Fundamentals of Programming By Budditha Hettige Overview Machines solve problems? How Machine Solve a Problem? What is Programming? What are Programming Languages Compilers Tools and Tips for Programming
More informationIT 1033: Fundamentals of Programming Loops
IT 1033: Fundamentals of Programming Loops Budditha Hettige Department of Computer Science Repetitions: Loops A loop is a sequence of instruction s that is continually repeated until a certain condition
More informationFull 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 informationIT 1033: Fundamentals of Programming Data types & variables
IT 1033: Fundamentals of Programming Data types & variables Budditha Hettige Department of Computer Science Exercise 3.1 Write a C++ program to display the following output. Exercise 3.2 Write a C++ program
More informationData Types & Variables
Fundamentals of Programming Data Types & Variables Budditha Hettige Exercise 3.1 Write a C++ program to display the following output. Exercise 3.2 Write a C++ program to calculate and display total amount
More informationCourse 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 informationArrays IT 1033: Fundamentals of Programming
Arrays IT 1033: Fundamentals of Programming Budditha Hettige Department of Computer Science What is Array An array, is a data structure consisting of a collection of elements Each identified by at least
More informationProgramming 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 information13 th Windsor Regional Secondary School Computer Programming Competition
SCHOOL OF COMPUTER SCIENCE 13 th Windsor Regional Secondary School Computer Programming Competition Hosted by The School of Computer Science, University of Windsor WORKSHOP I [ Overview of the Java/Eclipse
More informationLecture 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 informationCOMP 202 Java in one week
CONTENTS: Basics of Programming Variables and Assignment Data Types: int, float, (string) Example: Implementing a calculator COMP 202 Java in one week The Java Programming Language A programming language
More informationComputer 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 informationCOSC 123 Computer Creativity. Introduction to Java. Dr. Ramon Lawrence University of British Columbia Okanagan
COSC 123 Computer Creativity Introduction to Java Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca Key Points 1) Introduce Java, a general-purpose programming language,
More informationChapter 2: Data and Expressions
Chapter 2: Data and Expressions CS 121 Department of Computer Science College of Engineering Boise State University January 15, 2015 Chapter 2: Data and Expressions CS 121 1 / 1 Chapter 2 Part 1: Data
More informationIntroduction to Programming (Java) 2/12
Introduction to Programming (Java) 2/12 Michal Krátký Department of Computer Science Technical University of Ostrava Introduction to Programming (Java) 2008/2009 c 2006 2008 Michal Krátký Introduction
More informationChapter 2: Data and Expressions
Chapter 2: Data and Expressions CS 121 Department of Computer Science College of Engineering Boise State University April 21, 2015 Chapter 2: Data and Expressions CS 121 1 / 53 Chapter 2 Part 1: Data Types
More informationIntroduction To Java. Chapter 1. Origins of the Java Language. Origins of the Java Language. Objects and Methods. Origins of the Java Language
Chapter 1 Getting Started Introduction To Java Most people are familiar with Java as a language for Internet applications We will study Java as a general purpose programming language The syntax of expressions
More informationChapter 2: Programming Concepts
Chapter 2: Programming Concepts Objectives Students should Know the steps required to create programs using a programming language and related terminology. Be familiar with the basic structure of a Java
More informationLesson 02 Data Types and Statements. MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL
Lesson 02 Data Types and Statements MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL Topics Covered Statements Variables Constants Data Types
More informationWentworth 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 informationControl Statements: Part 1
4 Let s all move one place on. Lewis Carroll Control Statements: Part 1 The wheel is come full circle. William Shakespeare How many apples fell on Newton s head before he took the hint! Robert Frost All
More information12/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 informationCONTENTS: Compilation Data and Expressions COMP 202. More on Chapter 2
CONTENTS: Compilation Data and Expressions COMP 202 More on Chapter 2 Programming Language Levels There are many programming language levels: machine language assembly language high-level language Java,
More informationCOMP-202: Foundations of Programming. Lecture 2: Variables, and Data Types Sandeep Manjanna, Summer 2015
COMP-202: Foundations of Programming Lecture 2: Variables, and Data Types Sandeep Manjanna, Summer 2015 Announcements Midterm Exams on 4 th of June (12:35 14:35) Room allocation will be announced soon
More informationIntroduction to Java & Fundamental Data Types
Introduction to Java & Fundamental Data Types LECTURER: ATHENA TOUMBOURI How to Create a New Java Project in Eclipse Eclipse is one of the most popular development environments for Java, as it contains
More informationChapter 3 Syntax, Errors, and Debugging. Fundamentals of Java
Chapter 3 Syntax, Errors, and Debugging Objectives Construct and use numeric and string literals. Name and use variables and constants. Create arithmetic expressions. Understand the precedence of different
More informationFeatures of C. Portable Procedural / Modular Structured Language Statically typed Middle level language
1 History C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC
More informationCOMP 202 Java in one week
COMP 202 Java in one week... Continued CONTENTS: Return to material from previous lecture At-home programming exercises Please Do Ask Questions It's perfectly normal not to understand everything Most of
More informationCOMP 202. Java in one week
COMP 202 CONTENTS: Basics of Programming Variables and Assignment Data Types: int, float, (string) Example: Implementing a calculator Java in one week The Java Programming Language A programming language
More informationIntroduction to C++ IT 1033: Fundamentals of Programming
2 Introduction to C++ IT 1033: Fundamentals of Programming Budditha Hettige Department of Computer Science C++ C++ is a middle-level programming language Developed by Bjarne Stroustrup Starting in 1979
More informationIntroduction 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 informationBasics of Java Programming
Basics of Java Programming Lecture 2 COP 3252 Summer 2017 May 16, 2017 Components of a Java Program statements - A statement is some action or sequence of actions, given as a command in code. A statement
More informationChapter 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 informationChapter 2 Working with Data Types and Operators
JavaScript, Fourth Edition 2-1 Chapter 2 Working with Data Types and Operators At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics
More informationUniversità 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 information2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program
Chapter 2: Introduction to C++ 2.1 Parts of a C++ Program Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Parts of a C++ Program Parts of a C++ Program // sample C++ program
More informationCEN 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 informationBuilding Java Programs. Chapter 2: Primitive Data and Definite Loops
Building Java Programs Chapter 2: Primitive Data and Definite Loops Copyright 2008 2006 by Pearson Education 1 Lecture outline data concepts Primitive types: int, double, char (for now) Expressions: operators,
More informationCSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI
CSCI 2010 Principles of Computer Science Data and Expressions 08/09/2013 CSCI 2010 1 Data Types, Variables and Expressions in Java We look at the primitive data types, strings and expressions that are
More informationUNIT- 3 Introduction to C++
UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage
More informationExpressions and Data Types CSC 121 Spring 2015 Howard Rosenthal
Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types
More information1 Introduction Java, the beginning Java Virtual Machine A First Program BlueJ Raspberry Pi...
Contents 1 Introduction 3 1.1 Java, the beginning.......................... 3 1.2 Java Virtual Machine........................ 4 1.3 A First Program........................... 4 1.4 BlueJ.................................
More informationChapter 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 informationObjectives. In this chapter, you will:
Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates arithmetic expressions Learn about
More informationCS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University
CS5000: Foundations of Programming Mingon Kang, PhD Computer Science, Kennesaw State University Overview of Source Code Components Comments Library declaration Classes Functions Variables Comments Can
More informationCharacter Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Uppercase Alphabets Lowercase Alphabets Character Set A, B, C, Y, Z a, b, c, y, z Digits
More informationIntroduction 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 informationIntroduction 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 informationIntroduction 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 informationLecture 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 informationTOPIC 2 INTRODUCTION TO JAVA AND DR JAVA
1 TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson, and instructor materials prepared
More informationIntroduction to Programming Using Java (98-388)
Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;
More information3. Java - Language Constructs I
Educational Objectives 3. Java - Language Constructs I Names and Identifiers, Variables, Assignments, Constants, Datatypes, Operations, Evaluation of Expressions, Type Conversions You know the basic blocks
More informationJava Notes. 10th ICSE. Saravanan Ganesh
Java Notes 10th ICSE Saravanan Ganesh 13 Java Character Set Character set is a set of valid characters that a language can recognise A character represents any letter, digit or any other sign Java uses
More informationLecture 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 informationCS11 Java. Fall Lecture 1
CS11 Java Fall 2006-2007 Lecture 1 Welcome! 8 Lectures Slides posted on CS11 website http://www.cs.caltech.edu/courses/cs11 7-8 Lab Assignments Made available on Mondays Due one week later Monday, 12 noon
More informationChapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction
Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 1 Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers
More informationProgramming. Syntax and Semantics
Programming For the next ten weeks you will learn basic programming principles There is much more to programming than knowing a programming language When programming you need to use a tool, in this case
More informationIntroduction 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 informationChapter 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 informationTools : The Java Compiler. The Java Interpreter. The Java Debugger
Tools : The Java Compiler javac [ options ] filename.java... -depend: Causes recompilation of class files on which the source files given as command line arguments recursively depend. -O: Optimizes code,
More information4 Programming Fundamentals. Introduction to Programming 1 1
4 Programming Fundamentals Introduction to Programming 1 1 Objectives At the end of the lesson, the student should be able to: Identify the basic parts of a Java program Differentiate among Java literals,
More informationChapter 2: Data and Expressions
Chapter 2: Data and Expressions CS 121 Department of Computer Science College of Engineering Boise State University August 21, 2017 Chapter 2: Data and Expressions CS 121 1 / 51 Chapter 1 Terminology Review
More informationRoom 3P16 Telephone: extension ~irjohnson/uqc146s1.html
UQC146S1 Introductory Image Processing in C Ian Johnson Room 3P16 Telephone: extension 3167 Email: Ian.Johnson@uwe.ac.uk http://www.csm.uwe.ac.uk/ ~irjohnson/uqc146s1.html Ian Johnson 1 UQC146S1 What is
More informationExpressions and Data Types CSC 121 Fall 2015 Howard Rosenthal
Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types and
More informationObjectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program
Objectives Chapter 2: Basic Elements of C++ In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates
More informationChapter 2: Basic Elements of C++
Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates
More informationChapter 1 Introduction to java
Chapter 1 Introduction to java History of java Java was created by by Sun Microsystems team led by James Gosling (1991) It was mainly used for home appliance, it later became a general purpose programming
More informationCS111: PROGRAMMING LANGUAGE II
1 CS111: PROGRAMMING LANGUAGE II Computer Science Department Lecture 1: Introduction Lecture Contents 2 Course info Why programming?? Why Java?? Write once, run anywhere!! Java basics Input/output Variables
More informationData and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence
Data and Variables Data Types Expressions Operators Precedence String Concatenation Variables Declaration Assignment Shorthand operators Review class All code in a java file is written in a class public
More informationProgramming Language Basics
Programming Language Basics Lecture Outline & Notes Overview 1. History & Background 2. Basic Program structure a. How an operating system runs a program i. Machine code ii. OS- specific commands to setup
More informationChapter 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 informationMore Programming Constructs -- Introduction
More Programming Constructs -- Introduction We can now examine some additional programming concepts and constructs Chapter 5 focuses on: internal data representation conversions between one data type and
More informationBy the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program
1 By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program variables. Apply C++ syntax rules to declare variables, initialize
More informationChapter 1 Lab Algorithms, Errors, and Testing
Chapter 1 Lab Algorithms, Errors, and Testing Lab Objectives Be able to write an algorithm Be able to compile a Java program Be able to execute a Java program using the Sun JDK or a Java IDE Be able to
More informationProgramming for Engineers Iteration
Programming for Engineers Iteration ICEN 200 Spring 2018 Prof. Dola Saha 1 Data type conversions Grade average example,-./0 class average = 23450-67 893/0298 Grade and number of students can be integers
More informationCSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York
CSc 10200! Introduction to Computing Lecture 2-3 Edgardo Molina Fall 2013 City College of New York 1 C++ for Engineers and Scientists Third Edition Chapter 2 Problem Solving Using C++ 2 Objectives In this
More informationSequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;
Control Statements Control Statements All programs could be written in terms of only one of three control structures: Sequence Structure Selection Structure Repetition Structure Sequence structure The
More informationChapter 3: Operators, Expressions and Type Conversion
101 Chapter 3 Operators, Expressions and Type Conversion Chapter 3: Operators, Expressions and Type Conversion Objectives To use basic arithmetic operators. To use increment and decrement operators. To
More informationChapter 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 information7/8/10 KEY CONCEPTS. Problem COMP 10 EXPLORING COMPUTER SCIENCE. Algorithm. Lecture 2 Variables, Types, and Programs. Program PROBLEM SOLVING
KEY CONCEPTS COMP 10 EXPLORING COMPUTER SCIENCE Lecture 2 Variables, Types, and Programs Problem Definition of task to be performed (by a computer) Algorithm A particular sequence of steps that will solve
More informationObject Oriented Programming with Java
Object Oriented Programming with Java What is Object Oriented Programming? Object Oriented Programming consists of creating outline structures that are easily reused over and over again. There are four
More informationFundamental of Programming (C)
Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering
More informationData and Expressions. Outline. Data and Expressions 12/18/2010. Let's explore some other fundamental programming concepts. Chapter 2 focuses on:
Data and Expressions Data and Expressions Let's explore some other fundamental programming concepts Chapter 2 focuses on: Character Strings Primitive Data The Declaration And Use Of Variables Expressions
More informationJAVA Programming Fundamentals
Chapter 4 JAVA Programming Fundamentals By: Deepak Bhinde PGT Comp.Sc. JAVA character set Character set is a set of valid characters that a language can recognize. It may be any letter, digit or any symbol
More informationSection 2: Introduction to Java. Historical note
The only way to learn a new programming language is by writing programs in it. - B. Kernighan & D. Ritchie Section 2: Introduction to Java Objectives: Data Types Characters and Strings Operators and Precedence
More informationAssoc. 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 informationCOMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette
COMP 250: Java Programming I Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette Variables and types [Downey Ch 2] Variable: temporary storage location in memory.
More informationOutline. Parts 1 to 3 introduce and sketch out the ideas of OOP. Part 5 deals with these ideas in closer detail.
OOP in Java 1 Outline 1. Getting started, primitive data types and control structures 2. Classes and objects 3. Extending classes 4. Using some standard packages 5. OOP revisited Parts 1 to 3 introduce
More informationVisual C# Instructor s Manual Table of Contents
Visual C# 2005 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion Topics Additional Projects Additional Resources Key Terms
More information3 The L oop Control Structure
3 The L oop Control Structure Loops The while Loop Tips and Traps More Operators The for Loop Nesting of Loops Multiple Initialisations in the for Loop The Odd Loop The break Statement The continue Statement
More informationPace 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 informationConditional Programming
COMP-202 Conditional Programming Chapter Outline Control Flow of a Program The if statement The if - else statement Logical Operators The switch statement The conditional operator 2 Introduction So far,
More informationMobile Computing Professor Pushpendra Singh Indraprastha Institute of Information Technology Delhi Java Basics Lecture 02
Mobile Computing Professor Pushpendra Singh Indraprastha Institute of Information Technology Delhi Java Basics Lecture 02 Hello, in this lecture we will learn about some fundamentals concepts of java.
More informationMore Things We Can Do With It! Overview. Circle Calculations. πr 2. π = More operators and expression types More statements
More Things We Can Do With It! More operators and expression types More s 11 October 2007 Ariel Shamir 1 Overview Variables and declaration More operators and expressions String type and getting input
More informationFull file at
Java Programming, Fifth Edition 2-1 Chapter 2 Using Data within a Program At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional
More information