Java Flashcards
What is Java?
- A commonly used OOP language
- It is a complied language
Why use Java?
- Widely used
- Lots of documentation
- Great exception handling
- Lots of environments support Java
- Forwards compatible
Is Java 100% OOP?
No, primitives are not objects.
What is the JDK?
The Java Development Kit contains compiler and debugger tools to compile the Java Source Code. Also contains the JRE and JVM
What is the JRE?
The Java Runtime Environment provides an environment and in that environment the JVM runs the compiled byte code. Also contains the JVM and library
What is the JVM?
The Java Virtual Machine creates a layer of abstraction from the Java Code and the computer environment. It is used to convert java bytecode to machine readable code.
What is a State?
Properties of an object
What is a behaviour?
Actions that an object can take
What is an Object?
An object is an instantiation of a class
What is a class?
A class is the blueprints that provides the States and Behaviors its instantiated object will have.
What are the class members?
- Instance variables
- Methods
- Constructors
- Inner class
- static/instance blocks
What are the types of variables?
- Instance
- Local
- Static
What are the scopes of variables?
- Class–inside class
- Method–inside method
- Block–inside for or if statements
What are the Access Modifiers?
- public–globally accessible
- private–accessible only within that class
- protected–accessible only within that package and its sublclasses
- default–accessible only within that package
What are the Non-Access Modifiers?
- static
- final
- abstract
- synchronized
- volatile
- transient
What is the Static Modifier?
variable or function belongs to all instances of that class as it belongs to the type, not the actual objects themselves
What is the Final Modifer?
Define an entity that can only be assigned once. Once a final variable has been assigned, it cannot be changed.
What is the Abstract Modifier?
used for the purpose of extending.
What is the synchronized modifier?
used for threads. accessed by only one thread at a time
What is the Volatile Modifier?
Used for threads. lets JVM know that a thread accessing a variable must merge its own private copy with the master copy in memory.
What is the Transient Modifier?
used in serialization. field that is transient will not be sent at all and will appear as null on the other end
What is a Constructor?
A special method used to create an instance of a class
What are the types of Constructors?
- args
- no-args
- default
What are the four pillars of Object Oriented Programming?
- abstraction
- inheritance
- encapsulation
- polymorphism
What is abstraction?
it is focused on the concept of reusability which is achieved using generalization or specialization.
How do you achieve abstraction?
- abstract class
- frameworks
What is an Abstract class?
- a class that would denote a hierarchy between itself and the class extending it.
- can only extend one abstract class.
What is an Interface?
- an interface can be implemented many times
- all methods of an interface must be implemented
What is Polymorphism?
The concept in java that objects can have the same states and behaviors, and are interchangeable
How do you achieve Polymorphism?
- method overloading
- method overriding
What are the types of Polymorphism?
- Compile time polymorphism (static)
- Runtime polymorphism (dynamic)
What is inheritance?
The concept that classes can share states and behaviors through extension
How do you achieve inheritance?
extend a class
What is Encapsulation?
Its a technique used to control an object’s accessibility to its states
What is the hashcode?
It is an identifier for an object that has been converted to an integer
What is the Stack?
- refers to JavaStackMemory
- smaller than heap
What is the Heap?
-refers to the Java Heap Space, which allocates memory to Objects and JRE classes
What is the Finally Keyword?
- used in try/catch/finally block
- makes it execute no matter what, even if an exception is thrown
What is the Finalize Keyword?
-method used in garbage collection to invoke the JVM figures out that a particular instance should be garbage collector
What is an exception?
- Extends Throwable
- they are events in execution that deviate from the normal flow of execution.
What is throw?
method body to invoke an exception
What is throws?
method signature, used to declare an exception
What is the Garbage Collector?
a long running thread which gets rid of objects that no longer hold a reference in the heap to free up space
What is runtime?
when your compiled code is run when a user uses the application
What is compile time?
when the JVM compiles your java code into bytecode
What is a String?
- Immutable
- stored in string pool
- thread safe
What is a StringBuilder?
- mutable
- for strings that are changing rapidly
What is a StringBuffer?
- mutable
- synchronized
- slower
What is serialization?
is the process where java objects are converted to bytestreams