Chapter 1 Java Building Blocks Flashcards
Java Basics Working with Java Data Types
What is an object?
An object is a runtime instance of a class in memory.
What are the two primary elements in Java classes?
Methods and fields. Together these are called the members of the class.
[Blank] holds the state of the program.
Variables (Fields)
[Blank] operates on the state of the program.
Methods
Java calls a word with special meaning a [Blank].
Keyword
Public classes in Java means?
The class can be used by other classes.
A method is
an operation that can be called again.
Return type void means
that no value at all is returned.
Methods that require information be supplied to it from the calling method is called a [Blank]
parameter
The full declaration of a method is called [Blank]
method signature
What are the the three type of comments?
Single line comments: //
Multiple line comment:
/*
*
*/
Javadoc comment /** * * */
What is a main() method?
A Java program begins execution with its main() method. It is the gateway between the startup of a Java process, which is managed by the JVM (Java Virtual Machine).
The file must have what extension to be able to be compiled as Java code?
.java
The name of the file must also match the name of the class.
The compiler turns a .java file into what type of file?
.class
What is bytecode?
Bytecode is a class file which consists of instructions that the JVM knows how to execute.
What is method access modifier?
It declares the method’s level of exposure to potential callers in the program.
The keyword [Blank] binds a method to its class so it can be called by just the class name.
static
[Blank] is a fixed size list of items that are all the same type.
Arrays
Command line arguments are treated as [Blank] objects, even if they represent another data type.
String
You need to have [Blank] to compile because it includes a compiler.
JDK (Java Development Kit)
You need [Blank] to run the code.
JRE (Java Run-time Environment)
Java class runs on [Blank] and therefore runs on any machine with Java rather than just the machine or operating system they happened to have been compiled on.
JVM (Java Virtual Machine)
Java code is organized into folders called [Blank]
packages
What does import statement do?
Import statement tell Java which packages to look in for classes.
Wildcard (*) imports
all packages that matches classes in the package
What package is automatically imported?
java.lang
package contains the classes that are fundamental to the design of the Java programming language.
[Blank] keyword is needed to create an instance of a class.
new
[Blank] is a special type of method that creates a new object.
Constructor
Two key points to note about a constructor:
Name of constructor must match the name of the class.
There are no return type.
What is the purpose of a constructor.
Initialize fields.
Are you required to code a constructor?
No, the compiler will supply a “do nothing” default constructor for you.
Codes between braces are call a
code block
Instance initializers are
code blocks that appears outside a method.
What are the two type of data?
Primitive type
Reference type
What are the 8 primitive data type?
Byte Short Int Float Double Long Boolean Char
Boolean Type
True and False
Byte Type and Size
Integral Value and 8-bit
Short Type and Size
Integral Value and 16-bit
Int Type and Size
Integral Value and 32-bit
Long Type and Size
Integral Value and 64-bit
Float Type and Size
Floating Point Value and 32-bit
Double Type and Size
Floating Point Value and 64-bit
Char Type and Size
Unicode Value and 16-bit
Reference types refer to the [Blank]
Object (An instance of a class)
A reference “points” to an object by storing the [Blank] where the object is located/
memory address
A value can be assigned to the reference in which two way?
- A reference can be assigned to another object of the same type.
- A reference can be assigned to a new object using the new keyword.
Can a reference type be assigned to null?
Yes, it means it does not currently refer to an object.
Can a primitive type by assigned to null?
No, it will give you a compiler error.
Primitive type naming convention
lowercase type names
Classes naming convention
Class names begin with an uppercase letter followed by CamelCase. Don’t start any
identifiers with $. The compiler uses this symbol for some files.
A [Blank] is a name for a piece of memory that stores data.
variable
When you declare a variable, you need to
state the variable type along with giving it a name.
Can you declare and initialize a variable in the same statement?
Yes, as long as it is all the same type. You can also initialize any or all of those value inline.
3 rules of identifier names.
- The name must begin with a letter or the symbol $ or _.
- Subsequent characters may also be numbers.
- You cannot use the same name as a Java reserved word.
What is a reserved word?
A reserved word is a keyword that Java has reserved so that you are not allowed to use it.
Name some reserved words:
abstract assert boolean break byte case catch char class const* continue default do double else enum extends false final finally float for goto* if implements import instanceof int interface long native new null package private protected public return short static strictfp super switch synchronized this throw throws transient true try void volatile while
Method and variables naming convention:
Method and variables names begin with a lowercase letter followed by CamelCase.
Java supports which character set:
Unicode: which has more than 45,000 characters