Java Unit 1 Flashcards
These rules specify the basic vocabulary of the language and how programs can be constructed using things like loops, branches, and subroutines.
Syntax
A set of rules that determine the meaning of a program written in a language.
Semantics
Java programs are compiled into what?
Byte code!
What is a subroutine call statement?
A subroutine call statement is a predefined set of routines for a subroutine to complete.
Example: System.out.println is a subroutine.
In order to define a program, a class must include a subroutine named?
main
public static void main(String[] args) {
statements
}
Why do you have to type “public” in the first line of main()?
Using “public” means that the routine can be called from outside of the program.
A subroutine can’t exist by itself. What does it HAVE to be a part of?
A class
What is a package?
A group of classes.
To execute a program, you only need the compiled “ “ file, not the source code.
class
When defining a variable, capitalizing every word except the first is referred to as what?
Camel case
These names consist of several simple names separated by periods.
Compound names, also called qualified names.
Example: System.out.println
An “ “ represents anything that refers to or computes a data value.
expression
Name all of the primitive types. Hint: there are 8
- byte - 16 bits
- short
- int - 32 bits
- long - 64 bits
- float
- double
- char
- boolean
What kind of numbers do float and double types hold?
real numbers
What range of values can a byte type hold?
Anywhere from -128 to 127 which equals up to 256 integers.
What range of values can a short type hold?
From -32,768 to 32,767 (16 bits)
How many bytes of memory are float data types represented by?
Four bytes (chomp, chomp, chomp, chomp)
How many bytes of memory does the char type occupy?
Two bytes (chomp, chomp)
A char character is stored as a “” bit integer code number.
16
A data value is stored in the computer as a sequence of what?
bits
In a program, you represent constant values as “”.
literals (I literally did not know that)
What is the escape character for a carriage return?
‘\r’
What is the escape character for a linefeed?
‘\n’
How can you express a number in an exponential form?
By using ‘e’
Example: ‘y = 1.3e12’
This means that 1.3 will be raised to the power of 12.
Any numeric literal that contains a decimal point or exponential is a literal of type “ “.
double
To make a literal of type float, you have to append what?
An ‘f’ or ‘F’ to the end of the float.
Example: ‘x = 1.2F;’
In Java, a numeric literal that begins with a “” is interpreted as an octal number.
0 - zero
Binary literals start with “” or “” and contain only the digits 0 and 1
0b or 0B
A “” literal consists of \u followed by four hexadecimal digits.
Unicode (not to be confused with a Unicorn)
A variable can be used in a program only if it has been?
declared
What is the difference between the subroutine call System.out.print and the subroutine call System.out.println?
System.out.println adds a linefeed at the end while System.out.print does not.
A “” provides a subroutine with information it needs to perform its task.
parameter
Literals, variables, and function calls are considered “” expressions
simple
How can you get Java to evaluate the expression you want over order or precedence?
By using parenthesis.
“(A + B) * C”
Can you multiply a char character by a char character?
Yes! Char characters are Unicode which have a numerical value.
The == operator checks whether two objects are stored in the same “ “, rather than whether they contain the same value.
memory location
What does the following boolean expression do?
boolean test = true;
test = ! test;
Assigns a false value to the variable test. This is the boolean operator “not”
The operators && and || are said to be “ “ versions of the boolean operators.
short-circuited
What is this assignment called? “B = (short)A”
type cast