Full file at

Size: px
Start display at page:

Download "Full file at"

Transcription

1 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 Discussion Topics Additional Projects Additional Resources Key Terms

2 Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-2 Lecture Notes O verview In this chapter, students will learn the basics of programming in Java. Fundamental topics include data types, arithmetic operations, precedence rules, type casting, input and output, and assignment operators. The chapter also covers the basic structure of a Java program, including the import statement and commenting. C hapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols, and identifiers Explore primitive data types Discover how to use arithmetic operators Examine how a program evaluates arithmetic expressions Explore how mixed expressions are evaluated Learn about type casting Become familiar with the String type Learn what an assignment statement is and what it does Discover how to input data into memory by using input statements Become familiar with the use of increment and decrement operators Examine ways to output results using output statements Learn how to import packages and why they are necessary Discover how to create a Java application program Explore how to properly structure a program, including using comments to document a program T eaching s Explain that a computer program, or a program, is a sequence of statements whose objective is to accomplish a task, and that programming is a process of planning and creating a program. Explain that learning a programming language requires direct interaction with the tools, and emphasize that you must have a fundamental knowledge of the language, and you must test your programs on the computer to make sure that each program does what it is supposed to do. The Basics of a Java Program 1. Explain that a programming language is a set of rules, symbols, and special words, and explain the difference between the syntax and the semantics.

3 Java Programming: From Problem Analysis to Program Design, 3 rd Edition Explain that the smallest individual unit of a program written in any programming language is called a token. Java s tokens are divided into special symbols, reserved words, and identifiers. Special Symbols 1. Explain the special symbols presented on page 33, and note that a blank, which is not shown, is also a special symbol. Emphasize that symbols comprised of two characters (such as <= and ==) are considered a single symbol, and a blank may not appear between the two characters. Reserved Words (Keywords) 1. Explain that reserved words are called keywords and are always lowercase. 2. Emphasize that reserved words may not be used for any other purpose, or be redefined within any program. Take time to give examples of reserved words, and explain that they are considered single symbols. Note that a complete list of reserved words in Java is in Appendix A. Identifiers 1. Explain that identifiers are names of things, such as variables, constants, and methods, that appear in programs, and they may or may not be predefined. 2. Explain that a Java identifier consists of letters, digits, the underscore character ( _), and the dollar sign ($), and must begin with a letter, underscore, or the dollar sign. Stress the fact that Java is case sensitive, and walk through Example 2-2 to show examples of good and bad identifiers. Data Types 1. Explain that a data type is a set of values together with a set of operations, and only certain operations can be performed on a particular type of data.

4 Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-4 Primitive Data Types 1. Explain that there are three primitive data types: integral, floating-point, and Boolean, and refer to Figure Refer to Figure 2-2 to explain that integral data types fall into five categories. 3. Explain that each data type has a different set of values associated with it, and walk through Table 2-2, explaining the range of values associated with each integral data type. int Data Type 1. Explain that in Java, positive integers do not have to have a + sign in front of them, and no commas are used within an integer. char Data Type 1. Explain that the char data type is used to represent single characters such as letters, digits, and special symbols, and it can represent any key on your keyboard. 2. Explain that each character represented is enclosed within single quotation marks, and only one symbol can be placed between the single quotation marks. 3. Explain that Java uses the Unicode character set, which contains values numbered 0 to 65535, and each of the values of the Unicode character set represents a different character. 4. Explain that each character has a predefined ordering, which is called a collating sequence, in the set, and it is used when comparing characters. 5. Explain that the newline character is represented as \n, the tab character is \t, and the null character is \0, and note that Appendix C has a list of characters. boolean Data Type 1. Explain that the data type boolean has only two values: true and false, which are called the logical (Boolean) values. The central purpose of this data type is to manipulate logical (Boolean) expressions. 2. Explain that in Java, boolean, true, and false are reserved words, and the memory allocated for the boolean data type is one bit. Floating-Point Data Types 1. Explain that the floating-point data types deal with decimal numbers, and to represent real numbers, Java uses a form of scientific notation called floating-point notation.

5 Java Programming: From Problem Analysis to Program Design, 3 rd Edition Walk through Table 2-3 to show how decimal numbers are represented in floating-point notation, and point out that the E stands for the exponent. 3. Explain that as shown in Figure 2-3, the float and double types are used to represent decimal numbers. 4. Explain that floats represent any real number between 3.4E+38 and 3.4E+38, and the memory allocated for the float data type is 4 bytes. 5. Explain that doubles are used to represent any real number between 1.7E+308 and 1.7E+308, and the memory allocated for the double data type is 8 bytes. 6. Explain that the maximum number of significant digits in float values is 6 or 7, while the maximum number of significant digits in double values is 15. Emphasize that the default type of floating-point numbers is double. Therefore, using the data type float might produce an error, such as truncation from double to float. For students new to programming, it may not be obvious why using a float might cause a loss of data. Take time to explain truncation as it relates to the number of significant digits represented by each data type. Take time to explain what a literal, or constant, is. Arithmetic Operators and Operator Precedence 1. Walk through the five arithmetic operators, and point out that they can be used with both integral and floating-point types. 2. Explain that integral division truncates any fractional part because there is no rounding. 3. Explain that an arithmetic expression is constructed by using arithmetic operators and numbers, and the numbers in the expression are called operands. 4. Explain that the numbers used to evaluate an operator are called the operands for that operator, and operators that have only one operand are called unary operators, and operators that have two operands are called binary operators. Students new to programming may be unfamiliar with the concept of a unary operator. Take time to give examples of unary operators.

6 Java Programming: From Problem Analysis to Program Design, 3 rd Edition Explain integer division, emphasizing that the division operator represents the quotient in ordinary division when used with integral types, and walk through Example 2-3. Take time to work a few examples of integer division to make sure the concept is understood. Students new to programming may be unfamiliar with the mod operator. Take time to work examples, and to explain some of the subtleties of using the mod operator with negative numbers. Order of Precedence 1. Explain that Java uses operator precedence rules to determine the order in which operations are performed to evaluate the expression, and explain the precedence of the operators. 2. Explain that when arithmetic operators have the same precedence, they are evaluated from left to right, but that parentheses can be used to group arithmetic expressions. 3. Walk through Example 2-5 to illustrate operator precedence and the use of parentheses. 4. Explain that because arithmetic operators are evaluated from left to right, unless parentheses are present, the associativity of arithmetic operators is said to be from left to right. 5. Explain that since the char data type is also an integral data type, Java allows you to perform arithmetic operations on char data. Emphasize the difference between the character 8 and the integer 8, and work through several examples of using arithmetic operators on characters. Expressions 1. Explain that if all operands in an expression are integers, the expression is called an integral expression, and if all operands in an expression are floating-point numbers, the expression is called a floating-point or decimal expression. 2. Use Example 2-6 and Example 2-7 to illustrate integral and floating-point expressions.

7 Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-7 Mixed Expressions 1. Explain that an expression that has operands of different data types is called a mixed expression. 2. Explain that if the operator has the same types of operands (that is, both are integers or both are floating-point numbers), the operator is evaluated according to the type of the operand. 3. Explain that if the operator has both types of operands (that is, one is an integer and the other is a floating-point number), during calculation the integer is changed to a floatingpoint number with the decimal part of zero, and then the operator is evaluated, and the result is a floating-point number. 4. Explain that the entire expression is evaluated according to the precedence rules, and use Example 2-8 to show how to evaluate mixed expressions. Provide many examples of mixed expressions, as many students fail to realize the importance of this aspect of programming. A good illustrative example is the calculation of an average using all integer division versus using mixed division. Quick Quiz 1 1. The rules of a language determine which instructions are valid. Answer: syntax 2. True or False: Hello! is an example of a legal identifier. Answer: False 3. True or False: The Boolean data type has two possible values true and false. Answer: True 4. What is the value of the following expression? * 5 Answer: 23 Type Conversion (Casting) 1. Explain that implicit type coercion occurs when a value of one data type is automatically changed to another data type. 2. Explain that to avoid implicit type coercion, Java provides for explicit type conversion through the use of a cast operator.

8 Java Programming: From Problem Analysis to Program Design, 3 rd Edition Explain that the cast operator, also called the type conversion or type casting, takes the form (datatypename) expression. 4. Explain that in type casting, the expression is evaluated first and its value is then converted to a value of the type specified by datatypename. 5. Explain that when using the cast operator to convert a floating-point (decimal) number to an integer, you simply drop the decimal part of the floating-point number. 6. Work through Example 2-9 to demonstrate type conversion. 7. Explain that you can also use cast operators to explicitly convert char data values into int data values, and int data values into char data values by using a collating sequence. class String 1. Explain that a string is a sequence of zero or more characters, and strings in Java are enclosed in double quotation marks. 2. Present the class String, which contains various operations to manipulate a string, and note that it is presented in more detail in Chapter Explain that a string that contains no characters is called a null or empty string, and that strings such as hello are sometimes called character strings, string literals, or string constants. 4. Explain that the position of the first character is 0, the position of the second character is 1, and so on, and that the length of a string is the number of characters in it. Use Example 2-10 to illustrate these concepts. Emphasize that spaces must be counted when computing the length of a string. Input 1. Remind students that the main objective of Java programs is to perform calculations and manipulations on data, and the data must be loaded into main memory before it can be manipulated. Allocating Memory with Named Constants and Variables 1. Explain that a named constant is a memory location whose content is not allowed to change during program execution, and explain the syntax to declare a named constant.

9 Java Programming: From Problem Analysis to Program Design, 3 rd Edition Explain that the words static and final are reserved, and the word final specifies that the value stored in the identifier is fixed and cannot be changed. Explain that Java programmers typically use uppercase letters to name a named constant. Remind students that double is the default type for floating-point numbers, and explain the syntax for declaring a float. 3. Present the reasons for using named constants. 4. Explain that memory cells whose contents can be modified during program execution are called variables, and explain the syntax for declaring one variable or multiple variables. Explain that Java programmers typically use lowercase letters to declare variables. If a variable name is a combination of more than one word, then the first letter of each word, except the first word, is uppercase. Emphasize that variables must be declared before they can be used. Putting Data into Variables 1. Introduce this section by mentioning that the two common ways to place data into a variable are to use an assignment statement and to use an input, or read, statement. Assignment Statement 1. Explain the syntax for variable assignment, and emphasize that the value of the expression should match the data type of the variable. 2. Define the term initialization and explain that the equals sign is the assignment operator. 3. Walk through Example 2-13 to illustrate variable assignment, and use the code fragment to show the effect of the statements in the example.

10 Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-10 Explain that the Java language is strongly typed, which means that you cannot assign a value to a variable that is not compatible with its data type. 4. Explain that a statement such as x = y = z; is legal, and the associativity of the assignment operator is said to be from right to left. Saving and Using the Value of an Expression 1. Explain that to save the value of an expression and use it in a later expression, first declare a variable of the appropriate data type, and then use the assignment statement to assign the value of the expression to the variable that was declared. 2. Use Example 2-14 to illustrate saving the value of an expression to use it in a future expression. Declaring and Initializing Variables 1. Remind students that using a variable without initializing it will likely generate a compiler error. 2. Explain that variables can be initialized when they are declared, and explain the syntax for initializing variables at the time of declaration. Input (Read) Statement 1. Point out that in most cases, the standard input device is the keyboard, and that when the computer gets the data from the keyboard, the user is said to be acting interactively. The rest of this subsection presents the methods of the Scanner class. For students new to programming, it may be helpful to briefly explain the syntax of the examples, including the creation of an instance of the Scanner class, the dot operator, and the method calls. Note that this will be covered in more detail later in the book. 2. Explain that to put data into variables, we create an input stream object and associate it with the standard input device. Walk through the statement that accomplishes this. 3. Note that Scanner is a predefined Java class, and if the next statement can be interpreted as an integer, then the nextint() method retrieves the integer. 4. Explain that if the next input token can be interpreted as a floating-point number, the nextdouble() method retrieves the floating-point number.

11 Java Programming: From Problem Analysis to Program Design, 3 rd Edition Explain that the method next() retrieves the next input token as a string, and the method nextline() retrieves the next input as a string until the end of a line. 6. Emphasize that the expressions console.nextint(), console.nextdouble(), and console.next() skip whitespace characters. 7. Explain that System.in is called a standard input stream object and is designed to input data from the standard input device. However, the object System.in extracts data in the form of bytes from the input stream. 8. Explain that to use System.in, we first create a Scanner object so that the data can be extracted in a desired form. Note that the class Scanner is added to the Java library in Java version 5.0. Therefore, this class is not available in Java versions lower than Walk through Examples 2-15 through 2-17 to demonstrate how to read data of various types from a standard input device. 10. Explain what a comment is, and emphasize that comments are ignored by the compiler. Variable Initialization 1. Explain that a variable can be initialized by an assignment statement, or by using an input statement. 2. Stress that a read statement is much more versatile than an assignment statement. Reading a Single Character 1. Explain the syntax for reading a character using the next() method of the Scanner class and storing it in a char variable. In the example in the book, the first character is read from the input using the charat() method. Take time to explain the charat() method, and to walk through Example 2-18 to explain reading input in and storing it in variables. Increment and Decrement Operators 1. Explain that the increment operator, ++, increases the value of a variable by 1, and the decrement operator, --, decreases the value of a variable by 1.

12 Java Programming: From Problem Analysis to Program Design, 3 rd Edition Explain that the increment and decrement operators each have two forms, pre and post, and explain the syntax of the increment and decrement operators. 3. Explain the difference between pre- and post-increment and pre- and post-decrement operators, and walk through Example It may be helpful to work through several examples to illustrate the difference between pre- and post- increment and decrement operations. Point out that pre-increment operators and post-increment operators are also referred to as prefix operators and postfix operators, respectively. These operators have the highest level of precedence. Note that the result of the unary expression must be a variable of a numeric type, or a compile-time error occurs. Strings and the Operator + 1. Explain that string concatenation allows a string to be appended to the end of another string, using the operator Illustrate string concatenation using Example 2-20, pointing out that the operator + can be used to concatenate two strings, as well as a string and a numeric value or a character. Quick Quiz 2 1. If an operator has an integer and a floating-point operand, the result of the operation is a(n) number. Answer: floating-point 2. The expression (int)9.2 evaluates to. Answer: 9 3. True or False: The value of a variable can change during execution. Answer: True 4. Suppose a and b are int variables. What is the value of b? a = 3; b = 4 + (++a) Answer: 8

13 Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-13 Output 1. Note that the standard output device is usually the monitor. 2. Explain that in Java, output on the standard output device is accomplished by using the standard output object System.out. 3. Explain that the object System.out has access to two methods, print and println, to output a string on the standard output device. 4. Explain the syntax of the print and println methods and the difference between them. 5. Explain that the statement System.out.println(); prints a blank line, and point out that the empty parentheses are necessary. 6. Explain that when an output statement outputs char values, it outputs the character without the single quotation marks. Similarly, the value of a string does not include the double quotation marks, unless they are explicitly included as part of the string. 7. Walk through Examples 2-21 through 2-24 to illustrate output statements. 8. Walk through Table 2-4, explaining each of the escape characters, and use Example 2-25 for illustration. Method flush 1. Explain that the output generated by the methods print and println first goes into an area in the computer called a buffer. 2. Explain that when the buffer is full, the output is sent to the output device, and you can use the method flush associated with System.out to empty the buffer even if it is not full. Packages, Classes, Methods, and the import Statement 1. Introduce packages by explaining that only a small number of operations are defined in Java. Explain that many of the methods and identifiers needed to run a Java program are provided as a collection of libraries. 2. Explain that a package is a collection of related classes and every package has a name. 3. Explain that the term class is broadly used. It is used to create Java programs either application or applet, it is used to group a set of related operations, and it is used to allow users to create their own data types.

14 Java Programming: From Problem Analysis to Program Design, 3 rd Edition Explain that each of these operations is implemented using the Java mechanism of methods. 5. Explain that a method is a set of instructions designed to accomplish a specific task. 6. Explain that to make use of the existing classes, methods, and identifiers, you must specify the packages that contain the appropriate information using the reserved word import. 7. Explain the syntax of the import statement, emphasizing that import statements are placed at the top of the program. Point out to students that if you use the wildcard character (*) in the import statement, the compiler determines the relevant class(es) used in the program. Explain that the primitive data types are directly part of the Java language, and do not require that any package be imported into the program. Also, the class String is contained in the package java.lang. Emphasize that it is not necessary to import classes from the package java.lang because the system automatically does it for you. Note that mathematical functions are in the class Math in the package java.util, which must be imported. Creating a Java Application Program 1. Explain that the basic unit of a Java program is called a class, and a Java application program is a collection of one or more classes. 2. Remind students that a method is a set of instructions designed to accomplish a specific task, and some predefined or standard methods such as nextint, print, and println are already written and are provided as part of the system. 3. Explain that to accomplish most tasks, programmers must write their own methods. Emphasize that although it is often necessary to write a new method, whenever possible it is desirable to use a previously written method. Discuss reasons why. 4. Explain that one of the classes in a Java application program must have the method called main, and there can be only one method main in a Java program. 5. Emphasize that if a Java application program has only one class, it must contain the method main.

15 Java Programming: From Problem Analysis to Program Design, 3 rd Edition Explain that statements to declare memory spaces (named constants and variables), statements to create input stream objects, statements to manipulate data (such as assignments), and statements to input and output data will be placed within the class. 7. Explain that statements to declare named constants and input stream objects are usually placed outside the method main, and statements to declare variables are usually placed within the method main. 8. Explain that statements to manipulate data and input and output statements are placed within the method main. 9. Explain the syntax of a class to create a Java application program, and explain the general syntax of the method main. 10. Explain that the import statements and the program statements constitute the Java source code, which must be saved in a file called a source file that has the name extension.java. 11. Emphasize that the name of the class and the name of the file containing the Java program must be the same. 12. Explain that public static void main(string[] args) is called the heading of the method main. 13. Explain that the statements enclosed between curly braces ({ and }) form the body of the method main. 14. Explain that the body of the method main contains two types of statements: declaration statements and executable statements. 15. Explain that declaration statements are used to declare things such as variables. 16. Explain that executable statements perform calculations, manipulate data, create output, accept input, and so on. 17. Explain that variables or identifiers can be declared anywhere in the program, but must be declared before they can be used. 18. Walk through Examples 2-26 through 2-28 to illustrate the concepts in this section.

16 Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-16 The reserved word static may be a source of confusion to students. Point out that the heading of the method main contains the reserved word static. The statements to declare the named constants and the input stream objects are placed outside the definition of the method main. Therefore, Java requires that you declare the named constants and the input stream objects with the reserved word static. Note that static variables and classes will be discussed in more detail later in the book. Programming Style and Form Syntax 1. Introduce this section by emphasizing that a program must be understandable to other programmers, and also observe the correct syntax. 1. Remind students that the syntax rules of a language tell what is legal and what is illegal. Errors in syntax are detected during compilation. Emphasize that when the first syntax error is removed and the program is recompiled, subsequent syntax errors caused by the first syntax error may disappear. Therefore, you should correct syntax errors in the order in which the compiler lists them. Use of Blanks 1. Remind students that in Java, you use one or more blanks to separate numbers when data is input, and blanks are also used to separate reserved words and identifiers from each other and from other symbols. Emphasize that blanks (and whitespace in general) make the program much more readable. Use of Semicolons, Braces, and Commas 1. Explain that all Java statements must end with a semicolon, and the semicolon is also called a statement terminator. 2. Explain that braces can be regarded as delimiters, because they enclose the body of a method and set it off from other parts of the program. 3. Explain that commas are used to separate items in a list.

17 Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-17 Semantics 1. Explain that the set of rules that gives meaning to a language is called semantics. 2. Describe the difference between syntax and semantic errors. Naming Identifiers 1. Explain what self-documenting identifiers are, and that self-documenting identifiers can make comments less necessary. 2. Explain that an identifier used to name a named constant is all uppercase, and if the identifier is a run-together-word, then the words are separated with the underscore character. 3. Explain that an identifier used to name a variable is lowercase, and if the identifier is a run-together-word, then the first letter of each word, except the first word, is uppercase. 4. Explain that an identifier used to name a class is all lowercase with the first letter of each word in uppercase. Prompt Lines 1. Explain that part of good documentation is the use of clearly written prompts so that users will know what to do when they interact with a program. 2. Explain that prompt lines are executable statements that inform the user what to do. 3. Explain that in a program, whenever users must provide input, you must include the necessary prompt lines. Furthermore, these prompt lines should include as much information as possible about what input is acceptable. Take time to emphasize that prompt lines should only be included when they are specifically called for, and point out that many programs (such as those acting on data files) do not require prompts. Emphasize that there are other ways for the user to interact with the program, and these will be discussed later in the book. Documentation 1. Explain that a well-documented program is easier to understand and modify, even a long time after you originally write it. Explain that comments are used to document programs. 2. Explain that comments should appear in a program to explain the purpose of the program, identify who wrote it, and explain the purpose of particular statements.

18 Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-18 Comments 1. Explain that single line comments begin with // and can be placed anywhere in the line, and explain that everything after the // is ignored by the compiler. 2. Explain that multiple line comments are enclosed between /* and */ and the compiler ignores anything that appears between /* and */. Emphasize that single line comments can not include a newline, but that multiline comments may. Form and Style 1. Emphasize that programs should be properly indented and formatted, and to document the variables, programmers typically declare one variable per line, and put a space before and after an operator. 2. Walk through Example 2-29 to show the difference between poor use of white space and proper use of whitespace. More on Assignment Statements 1. Discuss the compound operators *=, +=, -=, /=, and %=. 2. Explain that the compound assignment statement lets you write simple assignment statements concisely by combining an arithmetic operator with an assignment operator. 3. Walk through Example 2-30, which demonstrates the use of compound statements. Programming Example: Convert Length 1. Walk through this example, which converts measurements in feet and inches into centimeters using the formula that 1 inch is equal to 2.54 centimeters. Programming Example: Make Change 1. Walk through this programming example, which computes the number of half-dollars, quarters, dimes, nickels, and pennies to be returned, returning as many half-dollars as possible, then quarters, dimes, nickels, and pennies, in that order. Quick Quiz 3 1. True or False: Java always initializes the value of a variable. Answer: False

19 Java Programming: From Problem Analysis to Program Design, 3 rd Edition Given the following assignments, what is the value in str? String str; str = Hello ; str = str + World ; Answer: Hello World 3. A(n) is a set of instructions designed to accomplish a specific task. Answer: method 4. Given the following statements, what is the value of myvar? int myvar = 0; int a = 5, b = 2; myvar = a / b; Answer: 2 Class Discussion Topics 1. What are possible errors and exceptions that might arise in any Java program? 2. Why would it be desirable to use pre-written code whenever possible? 3. Why is it important that code be well-commented and well-formatted? 4. What are ways to debug code? Additional Projects 1. Write a program that prompts the user for two characters and prints the sum of their Unicode values. 2. Write a program that prompts the user for an amount in dollars and converts it to the equivalent amount in euros (you can either assume that 1 euro = $1.25, or look up the current exchange rate on the Web). 3. Write a program that prompts the user for a temperature in degrees Fahrenheit and converts it to Celsius. Additional Resources 1. A complete listing of Java data types: 2. More information on expressions and a complete listing of operator precedence rules in Java:

20 Java Programming: From Problem Analysis to Program Design, 3 rd Edition Complete definitions of the predefined Java classes and Java API specifications: 4. A description of Java code conventions widely accepted in the Java community: 5. It is common practice to write Java comments that are compatible with the SunMicrosystems JavaDoc tool. This tool is capable of creating organized documentation for a Java project simply by parsing the comments in the Java source files. A thorough description of the JavaDoc standard can be found at: Key Terms arithmetic expression An expression constructed by using arithmetic operators and numbers. assignment operator The (=) the equals sign. Assigns a value to an identifier. associativity The order in which an operator is evaluated. binary operator An operator that has two operands. Boolean A data type that deals with logical values. cast operator Used for explicit type conversion. character string see string class Is used to create Java programs, either application or applet; it is used to group a set of related operations, and it is used to allow users to create their own data types. collating sequence A specific non-negative integer value in the Unicode character set. computer program A sequence of statements whose objective is to accomplish a task. data type A set of values together with a set of operations. decimal expression See floating-point expression declaration statement Used to declare things such as variables. decrement operator (--), which decreases the value of a variable by 1. double precision Values of type double. executable statements Perform calculations, manipulate data, create output, accept input, and so on. floating point expression An expression in which all operands in the expression are floating-point numbers. floating-point notation A form of scientific notation used by Java to represent real numbers. identifier Consists of letters, digits, the underscore character ( _), and the dollar sign ($), and must begin with a letter, underscore, or the dollar sign. implicit type coercion When a value of one data type is automatically changed to another data type. increment operator (++), which increases the value of a variable by 1. initialized A named constant that is declared integral A data type that deals with integers, or numbers without a decimal part. integral expression An expression where all operands are integers

21 Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-21 keyword A symbol that can not be redefined within any program. Also called a reserved word. length Describes the number of characters in a string. logical (Boolean) expression An expression that evaluates to true or false. method A set of instructions designed to accomplish a specific task. mixed expression An expression that has operands of different data types. multiple line comments Comments that are enclosed between /* and */. The compiler ignores anything that appears between /* and */. named constant A memory location whose content is not allowed to change during program execution. null (empty) A string containing no characters. operands The numbers and alphabetical symbols in the expression. operator precedence rules Determine the order in which operations are performed to evaluate an expression. output statements Any statement that sends data to the output device. Typically the output statement will print data to the monitor. package A collection of related classes. precedence See operator precedence rules precision The maximum number of significant digits. predefined methods Methods that are included in the Java class library. programming A process of planning and creating a program. programming language A set of rules, symbols, and special words. prompt lines Executable statements that inform the user what to do. run-together word When the name of a constant is a combination of more than one word. self-documenting identifiers Identifiers in the second set of statements. semantics The set of rules that gives meaning to a language. semantic rules Determine the meaning of instructions in a programming language. single line comment A statement that begins with // and can be placed anywhere in the line. single precision Values of type float. source code The combination of the import statements and the program statements. source file A file containing the source code, having the file extension.java. standard input stream object An object that is designed to receive input from the input device, such as System.in. standard methods See predefined methods standard output object An object that is designed to send data to the output device, such as System.out. statement terminator The semicolon (;) that terminates a statement. string A sequence of zero or more characters, which is enclosed in double quotation marks. string constant See String string literal See String syntax rules Rules of a programming language that determine the validity of instructions. token The smallest individual unit of a program written in any programming language. type casting See cast operator type conversion See cast operator

22 Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-22 unary operator An operator that has only one operand. variable A memory location whose content may change during program execution.

Chapter 2 Basic Elements of C++

Chapter 2 Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 2-1 Chapter 2 Basic Elements of C++ At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion

More information

Objectives. 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++ 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 information

Chapter 2: Basic Elements of C++

Chapter 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 information

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

Chapter 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 information

Full file at

Full 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

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

CSCI 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 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 information

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics Java Programming, Sixth Edition 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional Projects Additional

More information

Visual C# Instructor s Manual Table of Contents

Visual 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 information

Objectives. In this chapter, you will:

Objectives. 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 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

C++ Programming: From Problem Analysis to Program Design, Third Edition

C++ Programming: From Problem Analysis to Program Design, Third Edition C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 2: Basic Elements of C++ Objectives (continued) Become familiar with the use of increment and decrement operators Examine

More information

Data and Expressions. Outline. Data and Expressions 12/18/2010. Let's explore some other fundamental programming concepts. Chapter 2 focuses on:

Data 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 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

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. A Guide to this Instructor s Manual:

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. A Guide to this Instructor s Manual: Java Programming, Eighth Edition 2-1 Chapter 2 Using Data A Guide to this Instructor s Manual: We have designed this Instructor s Manual to supplement and enhance your teaching experience through classroom

More information

Basic Computation. Chapter 2

Basic Computation. Chapter 2 Basic Computation Chapter 2 Outline Variables and Expressions The Class String Keyboard and Screen I/O Documentation and Style Variables Variables store data such as numbers and letters. Think of them

More information

Chapter 2: Data and Expressions

Chapter 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 information

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

Introduction 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 information

C++ Basic Elements of COMPUTER PROGRAMMING. Special symbols include: Word symbols. Objectives. Programming. Symbols. Symbols.

C++ Basic Elements of COMPUTER PROGRAMMING. Special symbols include: Word symbols. Objectives. Programming. Symbols. Symbols. EEE-117 COMPUTER PROGRAMMING Basic Elements of C++ Objectives General Questions Become familiar with the basic components of a C++ program functions, special symbols, and identifiers Data types Arithmetic

More information

Chapter 2: Data and Expressions

Chapter 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 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

Chapter 2 Working with Data Types and Operators

Chapter 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 information

A variable is a name for a location in memory A variable must be declared

A variable is a name for a location in memory A variable must be declared Variables A variable is a name for a location in memory A variable must be declared, specifying the variable's name and the type of information that will be held in it data type variable name int total;

More information

Computational Expression

Computational Expression Computational Expression Variables, Primitive Data Types, Expressions Janyl Jumadinova 28-30 January, 2019 Janyl Jumadinova Computational Expression 28-30 January, 2019 1 / 17 Variables Variable is a name

More information

Basics of Java Programming

Basics 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 information

Chapter 2: Basic Elements of Java

Chapter 2: Basic Elements of Java Chapter 2: Basic Elements of Java TRUE/FALSE 1. The pair of characters // is used for single line comments. ANS: T PTS: 1 REF: 29 2. The == characters are a special symbol in Java. ANS: T PTS: 1 REF: 30

More information

Section 2: Introduction to Java. Historical note

Section 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 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

Program Fundamentals

Program Fundamentals Program Fundamentals /* HelloWorld.java * The classic Hello, world! program */ class HelloWorld { public static void main (String[ ] args) { System.out.println( Hello, world! ); } } /* HelloWorld.java

More information

ECE 122 Engineering Problem Solving with Java

ECE 122 Engineering Problem Solving with Java ECE 122 Engineering Problem Solving with Java Lecture 3 Expression Evaluation and Program Interaction Outline Problem: How do I input data and use it in complicated expressions Creating complicated expressions

More information

Data Conversion & Scanner Class

Data Conversion & Scanner Class Data Conversion & Scanner Class Quick review of last lecture August 29, 2007 ComS 207: Programming I (in Java) Iowa State University, FALL 2007 Instructor: Alexander Stoytchev Numeric Primitive Data Storing

More information

Basic Computation. Chapter 2

Basic Computation. Chapter 2 Walter Savitch Frank M. Carrano Basic Computation Chapter 2 Outline Variables and Expressions The Class String Keyboard and Screen I/O Documentation and Style Variables Variables store data such as numbers

More information

Primitive Data Types: Intro

Primitive Data Types: Intro Primitive Data Types: Intro Primitive data types represent single values and are built into a language Java primitive numeric data types: 1. Integral types (a) byte (b) int (c) short (d) long 2. Real types

More information

Chapter. Let's explore some other fundamental programming concepts

Chapter. Let's explore some other fundamental programming concepts Data and Expressions 2 Chapter 5 TH EDITION Lewis & Loftus java Software Solutions Foundations of Program Design 2007 Pearson Addison-Wesley. All rights reserved Data and Expressions Let's explore some

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

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

CMPT 125: Lecture 3 Data and Expressions

CMPT 125: Lecture 3 Data and Expressions CMPT 125: Lecture 3 Data and Expressions Tamara Smyth, tamaras@cs.sfu.ca School of Computing Science, Simon Fraser University January 3, 2009 1 Character Strings A character string is an object in Java,

More information

Chapter 2: Data and Expressions

Chapter 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 information

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee C Language Part 1 (Minor modifications by the instructor) References C for Python Programmers, by Carl Burch, 2011. http://www.toves.org/books/cpy/ The C Programming Language. 2nd ed., Kernighan, Brian,

More information

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

CS5000: 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 information

Chapter 3: Operators, Expressions and Type Conversion

Chapter 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 information

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Expressions 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 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

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

UNIT- 3 Introduction to C++

UNIT- 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 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. 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

The C++ Language. Arizona State University 1

The C++ Language. Arizona State University 1 The C++ Language CSE100 Principles of Programming with C++ (based off Chapter 2 slides by Pearson) Ryan Dougherty Arizona State University http://www.public.asu.edu/~redoughe/ Arizona State University

More information

3. Java - Language Constructs I

3. 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 information

4 Programming Fundamentals. Introduction to Programming 1 1

4 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 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

IT 374 C# and Applications/ IT695 C# Data Structures

IT 374 C# and Applications/ IT695 C# Data Structures IT 374 C# and Applications/ IT695 C# Data Structures Module 2.1: Introduction to C# App Programming Xianrong (Shawn) Zheng Spring 2017 1 Outline Introduction Creating a Simple App String Interpolation

More information

COMP 202 Java in one week

COMP 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 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

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

Data 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 information

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are: LESSON 1 FUNDAMENTALS OF C The purpose of this lesson is to explain the fundamental elements of the C programming language. C like other languages has all alphabet and rules for putting together words

More information

Program Elements -- Introduction

Program Elements -- Introduction Program Elements -- Introduction We can now examine the core elements of programming Chapter 3 focuses on: data types variable declaration and use operators and expressions decisions and loops input and

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

Review Chapters 1 to 4. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

Review Chapters 1 to 4. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013 Review Chapters 1 to 4 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013 Introduction to Java Chapters 1 and 2 The Java Language Section 1.1 Data & Expressions Sections 2.1 2.5 Instructor:

More information

Introduction to Java Chapters 1 and 2 The Java Language Section 1.1 Data & Expressions Sections

Introduction to Java Chapters 1 and 2 The Java Language Section 1.1 Data & Expressions Sections Introduction to Java Chapters 1 and 2 The Java Language Section 1.1 Data & Expressions Sections 2.1 2.5 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013 2 Scope Introduce the Java programming

More information

Zheng-Liang Lu Java Programming 45 / 79

Zheng-Liang Lu Java Programming 45 / 79 1 class Lecture2 { 2 3 "Elementray Programming" 4 5 } 6 7 / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch. 2 in HS 11 / Zheng-Liang Lu Java Programming 45 / 79 Example Given a radius

More information

Chapter 2: Using Data

Chapter 2: Using Data Chapter 2: Using Data Declaring Variables Constant Cannot be changed after a program is compiled Variable A named location in computer memory that can hold different values at different points in time

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

COMP 110 Introduction to Programming. What did we discuss?

COMP 110 Introduction to Programming. What did we discuss? COMP 110 Introduction to Programming Fall 2015 Time: TR 9:30 10:45 Room: AR 121 (Hanes Art Center) Jay Aikat FB 314, aikat@cs.unc.edu Previous Class What did we discuss? COMP 110 Fall 2015 2 1 Today Announcements

More information

Expressions and Data Types CSC 121 Spring 2017 Howard Rosenthal

Expressions and Data Types CSC 121 Spring 2017 Howard Rosenthal Expressions and Data Types CSC 121 Spring 2017 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types

More information

Lesson 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 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 information

Programming Lecture 3

Programming Lecture 3 Programming Lecture 3 Expressions (Chapter 3) Primitive types Aside: Context Free Grammars Constants, variables Identifiers Variable declarations Arithmetic expressions Operator precedence Assignment statements

More information

Chapter 2: Using Data

Chapter 2: Using Data Chapter 2: Using Data TRUE/FALSE 1. A variable can hold more than one value at a time. F PTS: 1 REF: 52 2. The legal integer values are -2 31 through 2 31-1. These are the highest and lowest values that

More information

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Features 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 information

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Expressions 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 information

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

COMP Primitive and Class Types. Yi Hong May 14, 2015 COMP 110-001 Primitive and Class Types Yi Hong May 14, 2015 Review What are the two major parts of an object? What is the relationship between class and object? Design a simple class for Student How to

More information

Java Notes. 10th ICSE. Saravanan Ganesh

Java 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 information

CS101: Fundamentals of Computer Programming. Dr. Tejada www-bcf.usc.edu/~stejada Week 1 Basic Elements of C++

CS101: Fundamentals of Computer Programming. Dr. Tejada www-bcf.usc.edu/~stejada Week 1 Basic Elements of C++ CS101: Fundamentals of Computer Programming Dr. Tejada stejada@usc.edu www-bcf.usc.edu/~stejada Week 1 Basic Elements of C++ 10 Stacks of Coins You have 10 stacks with 10 coins each that look and feel

More information

Language Basics. /* The NUMBER GAME - User tries to guess a number between 1 and 10 */ /* Generate a random number between 1 and 10 */

Language Basics. /* The NUMBER GAME - User tries to guess a number between 1 and 10 */ /* Generate a random number between 1 and 10 */ Overview Language Basics This chapter describes the basic elements of Rexx. It discusses the simple components that make up the language. These include script structure, elements of the language, operators,

More information

CSc 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 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 information

AP Computer Science A

AP Computer Science A AP Computer Science A 1st Quarter Notes Table of Contents - section links Click on the date or topic below to jump to that section Date : 9/8/2017 Aim : Java Basics Objects and Classes Data types: Primitive

More information

Chapter 17. Fundamental Concepts Expressed in JavaScript

Chapter 17. Fundamental Concepts Expressed in JavaScript Chapter 17 Fundamental Concepts Expressed in JavaScript Learning Objectives Tell the difference between name, value, and variable List three basic data types and the rules for specifying them in a program

More information

JAVA Programming Fundamentals

JAVA 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 information

Objects and Types. COMS W1007 Introduction to Computer Science. Christopher Conway 29 May 2003

Objects and Types. COMS W1007 Introduction to Computer Science. Christopher Conway 29 May 2003 Objects and Types COMS W1007 Introduction to Computer Science Christopher Conway 29 May 2003 Java Programs A Java program contains at least one class definition. public class Hello { public static void

More information

A Java program contains at least one class definition.

A Java program contains at least one class definition. Java Programs Identifiers Objects and Types COMS W1007 Introduction to Computer Science Christopher Conway 29 May 2003 A Java program contains at least one class definition. public class Hello { public

More information

Basics of Programming

Basics of Programming Unit 2 Basics of Programming Problem Analysis When we are going to develop any solution to the problem, we must fully understand the nature of the problem and what we want the program to do. Without the

More information

Lesson 02 Data Types and Statements. MIT 11053, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL

Lesson 02 Data Types and Statements. MIT 11053, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL Lesson 02 Data Types and Statements MIT 11053, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL Topics Covered Statements Variables Data Types Arithmetic

More information

CS112 Lecture: Primitive Types, Operators, Strings

CS112 Lecture: Primitive Types, Operators, Strings CS112 Lecture: Primitive Types, Operators, Strings Last revised 1/24/06 Objectives: 1. To explain the fundamental distinction between primitive types and reference types, and to introduce the Java primitive

More information

We now start exploring some key elements of the Java programming language and ways of performing I/O

We now start exploring some key elements of the Java programming language and ways of performing I/O We now start exploring some key elements of the Java programming language and ways of performing I/O This week we focus on: Introduction to objects The String class String concatenation Creating objects

More information

CSE 1001 Fundamentals of Software Development 1. Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018

CSE 1001 Fundamentals of Software Development 1. Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018 CSE 1001 Fundamentals of Software Development 1 Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018 Identifiers, Variables and Data Types Reserved Words Identifiers in C Variables and Values

More information

IPCoreL. Phillip Duane Douglas, Jr. 11/3/2010

IPCoreL. Phillip Duane Douglas, Jr. 11/3/2010 IPCoreL Programming Language Reference Manual Phillip Duane Douglas, Jr. 11/3/2010 The IPCoreL Programming Language Reference Manual provides concise information about the grammar, syntax, semantics, and

More information

Hello World. n Variables store information. n You can think of them like boxes. n They hold values. n The value of a variable is its current contents

Hello World. n Variables store information. n You can think of them like boxes. n They hold values. n The value of a variable is its current contents Variables in a programming language Basic Computation (Savitch, Chapter 2) TOPICS Variables and Data Types Expressions and Operators Integers and Real Numbers Characters and Strings Input and Output Variables

More information

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

Object oriented programming. Instructor: Masoud Asghari Web page:   Ch: 3 Object oriented programming Instructor: Masoud Asghari Web page: http://www.masses.ir/lectures/oops2017sut Ch: 3 1 In this slide We follow: https://docs.oracle.com/javase/tutorial/index.html Trail: Learning

More information

Chapter 2. Lexical Elements & Operators

Chapter 2. Lexical Elements & Operators Chapter 2. Lexical Elements & Operators Byoung-Tak Zhang TA: Hanock Kwak Biointelligence Laboratory School of Computer Science and Engineering Seoul National Univertisy http://bi.snu.ac.kr The C System

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

Chapter 2: Introduction to C++

Chapter 2: Introduction to C++ Chapter 2: Introduction to C++ Copyright 2010 Pearson Education, Inc. Copyright Publishing as 2010 Pearson Pearson Addison-Wesley Education, Inc. Publishing as Pearson Addison-Wesley 2.1 Parts of a C++

More information

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

2.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 information

Operators. Java operators are classified into three categories:

Operators. Java operators are classified into three categories: Operators Operators are symbols that perform arithmetic and logical operations on operands and provide a meaningful result. Operands are data values (variables or constants) which are involved in operations.

More information

MODULE 02: BASIC COMPUTATION IN JAVA

MODULE 02: BASIC COMPUTATION IN JAVA MODULE 02: BASIC COMPUTATION IN JAVA Outline Variables Naming Conventions Data Types Primitive Data Types Review: int, double New: boolean, char The String Class Type Conversion Expressions Assignment

More information

Types and Expressions. Chapter 3

Types and Expressions. Chapter 3 Types and Expressions Chapter 3 Chapter Contents 3.1 Introductory Example: Einstein's Equation 3.2 Primitive Types and Reference Types 3.3 Numeric Types and Expressions 3.4 Assignment Expressions 3.5 Java's

More information

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen Chapter 2: Introduction to C++ 2.1 Parts of a C++ Program Copyright 2009 Pearson Education, Inc. Copyright 2009 Publishing Pearson as Pearson Education, Addison-Wesley Inc. Publishing as Pearson Addison-Wesley

More information

Information Science 1

Information Science 1 Information Science 1 Simple Calcula,ons Week 09 College of Information Science and Engineering Ritsumeikan University Topics covered l Terms and concepts from Week 8 l Simple calculations Documenting

More information

CPS122 Lecture: From Python to Java last revised January 4, Objectives:

CPS122 Lecture: From Python to Java last revised January 4, Objectives: Objectives: CPS122 Lecture: From Python to Java last revised January 4, 2017 1. To introduce the notion of a compiled language 2. To introduce the notions of data type and a statically typed language 3.

More information

LECTURE 02 INTRODUCTION TO C++

LECTURE 02 INTRODUCTION TO C++ PowerPoint Slides adapted from *Starting Out with C++: From Control Structures through Objects, 7/E* by *Tony Gaddis* Copyright 2012 Pearson Education Inc. COMPUTER PROGRAMMING LECTURE 02 INTRODUCTION

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