Lecture 4 - Two basic types: o Declarations o Executable...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Strings Are a series of chars String literals are delimited with “ “ o Eg: “A string” Strings are objects of the String class (java.lang package) o Have associated methods o Are immutable (i.e. can’t be changed) * Use the StringBuffer class to store strings that may change Strings are treated specially in Java o The compiler creates a String object for each string literal in the source code o Can be created without using new (the keyword operator ‘new’) String name = “Alice”; o Can be concatenated using + Eg: “John “ + “Adams” Object References Essentially, are “pointers” to objects created on heap memory * Form: classname objectRef; o Eg: Vector myVector; o myVector = new Vector(); o or Vector myVector = new Vector(); Default Initializations Variables are set to “zero” unless explicitly initialized: o Byte, short, int, and long 0 o float and double 0.0 o char ‘\u0000’
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
o boolean false o object references null Statements Are the basic components of a program
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Two basic types: o Declarations o Executable statements Are terminated with ; Eg: double x = 3.5; import java.awt.Graphics; value = 3 * i; * System.out.println(Hello); //System is class, out is object, println is method Assignment Statements General form: variable = expression; The expression is evaluated and the result stored in the variable Eg: x = 5.3; y = x + 3.7; Expressions are a combination of operators and operands o They evaluate to some value Arithmetic Operators Operator Meaning + addition-subtraction * multiplication / division % modulus (remainder) Division o If both operands are integers, the result is an integer (possibly truncated) Eg: 23 / 10 results in 2 o If one or more operands are floating point, the result is floating point Eg: 23.0 / 10 results in 2.3 Modulus o 23 % 10 results in 3 o 23.0%10 results in 3.0 o-23.0 % 10 results in -3.0...
View Full Document

Page1 / 3

Lecture 4 - Two basic types: o Declarations o Executable...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online