Java Illuminated: Chapter 2 [Programming]

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Assignment Operator

When you declare a variable you can also assign an initial value to the data to do this you need to use an assignment operator (=) dataType variableName = initialValue; variable1 = initialValue1 The INITIAL VALUE gets ASSIGNED to the item variable1

$

$ is designated for software generated variable names.

String concatenation operator

+ operator which allows us to print the values of variables along with string literals. ex: System.out.println("testGrade is " + grade);

\r

Carriage Return

Classes

Describe a logical entity that has data as well as methods to manipulate that data.

\"

Double Quotes

Float-Point Data type

Floating data types store numbers with fractional parts. Java supports two floating point data types: single precision float and double-precision double.

Variables

Java allows you to refer to data in a program by defining variables which are named locations in memory where you can store values.

\n

Newline

\'

Single Quote

Identifiers

Symbolic names that you assign to classes, methods, and data.

\t

Tab

Data type

The type of data which defines the type of data that will be input or output

dataType variable2 = variable1

float = salesTax = .05f; double taxRate = salesTax; <-- GOOD double = salesTax = .05f; float taxRate = salesTax <-- NOT GOOD because float is a lower precision.

Reserved words

words that cannot be used as identifiers.

Declaring a variable

Naming a variable: By convention naming variables always start in lowercase and letters after that are upper cased example ageInYears, booksToRead.

Java supports eight primitive data types

byte, short, int, long, float, double, char, and boolean.

Java letter

a-z A-Z _ or $

\f

Form Feed

Constant

A data item in which its value will not and should not change during program execution nor is it likely to change from one execution of the program to the other.

String literal

A sequence of characters enclosed by double quotes. One set of quotes "opens" the string literal and the second set of quotes "closes" the literal. Ex "hello" "Hello world" "The value of x is " String literals cannot extend more than one line. You can use the concatenation operator to break up a long statement.

\\

Backslash

\b

Backspace

Boolean

Boolean data type can store only two values which are expressed using the Java reserved words true and false. Booleans are typically used for decision making and for controlling the order of execution of a program. ex: boolean isEmpty boolean passed, failed;

Block

Consists of 0, 1, or more statements and starts with a left curly brace and ends with a right curly brace. Blocks are required for class and method definitions and can be used anywhere else in the program that a statement is legal.

Char

FOR STORING SINGLE LETTERS Ex: char finalGrade; char middleInitial; char newline, char tab. Uses 16 bits. stored in 2 bytes. Char data type stores one Unicode character which is encoded as unsigned numbers. minimum value encoded as 0000 null maximum value FFFF = not a character.

Float-Double

Float is stored in 32 bits / 4 size in bytes Double is stored in 64 bits / 8 size in bytes Float is used for calculations not requiring such precision also because they require less memory. Double is used over the float type for greater precision. It is advised that floating numbers require more time for processing. float salesTax double interestRate double paycheck, sumSalaries;

Java integer data types

Int, long, short, byte these differ in the number of bytes of memory allocated to store each type and, therefore, the maximum and minimum values that can be stores in a variable of that type. All of Java's integer types are signed meaning they can be positive or negative the high-order or leftmost bit is reserved for the sign. Int (2.1 bil = 4 bytes ) = sufficient for most needs stores +/- integers up to 2 billion. Short/byte(32k = 2 bytes / 127 = 1 byte) data types are only used for when memory space is critical long data type (9 x 10^6 = 8 bytes) is needed for values larger than 2 billion

final

The keyword preceding datatype that is going to define constants. ex dataType CONSTANT_IDENTIFIER = assignedValue; Assigning a value is optional when the constant is defined but you must assign a value before the constant is used in the program.

Block Comments

These can span several lines and they begin with /* and end with */ everything between the two are ignored by the compiler.

CONSTANT_IDENTIFIER

Usually in all caps to make constants stand out easily and also these are usually defined at the top. Ex. final int DAYS_IN_LEAP_YEAR = 366;


Kaugnay na mga set ng pag-aaral

Sherpath: Informatics in Nursing Practice

View Set

Set 4: Practice Test Q's and A's

View Set

HEMATOPATHOLOGY OF RED BLOOD CELLS AND BLEEDING DISORDERS

View Set

Computer Science ( A ) - Exercises 07.01-05

View Set

Ch. 56 ST-Elevation MI Management

View Set

Accessory Digestive & Reproduction

View Set

1- Care of the Patient with an Endocrine Disorder

View Set

Conectores (Corregir la cohesión de un texto)

View Set