Java Flashcards
The Java Development Kit contains what?
The Java Interpreter, The Java Compiler, and also the Java Virtual Machine
What is the Java Virtual Machine (JVM)
We are installing an operating system as a virtual machine that is dedicated to interpreting Java bytecode
Java bytecode is generated using the java compiler (javac) in the Java Development Kit (JDK). The JDK includes the Java Runtime Environment (JRE) which contains our JVM and allows us to run our Java programs.
What are .class and .jar files?
We need the JDK and we will compile java code into .class or .jar files. After compiling, we can run the bytecode with tools that are included in the JDK
What are some features about Java that are appealing?
1) Strong and Static Typing
2) Compiled Language
3) Object Oriented
4) Widely Used
5) Ecosystem
6) Java’s API
What is dynamic vs static?
These refer to when we assign types to variables: Languages with static tying assign a type to declared variables at compile time and set aside the right amount of memory that for that variable, while those with dynamic typing assign types only when the variable declaration code runs during execution and change the memory allocated for the variable as needed - this comes at the cost of program speed while it reorganizes things.
What are some dynamic and statically typed languages?
Java, C, Swift are statically typed languages. Javascript, Python, and Ruby are dynamically typed
What does it mean to be a compiled language?
It goes through analysis and optimization before it is run. The compiler can find repetitive code that you failed to optimize and do this for us, resulting in a faster program that we might otherwise have.
What does javac do in the terminal?
It compiles our code into bytecode and holds it in a file with a .class extension. Then when we call java and the file then it goes through.
What must be exactly the same as your class?
File name must be exactly the same as your class name
What is the main method?
Defines the entry point for an executable Java file. It is required for any file that is intended to be run from the command line.
Every application begins with a class definition
A class can contain multiple methods (which should be enclosed between the class opening and closing curly brace tag).
Explain public static void main
The entry point for an executable Java file. Three modifiers for the main method:
public: This is known as an access modifier. Any public method we write is accessible from any other class or method in our project
static: means that method belongs to and is called from the class itself rather than from an instance of the class.
void: the main() method does not return anything.
Why do we declare our types with variables?
This is to help with speed and safety. Speed, because all variables of the same type require the same amount of memory, and by declaring the type at initialization, Java is able to allocated only the proper amount. It helps with safethy, in that if we try to assign a vvalue of the wrong type to a variable, we get an error
What is the difference in syntax for primitive types and object types?
primitive types are lowercase, while object types are capitalized.
Why is it important to know the range of values that our data types can hold?
For type casting 1 - byte 2 - short, char 4 - int, float 8 - long, double NA - boolean
What is explicit cassting
Explicit casting is when we declare the type that we want to convert to in our source code.
What is implicit casting?
Implicit casting is the opposite, casting from a smaller data type to a larger
Explain importing
Java programs are heavily dependent on importing code that already has been created. It is uncommon to have Java programs that are completely standalone without any imports. Although reusing given classes and methods is common, you should always be checking the documentation for best practices and deprecation.
Explain Strings
Strings represent a sequence of characters. Strings, like any other object, belong to a class. INstances of the String class are immutable, so once you create a String, it cannot be modified
Methods are…
just functions that are attached to an object. Each method will have a code body and a method declaration, which includes the access level, return type, name, and parameter variables
RETURN MUST ALWAYS BE A CLASS, PRIMITIVE, OR VOID
What is overloading?
We can call two methods the same name. They could have different parameters
Describes arrays in Java?
Arrays in Java are a fixed-size sequential collection of elements of the same tyoe with a zero-based index. To use an array, e first need to declare it, initiliizar and add elements or values to it.
NOTE: In Java an array has a fixed size (after initialization), meangint that you canmot add or remove items from an array. In the example above, we declared that this arrray would contain five items. You cannot decrease or increase the number of elements in this array after initialization.