Module 2: Basic Elements of Java Flashcards
Are user-defined names for methods, variables, constants, and classes
Identifiers
Rules in Naming Identifiers
- The first character of your identifier should start with a letter of the alphabet, an underscore (_), or a dollar sign ($).
- Identifier must contain no spaces.
- Identifier must contain no special characters.
- Keywords are Reserved words, thus it should not be used as Identifier
Create identifiers that are _____.
descriptive of their purpose
If your identifier is composed of several words (65,535 characters is the maximum length per identifier), _____ is a good programming practice.
capitalizing the first letter of each word
- Specify the different sizes and values that can be stored in the variable variable
- Defines the values that a variable can take
Data Types
Two Types of Data Types
- Primitive Data Type
2. Reference Data Type (Non-Primitive Data Type)
- The building blocks of data manipulation.
- Basic data types available in Java language.
Primitive Data Type
Include Classes, Interfaces, and Arrays
Reference Data Type (Non-Primitive Data Type)
8 Primitive Data Types
- boolean
- byte
- char
- short
- int
- long
- float
- double
Primitive Data Type:
true or false
boolean
Primitive Data Type:
two’s (2) compliment integer
byte, short, int, and long
Primitive Data Type:
unicode character
char
Primitive Data Type:
IEEE 754 floating point
float and double
Default value of boolean
false
Default value of byte
0
Default value of char
\u0000
Default value of short
0
Default value of int
0
Default value of long
0
Default value of float
0.0
Default value of double
0.0
Range of Values of boolean
true, false
Range of Values of byte
-128 to 127
Range of Values of char
Character representation of ASCII values 0 to 255
Range of Values of short
-32,768 to 32,767
Range of Values of int
-2,147,483,648 to 2,147,483,647
Range of Values of long
-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
Range of Values of float
up to 7 decimal digits
Range of Values of double
up to 16 decimal degits
Are identifiers whose values can be changed
Variables
The general syntax for declaring a variable is:
;
To declare a variable with an initial value, the syntax is:
=;
Are identifiers whose values never change once declared
Constants
The general syntax for declaring constants is:
final = ;
The process of assigning a value or variable of a specific type to a variable of another type
Type Casting
Type Casting is a method or process that _____ into _____ in both ways manually and automatically.
converts a data type; another data type
The _____ is done by the compiler and _____ performed by the programmer
automatic conversion; manual conversion
Two Types of Castings
- Widening Type Casting
2. Narrowing Type Casting
Converting a lower data type into a higher one
Widening Type Casting
Widening Type Casting is also known as _____
Implicit Conversion or Casting Down
Converting a higher data type into a lower one
Narrowing Type Casting
Narrowing Type Casting is also known as _____
Explicit Conversion or Casting Up
If we do not perform casting in Narrowing Type Casting then the compiler reports a _____.
compile-time error
In the case of Narrowing Type Casting, the higher data types (having larger size) are converted into lower data types (having smaller size). Hence there is the _____. This is why this type of conversion does not happen automatically.
loss of data
Are symbols that perform logical or mathematical functions on operands such as variables, constants, and objects
Operators
Java divides the operators into the following groups:
- Arithmetic
- Unary
- Shorthand Assignment
- Relational/Comparison
- Logical/Conditional
- Bitwise
Are used to perform common mathematical operations
Arithmetic Operators
Are used to increasing or decreasing the value of an operand
Unary Arithmetic Operators
Adds 1 to the value of a variable
Increment Operator
Decreases 1 from a value of a variable.
Decrement Operator
Symbol for Pre-increment
++a
Symbol for Pre-decrement
–a