CS 18000 Lecture Notes - Lecture 5: Exclusive Or, Control Flow, Null Pointer

31 views3 pages
1. Declarations and Reference Types
i. I.e. : Wheel w = new wheel(15.6);
b. Declaration of a variable of a reference type allocates space only for the reference,
not for the object to which it refers
c. Default value of a reference variable “null”
d. Attempting to “use” an uninitialized reference variable results in a “null pointer
exception”
2. String
a. Java class String is built in
i. No need to import
ii. Language supports String literals (“hello”)
3. Operations on Strings
a. Concatenation (+) built-in to Java
b. Many operations can be performed on Strings b/c it creates sequences
c. I.e. string ->
i. String a = “kit” + “ten” ; // a is kitten
4. Comparing Strings
a. == does not work
b. String equals method: s1.equals(s2)
5. Formatting Strings
a. Template string includes regular characters and “escape sequences”
i. %s: string
ii. %d: integer
iii. %f: float
iv. %10s: pad string on left to make it 10 characters
v. %-10s: pad string on right to make it 10 characters
vi. %12d: pad integer on left to make it 12 characters
vii. %10.3f: format number with 3 decimals; total width 10
viii. %.2f: format with 2 decimals
Unlock document

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

Already have an account? Log in

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