Java Flashcards

1
Q

What are the concepts of OOP, describe them all. What are the related Java concepts

A

Encapsulation - Isolate some logic from the outside world, maintain functionality through an internal implementation. For example, a you have a method that finds a value based on an id. There is a private instance variable that is a list, the method implementation searches the list. It is possible to change the implementation to use a hash map without breaking the API

Abstraction - See above

Inheritance - The ability to extend from another class, keeping the features/functionality from your parent but adding your own.

Polymorphism - Means many forms, refers to the idea that an object can be defined as a number of different things, a Square can be a Shape, which is itself an object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is method overriding. Compare and contrast with overloading.

A

Override - When a method in a subclass has the same name, same parameters or signature, and same return type(or sub-type) as a method in its super-class

Overload - When a method of the same name as another method within the class (or its hierarchy) has a “different” set of parameters (be they vary by type, number, or both). A method cannot overload another by simply returning a different type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

final, finally, finalize keywords

A

final:
- Marks a class as being unable to be extended
- Marks a method as being unable to be overridden
- Marks a variable as being unable to change. (must be initialized)

finally:
- Used in try/catch statements to execute some logic after the try/catch block regardless of its outcome.

finalize:
- A method you can define to perform cleanup on an object, which is invoked when the object is garbage collected. It is a method defined on java.lang.Object, non-static

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Describe some of the significant differences in Java versions

A

Java 0 - 7 Steadily added important features
- JDBC
- Swing
- Collections
- Web Start
- Generics (5)
- Enum
- for each
Java 8, Major release with LTS, many companies are still using
- Lambdas and general functional programming language support
- Better date/time api
Java 9
- Java Modules
- JShell

Java 11 (LTS)
- HTTP Client
- Licensing change (requires switching to OpenJDK for most)
Java 14
- Improved switch statements (with expressions)
Java 16
- Records (love)
Java 17 (LTS)
- Sealed classes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is Java, what is JRE, vs JVM vs JDK

A

Java is not compiled into a platform-specific machine; instead, it is compiled into platform-independent bytecode. This code is interpreted by the Virtual Machine on which the platform runs.

JDK - development kit which includes JRE, Java, compiler and some other tools for creating java applications

JRE - Is to execute a java program, this means JVM, and core classes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the JIT compiler

A

Just in time compiler, compiles to platform specific bytecode at runtime which speeds things up

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

String vs StringBuilder vs StringBuffer

A

String - Each string is stored in memory after initialized, every new string is “saved”

StringBuilder - Avoids the above. new StringBuilder(“hello”).append().toString();

StringBuffer - Same as above except it is thread safe (with a performance hit)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Give a brief overview of inner classes, how do they work and what is their visibility. What are they used and how do you use them.

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a vector

A

Basically an array list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Read from a file line by line

A

String file =”src/test/resources/fileTest.txt”;

 BufferedReader reader = new BufferedReader(new FileReader(file));
 String currentLine = reader.readLine();
 reader.close();
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Heap vs Stack memory

A

Stack memory is the amount of memory allocated to each individual program.

Heap memory - not assigned but willl be available for use by the Java code when it is required, which is generally during the program’s runtime.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is JPA and Hibernate, compare the 2.

A

JPA - Jakarta (or Java) Persistence API, is a standard for handling the persistence of java objects (essentially an ORM feature). Standards for determining how to map a java object into a persisted location (usually a database). Contains descriptors for how to handle data types, relationships, and CRUD operations. Developers interact with this using annotations.

Hibernate - A Java ORM solution which actually predates JPA. As a result, Hibernate can solve most of the problems as JPA specifies without using JPA at all. However, most now would use hibernate as a JPA implementation. That is useful since our code can comply with a widely accepted standard while using hibernate (a fully-fledged stable solution) as the underlying implementation. Hibernate is specific to relational databases, but that’s not necessarily true of JPA and there are implementation of JPA that communicate with NoSQL databases.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly