Java Building Blocks Flashcards
class
A description of an object. A class in Java is defined in a source file with the .java extension and compiled into a file with the .class extension.
object
A runtime instance of a class in memory
members of a class
methods and fields
Method Signature
The full declaration of a method
/* */ vs. /** */
The first is a regular multiline comment, the second is a special Javadoc comment
When you have two classes defined in the same java file, how many can be public?
1
Java Virtual Machine (JVM)
Runs Java class files.
main() method declaration
public static void main(String[] args)
How to compile and run a program called Zoo.java
javac Zoo.java
java Zoo
bytecode
Compiled Java code. Bytecode appears in files with the .class extension.
access modifier
Defines what other code can refer to the code. Choices are private,
protected, public, and default (no modifier.)
static
Binds a method or field to its class so it can be called by just the class name, as in, for example, Zoo.main(). Java doesn't need to create an object to call the main() method Makes a variable shared across all instances of this class.
What type does java read in arguments as by default?
String
package
A grouping of classes, interfaces, enumerations, and annotated types.
What is the package that is automatically imported?
java.lang
default package
An unnamed package used when no package statement is present in the code. This is a special unnamed package that you should use only for throwaway code. In real life, always name your packages to avoid naming conflicts and to allow others to reuse your code.
JAR file
Like a zip file of mainly Java class files.
What return type does a constructor have?
None! Not even void
Instance Initializers
Code blocks (between braces { }) outside of methods
Code Block
Code between { }
When creating a new object, when does the constructor run?
After all fields and instance initializer blocks have run
Two types of data
Primitive types
and
Reference types
byte type
8-bit integral value (whole number)