Java Basics Flashcards
Java Object
A runtime instance of a class in memory
Class’s elements
Fields & methods
How many public classes a file can have?
- Each file can contain only one public class
2. The file name must match the class name, including case, and have a .java extension.
What is the main method structure?
public static void main(String [] args)
public static void main(String args [])
public static void main(String… args)
public static final void main(String [] args)
package
A grouping of classes, interfaces, enumerations, and annotated types.
What is the package that is automatically imported?
java.lang
What are imports needed for?
Imports are needed to be able to reference an external class.
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
What are wildcards used for?
Wildcards (*) are used to import all the classes from the a package. Importing all the classes in a package vs just the class that is going to be used does not slow down the program. Listing each of the classes makes the code easy to read. Using the wildcard can shorten the import list. Only one (at the end) is permited in an import.
Imports precedence explicit vs wildcard
Explicit import takes precedence over any wildcards.
package compilation errors
package error on runtime only;
import at compile time.
class structure
package. imports. class declaration.
bytecode
Compiled Java code. Bytecode appears in files with the .class extension.
What is the purpose of a constructor?
The purpose of the constructor is to initialize fields, although you can put any code in there.
Constructor return type
It has no return type.