Java Flashcards
What is java?
Java is a programming language and computing platform. Java is secure and reliable. From laptops to datacenters, game consoles to scientific supercomputers, cell phones to the Internet,
Java is everywhere!
Why java
Object-oriented. Automatic memory management. Rich API. It’s portable. Easy to learn. It has simple syntax based on C. Java is FREE.
Supported by Oracle Corporation
What is the JVM
java virtual machine
allows java bytecode (.class files) to be executed on your machine (binary). Loads, verifies, and executes code.
The JVM is abstract in nature
What is the JRE
java runtime environment
JRE is [JVM + the set of necesary libraries]. Minimum requirement to run java code.
What is the JDK
Java development kit
is [JRE + development tools]. Dev tools include: the compiler + debugger + javadocs + etc.
The compiler turns source code (.java files) into bytecode (.class files).
What is a bit?
a binary value (0 or 1 aka ON or OFF)
What is a byte?
is 8 bits (256 different conbinations of 0s and 1s. 2^8)
What is a nibble?
is 4 bits (16 different combinations 0s and 1s. 2^4)
What are the naming conventions in java?
variable names: camel case. e.g. myFirstName,myLastName
class names (nouns): title case. e.g. Animal, UserStory, ButtonColors
interface names (adjectives): title case. e.g. Runnable, Comparable
method names (verbs): camel case. e.g. drawRectangle, run
package names: lowercase. e.g. java, lang, sql, util, etc
constants: uppercase. e.g. RED, YELLOW, MAX_PRIORITY, etc
What are the primitive datatypes in java?
● boolean - a true or false value (1 bit in size)
● byte - a smaller space efficient integer representation (1 byte in size)
● char - a single character value (2 bytes in size)
● int - a integer numeric value (4 bytes in size)
● double - a decimal numeric value (8 bytes in size)
● float - a floating point value. Holds big decimals with less precision (4 bytes in size)
● short - a smaller space efficient integer representation (2 bytes in size)
● long - a large integer representation (8 bytes in size)
What is flow control?
statements that break up the normal flow of execution by employing decision making, looping, and branching, enabling your program to conditionally execute particular blocks of code.
Types of flow control statements include: ● if, else if, and else blocks ● ternary statements ● switch cases ● while loops ● do while loops ● for loops ● enhanced for loops (aka for each loops) ● try, catch, and finally blocks
What does the keyword “break” do?
tells java to cease the logic of the current code block. Java will then begin processing the logic just after the code block’s ending curly brace.
may be used in if statements, while loops, etc.
What does the keyword “continue” do?
tells java to cease the logic of the current code block THEN go back to the top of the loop’s code block. Java will then begin processing the logic as if it has reached a new iteration of the loop.
What is short circuiting?
deals with && and || operators.
While computing a true/false condition, if the short circuiting operators determine that the result of the condition is apparent even without computing the rest of the statement then it will stop short and proceed with the answer is already knows.
For example, if the left side of && is
already false then it is impossible for the statement to be true; so java will not compute the right side.
Another example, if the left side of || is true then java will stop computing because the condition will be true regardless of the right side’s results.
What datatypes does a switch case allow?
Switch cases only allow the following datatypes in its condition declaration: ● int (and Integer, the wrapper class) ● short (and Short) ● byte (and Byte) ● char (and Character) ● String ● enum
What is an array?
an object which contains elements of a similar datatype Can only store fixed set of elements and is index based.
We can create arrays in two ways:
● int[] arrayOne = {15, 88, 99};
● String[] arrayTwo = new String[200];
each element starts at the datatypes default value,
btw.
We can access each element of an array using square brackets [ ]. If you attempt to access an element that doesn’t exist then you’ll get a
“ArrayIndexOutOfBounds” exception
2 What method do you call to find the size of an array?
You can find the size of an array (number of element) by using: myArray.length;
BUT “.length” is NOT a method; it’s a property of an array
What is a method?
A modularized block of code; created by putting a series of statements between two curly braces. This special block of code will be given a name so that it can be referred to later.
(collection of statements that perform some specific task and return the result to the caller.)
The method signature in java is: [any modifiers] [the return data type] [the method name] ( [the parameter list] ) { // my logic }
EX: static void myMethod() {
System.out.println(“yay!”);
}
What is a function vs a method?
A method is simply a function that is attached to an object.
It’s truly as simple as that. Java is almost entirely object oriented so it strictly uses methods, not functions.
What is method overloading
Overloading is when you have multiple methods with the same name, but different parameter lists.
There are three ways to change the parameter list:
● change the data types
● change the number of parameters
● change the order of the datatypes in the parameter list
This concept does not need inheritance to exist; it happens all within the same class.
What is a class?
A blueprint for an object. A class is abstract in nature, you can not have a physical instance of a class; it simply defines the structure of an object.
Think of a class like a recipe to create a food dish; it isn’t the food itself…just the instructions to create the food.