Chapter 3: The World of Variables and Operators

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

modulus operator

An operator, denoted with a percent sign ( %), that works on integers and yields the remainder when one number is divided by another.

system.out.print(variable)

It takes the variable and pulls the value out of the variable and prints it.

system.out.print("")

It will print out the string within the quotation marks

Byte storage space

8 bits A group of eight bits.

int data type

___ data type uses 4 bytes of storage space and has a range of -2^31 (-2147483648) to 2^31 - 1 (2147483647). It is most commonly used data type for storing integers as it has the most practical range.

char data type

____ stands for character and is used to store single unicode characters such as 'A', '%', '@' and 'p' etc. It uses 2 bytes of memory. holds any single character

control flow statements

________ __________ __________ let you control the flow of the execution of the code in your program. In Java programming language, you can control the flow of execution of the code by placing the decision making, branching, looping, and adding conditional blocks.

Initializing a variable

The first time you set the value of a variable. the act of assigning its first value, often at the same time the variable is created The assignment of a value to a variable 📕: Every time you declare a new variable, you need to give it an initial value. This is known as ______________ ___ _______ .

concatenate

to link together or join. Typically used when joining together text Strings in programming (e.g. "Hello, "+name)

Bit

A contraction of "Binary Digit"; the single unit of information in a computer, typically represented as a 0 or 1 A contraction of "Binary Digit". A bit is the single unit of information in a computer, typically represented as a 0 or 1. binary digits the smallest unit of data in a computer

narrowing conversion

A conversion from one data type into another in which information could be lost. Converting from "double" to an "int" is a _______________ If we want to assign a larger data type to a smaller data type, we need to indicate it explicitly using a pair of parenthesis. This is known as ________________. Ex: int x = (int) 20.9; here we can casting a double (8 bytes) into an int (4 bytes)

camel casing

A style of creating identifiers in which the first letter is not capitalized, but each new word is. a style in which an identifier begins with a lowercase letter and subsequent words within the identifier are capitalized 📕: is the practice of writing compound words with mixed casing, capitalising the first letter of each word except the first word. Ex: thisIsAVariableName

Variables

Are names given to data that we need to store and manipulate in our programs. Allow the program to save values and change them. Are sometimes called fields

byte data type

Book: The ______ data type is used for storing integers from -128 to 127. It uses 1 byte of storage space (this is known as the width or the size of the data type). We normally use the ____ data type if storage space is a concern or if we are certain the value of the variable will not exceed the -128 to 127 range. holds very small integers from -128 to 127

Primitive Data Types

Book: there are 8 basic data types that are predefined in Java. These are known as ___________ data types supported directly by computer hardware or a programming language byte, short, int, long, float, double, char, boolean

+= operator

Compound assignment operator that adds the right-hand operand to the left and stores the result in the left-hand operand; a ___ b is equivalent to a = a + b.

System.out.println

Java method that lets us print out a line of output followed by a newline to the user Displays text for the user: Ex. System.out.println("Hello") Hello

public static void main(String[] args)

Line 2 of program, opens programming block method header main method The start of every of every time you code.

floating point numbers

Numbers with fractional parts A number that can have a fractional part -Scientific notation in computers -Allows very large and small numbers using exponents -Made up of: *Significand*: 5, 1.5, -2.001 *Exponent*: 2, -2 -Put decimal after integers to make floating point 1 ~ 1.0

Type casting (in java)

Sometimes in our program, it is necessary to convert one data type to another, such as from a double to an int. This is known as ______ ________

++ or -- operator

The __ operator is used when you want to increase the value of a variable by 1. Ex: If: int x = 2; if you write x__ ; the value of x becomes 3. It is equivalent to x=x+1 There is no need to use the = operator when you use the __ operator The __ operator can be placed in front of or behind the variable name. or __ would equal to x= x-1 This operator decreases the value of the operator by 1

long data type

The ____ data type uses 8 bytes of storage space and has a range of 2^63 to 2^63 -1. It is rarely used unless you really need to store a very large integer (such as the number of inhabitants on Earth). In order to specify a long value, you have to add the suffix "L" to the end of the number.

Short data type

The _____ data type uses 2 bytes of storage space and has a range of -32,768 to 32,767. holds small integers from -32,768 to 32,767

+=, -=, *=, /=, %=

The arithmetic/assignment operators, providing a shorthand for assignments that use a single operation to modify the value of a variable. For example, the statement a += 5; is equivalent to the statement a = a + 5; 📕: Instead of writing x = x+2, we can write x __ 2 to express the same meaning. The _______ operator is a shorthand that combines the assignment operator with the addition operator. Hence, x_____2 simply means x = x+2 similarly if we want to do a subtraction we can write x= x-2 or x -= 2. The same works for all 5 operators.

boolean data type

________ is a special data type that can only hold two data values true and false. It is commonly used in control flow statements. allows you to create variables that may hold one of two possible values: "true" or "false"

float data type

data type uses 4 bytes of storage and has a range of approximately -3.40282347 x 10^38 to +4.0282347 x 10^38. It has a precision of about 7 digits. This means that if you use ____ to store a number like 1.23456789 (9 digits) the number will be rounded off to approximately 7 digits (i.e., 1.234568). If you want to treat the floating point number as a _____ you have to add a suffix "F" to the end of the number

double data type

the ______ data type uses 8 bytes of storage and has a range of approximately negative 1.79769313486231570 x 10^308 to positive 1.79769313486231570 x 10^308, with a precision of 15 digits. By default whoever you specify a floating point number in Java, it is automatically considered to be a ______ not a float. If you want Java to treat the floating point number as a float, you have to add a suffix "F" to the end of a number.

Assignment Operator (the equals sign =)

📕: The = sign in programming has a different meaning from the = sign we learned in math. In programming, the = sign is known as an __________ ________. It means that we are assigning the value on the right side of the = sign to the variable on the left. The '=' character causes the compiler or interpreter to evaluate to the expression on its right and store the result in the variable(s) on its left. ex: year = 20;

Basic operators (in Java)

📕: besides assigning an initial value to a variable or assigning another variable to it, we can also perform the usually mathematic operations on variable. _____ ________ in Java include +,-,*,/ and % which represent addition, subtraction, multiplication division and modulus respectively.


Set pelajaran terkait

World Geography Unit 1 Quizzes 1-3

View Set

Collaboration and Workbook Sharing

View Set

Chapter 16: Financial Leverage and Capital Structure Policy.

View Set

MED SURG fluid and electrolyte balance

View Set

LearningCurve 4d: Hearing; The Body Senses; The Chemical Senses (LO 4.12-4.22)

View Set

Human Growth and Development : Freud and Erikson's theories

View Set

S-130 Wildland Firefighter Training

View Set