CS 18000 Lecture Notes - Lecture 3: Substring, Reserved Word, Pariah Dog

44 views5 pages
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
Unlock document

This preview shows pages 1-2 of the document.
Unlock all 5 pages and 3 million more documents.

Already have an account? Log in
- 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
Unlock document

This preview shows pages 1-2 of the document.
Unlock all 5 pages and 3 million more documents.

Already have an account? Log in

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.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents