CS 18000 Lecture Notes - Lecture 3: Substring, Reserved Word, Pariah Dog
Scanner
- This is what allows users to read values of various types.
Java Formatting Notes
- Naming conventions:
- Variables: lowerCamelCase
- I.e. squareIt, returnIt
- Classes: UpperCamelClass
- I.e. WheelClass, CalculatorClass
- Symbolic constants: UPPER_CASE
- I.e.
- Open curly at end of line ({), denotes beginning and ending of group statement
Numbers and Mathematical Operators
Values, Variables, and Literals
- Programs (and CPU’s) work with values
- Values are represented in programs by literals and stored in variables
- Literals
- I.e. -3, -23, 4.5, .23, 3E8, 6.02e+23
- “Hello there”, ‘A’, true, false
- Variables
- I.e. x,y, a, b, hello Message, wheel, robot, r1, w27
- Use letters, digits, and “_” (start with letter)
- Identify a location in memory
Types
- Variables and literals have types
- I.e.: int, double, String
- Type is a formal definition
- Set of values, operations
Example Java type, int
- Set of values: subset of the integers
- Stored in 4 consecutive bytes, 32 bits
- Range: -2147483648 ~ 2147482647
- Literals: 23, 45, -19, 0
- Variables declared with “int” reserved word
- Set of operations: standard mathematical
- +, -, &, /
- %(mod) remainder = 17/3 = 5 ⅔ -> 2
-87%25 = 12
Type Categories in JAva
- Primitive Types
- Built-in to language
- Boolean, byte, short, int, long, float, double, char
- Occupy enough bits/bytes to store value
Example Reference Type: String
- Set of values:
- Sequences of characters
- Length: 0 to 2,147,483,647
- Set of operations:
- Concat() (also + operator)
- toUpperCase()
- length()
- substring()
- Plus many others
Document Summary
This is what allows users to read values of various types. Open curly at end of line ({), denotes beginning and ending of group statement. Values are represented in programs by literals and stored in variables. I. e. x,y, a, b, hello message, wheel, robot, r1, w27. Use letters, digits, and _ (start with letter) %(mod) remainder = 17/3 = 5 -> 2. Boolean, byte, short, int, long, float, double, char. Concat() (also + operator) touppercase() length() substring() Wheel class public class wheel { double radius; Return 2 * math. pi * radius; double getarea() { Return math. pi * radius * radius; double getradius() { return radius; A new one created for each new wheel() . In java, variables must be declared and given a type. Java compiler does 2 things with this information. Arranges for space to be allocated for the variable to store a value. Ensures that only valid (type-defined) operations can be perfromed on this variable.