OOP Java Vezba 02
OOP Java Vezba 02
OOP Java Vezba 02
com
Java Fundamentals
4-3: Data Types and Operators
Practice Activities
Objectives:
• Use primitive data types in Java code
Vocabulary:
Identify the vocabulary word for each definition below.
The group of Java data types that do not use the keyword new when declared or
initialized. Primitive Data Types store the value in the same place in memory as the
variable name.
The smallest java primitive type (1 byte) that can hold an integer value.
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their
respective owners.
2
This Java primitive data type (4 bytes) can hold integer values.
This Java primitive data type (8 bytes) is the largest primitive that can hold a decimal
value.
This Java primitive data type (4 bytes) can be initialized with a decimal number preceding
letter f. Example: float x = 3.5f;
Can be any number, text, or other information that represents a value; used to initialize a
primitive type.
A Java statement when a variable is defined but not necessarily assigned a value.
Example: int x;
This word describes the mathematical precedence that a variable has in a Java program.
A java primitive data type (2 bytes) that can hold single character values. Example: “a”,
“#”, or “X”
Used to describe the block of code where a variable exists in a program. A block of code
is denoted by {}.
The process of explicitly modifying one data type to become a different data type.
The equals sign “=” used in a Java statement to assign a value to a variable.
The process of modifying one data type to become a different data type, this may be
implicit or explicit.
A Java primitive data type (2 bytes) that holds integer numbers within a shorter range
than an int.
A one-bit java primitive type that can hold the value true or false.
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their
respective owners.
3
2. Write the following math formulas in Java. You will need to use methods from the Math class as well as nesting of
methods and parentheses to force the order of operations to correctly calculate the answer. Assume that all the
variables in the formulas have already been declared and initialized.
√𝑥𝑥 5 −6
a.𝑎𝑎 =
4
b. 𝑏𝑏 = 𝑥𝑥 𝑦𝑦 − 6 𝑥𝑥
𝑧𝑧
c. 𝑐𝑐 = 4𝑐𝑐𝑐𝑐𝑐𝑐( ) − 𝑠𝑠𝑠𝑠𝑠𝑠𝑥𝑥 2
5
d. 𝑑𝑑 = 𝑥𝑥 4 − �6𝑥𝑥 − 𝑦𝑦 3
1
e. 𝑒𝑒 = 1
𝑦𝑦−
𝑥𝑥−2𝑦𝑦
3. A bus holds 45 people. The school will only use a bus if they can fill it completely. The rest of the people will ride in
vans. Write a program that will take in the number of people that are signed up to go on a field trip. Have the
program print the number of busses necessary and then total number of people that will need to ride in vans.
4. Write true or false on the blanks in the program below to show the value of the boolean variable true_false as the
program executes.
int i=5;
int j=6;
boolean true_false;
true_false=(j<5); ________
true_false=(j>3); ________
true_false=(j<i); ________
true_false=(i<5); ________
true_false=(j<=5); ________
true_false=(6<6); ________
true_false=(i!=j); ________
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their
respective owners.
4
5. Explain why each of the declarations in the second list are wrong.
6. Explain why each of the declarations in the second list do not follow conventions for variable names.
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their
respective owners.