Podcast
Questions and Answers
What is the primary difference between passing by value and passing by reference in Java?
What is the primary difference between passing by value and passing by reference in Java?
- Passing by value creates a copy of the variable, while passing by reference allows direct modification of the original variable. (correct)
- Passing by value modifies the original variable, while passing by reference creates a copy.
- There is no difference; both methods achieve the same outcome.
- Passing by value is used for primitive types, while passing by reference is used for objects.
In Java, ==
compares the content of objects, while .equals()
compares the memory address.
In Java, ==
compares the content of objects, while .equals()
compares the memory address.
False (B)
Explain the concept of polymorphism in object-oriented programming.
Explain the concept of polymorphism in object-oriented programming.
Polymorphism allows objects of different classes to respond to the same method call in a class-specific way.
A ______ interface in Java contains only one abstract method.
A ______ interface in Java contains only one abstract method.
Match the access modifiers in Java with their visibility:
Match the access modifiers in Java with their visibility:
Which statement best describes the difference between an interface and an abstract class in Java?
Which statement best describes the difference between an interface and an abstract class in Java?
A HashTable
in Java allows null
keys and null
values.
A HashTable
in Java allows null
keys and null
values.
Explain the difference between StringBuilder
and StringBuffer
in Java.
Explain the difference between StringBuilder
and StringBuffer
in Java.
In Java, throw
is used to explicitly ______ an exception, while throws
is used in method signatures to indicate that a method might throw an exception.
In Java, throw
is used to explicitly ______ an exception, while throws
is used in method signatures to indicate that a method might throw an exception.
Match the following Java 8 features with their descriptions:
Match the following Java 8 features with their descriptions:
Which of the following is NOT a valid use case for JUnit?
Which of the following is NOT a valid use case for JUnit?
In the context of unit testing, 'mocking' refers to creating a real instance of a dependency for testing purposes.
In the context of unit testing, 'mocking' refers to creating a real instance of a dependency for testing purposes.
What is the primary difference between Comparable
and Comparator
in Java?
What is the primary difference between Comparable
and Comparator
in Java?
An ______ class cannot be instantiated directly, but it can be subclassed.
An ______ class cannot be instantiated directly, but it can be subclassed.
Match the SOLID principles with their descriptions:
Match the SOLID principles with their descriptions:
Which of the following best describes the difference between Overriding
and Overloading
in Java?
Which of the following best describes the difference between Overriding
and Overloading
in Java?
A deadlock occurs when two or more threads are blocked indefinitely, waiting for each other to release resources.
A deadlock occurs when two or more threads are blocked indefinitely, waiting for each other to release resources.
What is the purpose of the volatile
keyword in Java?
What is the purpose of the volatile
keyword in Java?
In Java, a ______ is a design pattern that ensures a class has only one instance and provides a global point of access to it
In Java, a ______ is a design pattern that ensures a class has only one instance and provides a global point of access to it
What could cause an OutOfMemoryError in Java?
What could cause an OutOfMemoryError in Java?
Flashcards
What is the final
keyword?
What is the final
keyword?
A keyword in Java that indicates that a variable, method, or class cannot be changed or overridden.
What is static in Java?
What is static in Java?
A variable, method, or class that belongs to the class itself rather than to any instance of the class.
What are Primitive Data Types in Java?
What are Primitive Data Types in Java?
byte, short, int, long, float, double, boolean, and char.
Passing by Value vs. Passing by Reference
Passing by Value vs. Passing by Reference
Signup and view all the flashcards
Difference between int
and Integer
Difference between int
and Integer
Signup and view all the flashcards
Difference between ArrayList
and LinkedList
Difference between ArrayList
and LinkedList
Signup and view all the flashcards
What is Java Heap Memory?
What is Java Heap Memory?
Signup and view all the flashcards
What is a memory leak?
What is a memory leak?
Signup and view all the flashcards
What is Garbage Collection in Java?
What is Garbage Collection in Java?
Signup and view all the flashcards
What is the String Pool?
What is the String Pool?
Signup and view all the flashcards
Difference Between .equals()
and ==
Difference Between .equals()
and ==
Signup and view all the flashcards
What is 'generic'?
What is 'generic'?
Signup and view all the flashcards
What is OOP?
What is OOP?
Signup and view all the flashcards
What is polymorphism?
What is polymorphism?
Signup and view all the flashcards
Overriding
Overriding
Signup and view all the flashcards
Overloading
Overloading
Signup and view all the flashcards
What are Access Modifiers?
What are Access Modifiers?
Signup and view all the flashcards
Interface vs. Abstract Class
Interface vs. Abstract Class
Signup and view all the flashcards
What is Serialization?
What is Serialization?
Signup and view all the flashcards
What is SerialVersionUID?
What is SerialVersionUID?
Signup and view all the flashcards
Study Notes
-
"final" is a keyword used to apply restrictions on a class, method, or variable.
-
A final class cannot be inherited.
-
A final method cannot be overridden.
-
A final variable's value cannot be changed after initialization.
-
A static field is a class-level variable shared among all instances of the class.
-
A static method belongs to the class rather than any specific instance.
-
A static class is a nested class that does not need an outer class instance.
-
Primitive data types in Java include boolean, byte, short, int, long, float, double, and char.
-
Passing by value creates a copy of the variable, while passing by reference passes the memory address.
-
Changes made to a parameter passed by reference affect the original variable.
-
'int' is a primitive data type, storing integer values while 'Integer' is a wrapper class for the primitive type int.
-
ArrayList is a dynamic array, while LinkedList is a doubly-linked list.
-
ArrayList provides fast element access, while LinkedList offers efficient insertion and deletion.
-
Java 8 has made improvements to memory management.
-
Java Heap memory is a part of memory allocated to JVM to store objects and JRE classes.
-
Memory leak occurs when objects are no longer used by the application but the garbage collector fails to release them.
-
Garbage Collection is the process of automatically managing memory by freeing up unused objects.
-
String Pool is a memory area in the Java heap where the JVM stores unique string literals.
-
"==" compares references of objects, while ".equals()" compares the content.
-
Generics allows a type or method to operate on objects of various types while ensuring type safety.
-
OOP is a programming paradigm based on "objects" that contain data and code: encapsulation, inheritance, and polymorphism.
-
Polymorphism is the ability of an object to take on many forms which is achieved through method overriding and overloading.
-
Overriding occurs when a subclass provides a specific implementation of a method already defined in its superclass.
-
Overloading is creating multiple methods with the same name but different parameters within the same class.
-
Access modifiers in Java control the visibility of class members: public, private, protected, and default (package-private).
-
An Interface is a contract that a class must adhere to, specifying methods the class must implement.
-
An abstract class cannot be instantiated and can have both abstract and concrete methods; interfaces cannot have concrete methods before Java 8.
-
HashMap implementation involves hashing keys to indices in an array and handling collisions using techniques like chaining.
-
HashTable does not allow null keys because it relies on the key's hash code, and calling hashCode() on a null value would result in a NullPointerException.
-
HashMap allows null keys, TreeMap stores key-value pairs in a sorted order, and HashTable is synchronized.
-
StringBuilder is mutable and not thread-safe, while StringBuffer is mutable and thread-safe.
-
Handling exceptions involves using try-catch blocks to gracefully manage errors.
-
"throw" keyword is used to explicitly throw an exception, while "throws" is used in the method signature to declare exceptions.
-
NullPointerException is a runtime exception thrown when attempting to use a null reference.
-
Optional classes can avoid NullPointerException by providing a container object which may or may not contain a non-null value.
-
Java 8 introduced features like lambda expressions, streams, default methods in interfaces, and the Optional class.
-
Functional Interfaces enable functional programming with single abstract method.
-
Streams provide a way to process collections of objects in a declarative way.
-
JUnit is a testing framework, involving creating test methods with annotations like @Test.
-
Mocking involves creating mock objects to isolate and test components in isolation.
-
Stubbing involves replacing real dependencies with controlled substitutes.
-
TestNG is an alternative testing framework that offers features like parallel test execution and parameterized testing.
-
JSON is a lightweight data-interchange format used for data transmission between a server and a web application.
-
JDBC is an API for connecting to databases and executing queries.
-
SOAP is a protocol for exchanging structured information in web services.
-
Comparable is implemented by a class to define a natural ordering of its objects, while Comparator is a separate class used for custom ordering.
-
Common Git commands include init, add, commit, push, pull, and branch.
-
Abstract Class vs Interface usage depends on code re-use needs; abstract classes can have state and behavior.
-
Java 8 features include lambda expressions, streams, functional interfaces, default and static methods in interfaces
-
Comparators facilitate defining custom object comparison rules.
-
Exceptions can be handled using try-catch blocks.
-
Java's four principles are Abstraction, Encapsulation, Inheritance, and Polymorphism.
-
Java Generics allows type abstraction, promoting code reusability and type safety.
-
Serialization converts an object to a byte stream for storage or transmission.
-
HashMap differs from HashTable as it allows null keys/values and is not synchronized.
-
Hashcode should be implemented because it is used to identify objects quickly by retrieving them from the map
-
Checked exceptions are caught at compile time, while unchecked exceptions occur at runtime.
-
Lambda expressions are anonymous functions.
-
Functional interfaces have a single abstract method.
-
Error is irrecoverable, Exception is recoverable.
-
Hash collision occurs when two different keys produce the same hash value; resolved by chaining or open addressing.
-
Singleton ensures only one instance exists.
-
Future represents result of asynchronous computation.
-
Common design patterns include Singleton, Factory, Observer, and Decorator.
-
Custom exceptions are created for specific error handling scenarios.
-
OutOfMemoryError arises from insufficient memory; prevent using optimization and memory management.
-
Types of exceptions include checked, unchecked, and errors; OutOfMemory vs StackOverflow represent memory issues.
-
Method references are shorthand for lambda expressions involving existing methods.
-
Stream API enables functional-style operations on collections.
-
Functional programming is a declarative style using pure functions.
-
Optional handles nullable values.
-
HashMap uses a hash table internally with collision handling.
-
New Java 8 features include lambda expressions, streams, and functional interfaces.
-
Deep copy creates new independent object; shallow copy shares references.
-
Mutlithreading enables concurrent execution using threads.
-
Method references provide shorthand for referring to methods.
-
Handle errors using try-catch blocks.
-
Stream API provides high-level abstraction for processing collections.
-
Deal with large data using Kafka, Stored Procedures, Executor Service, and Cache.
-
LinkedList operations have differing time complexities.
-
The JVM compiles and runs Java code.
-
Intermediate operations are lazily executed; terminal operations trigger execution.
-
Java 8 introduced Callable and Future for asynchronous computations.
-
Multiple threads are created and managed using the Thread class and Runnable interface.
-
Serializable marks a class as capable of being serialized.
-
SerialVersionUID is used during deserialization to verify that the sender and receiver of a serialized object have loaded compatible classes.
-
Collections can be traversed using iterators, for-each loops, and streams; redisTemplate is used for caching.
-
Immutable objects cannot be modified after creation, some examples include String, Integer, and LocalDate.
-
Internal Implementation of HashMap: Buckets, hashcodes.
-
HashMap has O(1) time complexity for average; O(n) for worst case if there is a very bad hash collision
-
Volatile ensures visibility of changes across threads.
-
Threads communicate through shared memory or message passing.
-
HashMap store key-value mappings; collision occurs if two keys have same has.
-
Thread Join delays the execution of current thread until specified thread is dead.
-
Java 8 Advantages: Streams, Functional Interface, Ease of code.
-
Default methods provide flexibility for interfaces; static methods belong to the interface.
-
Asynchronized is not a word, however, synchronization ensures thread safety.
-
CompletableFuture allows asynchronous computations with callbacks.
-
Composition represents "has-a" relationship; association is a general relationship.
-
ArrayList is array-backed; LinkedList uses nodes.
-
ConcurrentHashMap provides thread-safe operations through segmentation.
-
Concurrent modification exceptions occur when modifying a collection during iteration which can be handled by using concurrent collections
-
Make classes immutable by preventing changing its internal state.
-
Producer-consumer problem manages communication between threads
-
Deadlock arises when threads wait indefinitely for resources which can be avoided through careful design and resource allocation.
-
Volatile ensures visibility of variable changes across threads.
-
Volatile ensure latest result using memory barriers.
-
Employee objects can be sorted using comparators.
-
The front-end communicates with the back-end through APIs.
-
Heap stores objects; stack stores method calls and local variables
-
HashSet does not maintain order and uses hashing; TreeSet maintains sorted order using a tree.
-
TreeSet sorts objects using the Comparable or Comparator interfaces.
-
Factory design pattern creates objects without specifying concrete classes.
-
Observer pattern defines dependency between objects to notify observers.
-
serialVersionUID compatibility issues can occur if the serialVersionUID is not defined, which causes InvalidClassException.
-
ConcurrentHashMap prevents concurrency issues from multi-threading.
-
Memory leaks are caused by unreleased objects; detectable through profiling.
-
Optional and null checks avoid null pointer exceptions.
-
Map transforms values; FlatMap transforms and flattens collection: stream of collections into one stream
-
TreeMap vs. HashMap: Sorted vs. unsorted.
-
sleep() pauses thread execution for a specified time; wait() releases the lock and waits for notification.
-
HashMap vs. LinkedHashMap: Unordered vs. insertion-ordered.
-
PreparedStatement helps prevent SQL injection attacks.
-
String is immutable for security, caching, and thread safety.
-
Encapsulation hides internal implementation details. Polymorphism allows objects to take multiple forms.
-
JDK is the development kit; JVM is the virtual machine that runs Java bytecode.
-
Reactive programming handles asynchronous data streams.
-
Security protocols ensure secure communication.
-
Object lifecycle: creation, usage, destruction.
-
Deadlock occurs when two or more threads are blocked.
-
Abstraction shows essential details; encapsulation hides internal details.
-
Inheritance: one class acquires properties of another class; types in java: single, multilevel, hierarchical
-
Class loader loads class files into JVM.
-
SPA is single page application, hibernate is a framework for mapping object relations.
-
Java Collections Framework provides interfaces and classes for storing and manipulating data.
-
Garbage Collection reclaims unused memory automatically.
-
Lambda function enables functional programming.
-
Singleton Pattern ensures only one instance of class is created.
-
Mechanism of HashMap involves hashing keys and collision handling.
-
Spring Boot simplifies Spring application setup.
-
Auto configuration of spring boot projects is achieved with annotations
-
Dependency injection reduces coupling, with three methods
-
Components encapsulate functionality; annotations provide metadata.
-
Handler and controller manage requests.
-
@Conditional annotation defines conditions for bean creation.
-
Optimize projects through profiling and performance tuning, scalability is maintained by Load Balancing
-
Single Responsibility Principle dictates class should have one reason to change.
-
APIs define communication interfaces.
-
Optimize high traffic using caching, load balancing, and efficient algorithms.
-
Database choice depends on application needs
-
Lambda architecture designed for processing large amounts of data.
-
Java 17/Java 8 different features and benefits.
-
Java 8 supports lambda functions and streams.
-
Threadpool reduces overhead by reusing threads which monitors signal requests.
-
If a threadpool is at max, requests can become blocked until threads are free.
-
Optimizing multithreaded app involves balancing the load.
-
Blocking/non-blocking calls affect thread availability.
-
SOLID principles guide software design
-
Final/Finally/Finalize serve different purposes related to variables, exception handling, and garbage collection.
-
Overloading/overriding: Method signatures and behaviors.
-
Static methods belong to the class and how they are used differs
-
Interface default/static methods: usage and implications.
-
Default method implementations in an interface; implementations may override.
-
Stream API: Stream processing which may involve parallel computing.
-
Stream API (parallel stream), interface changes, absolute classes with null point exception, collections changes
-
Parallel vs stream API is used for Async calls in multi-threaded contexts.
-
Performance differences between 2 is determined by testing
-
Thread downsides: Deadlocks or Race Conditions
-
Lambda and SAM (single abstract method) interfaces relationship; default allows additional methods.
-
Default methods in interfaces introduce flexibility.
-
Abstraction in OOP means simplification
-
Liskov Substitution Principle = objects substituted must not break
-
4 OOP Principles: Abstraction, Encapsulation, Inheritance, Polymorphism = use of Interfaces to manage.
-
Marker interfaces: Serializable, Cloneable.
-
Volatile ensures visibility of variable changes across threads.
-
Collections: ArrayList, employee check, sort by last name.
-
Primitive data types in Java include boolean, byte, short, int, long, float, double, and char.
-
Polymorphism: Method overriding and overloading and explains concept.
-
Thread lifecycle: new, runnable, running, blocked/waiting, terminated.
-
StringBuilder is mutable and faster, StringBuffer is thread-safe and slower.
-
Functional programming: Lambda/pure functions.
-
Cyclic dependency in Spring: How to fix it with design.
-
Lazy initialization: Object creation on demand.
-
Transitive dependency: A depends on B depends on C
-
Spring Boot: auto-configuration and stand alone
-
Inject beans: @Autowired
-
Type preference: Specificity wins.
-
Immutable class creation: no setter methods.
-
Private constructors and static factory methods instantiate classes.
-
Have you worked with Java 8? Streams and Lambdas are useful.
-
New Java 11 features: Local variable type inference.
-
Lambda expressions: Anonymous functions
-
Functional interfaces: Single abstract method.
-
Functional interfaces allow concrete methods
-
Functional interfaces, such as Supplier, Predicate are Useful.
-
Own functional interface: Can be achieved as needed.
-
thenApply(): Processes sequentially; thenApplyAsync(): Processes concurrently.
-
supplyAsync(): Executes task asynchronously; CompletableFuture: Represents result.
-
Some design patterns include Singleton, Factory, Observer.
-
Multiple beans with same type instantiation may occur occasionally.
-
Polymorphism: Multiple forms.
-
Multi-inheritance is disallowed in Java due to ambiguity
-
Two interfaces with method name create namespace collisions
-
Collections include: TreeMap, HashMap.
-
HashMap vs. ConcurrentHashMap: Unsafe vs. thread safe
-
Hashtable vs. ConcurrentHashMap: Legacy vs. concurrent.
-
Main features of Spring Boot: Auto-configuration, embedded servers.
-
Previous usage of older Spring.
-
YAML config advantages: more readable
-
Basic annotations include @Component, @Service, @Repository, @Controller
-
JPA advantage over JDBC: Abstraction eliminates boilerplate.
-
Types of Cascade: CascadeType.PERSIST, REMOVE
-
save() and saveAndFlush() persistence ops occur immediately.
-
Internal Java architecture: How JVM manages and processes.
-
Abstraction benefits: Simplifies complexity.
-
New Java 8 features are Streams, Lambdas.
-
String is immutable for thread safety.
-
Java versions used
-
Lambda function experience: useful, and improves code.
-
The Java collections framework includes interfaces and classes.
-
Difference between ArrayList and LinkedList: array vs. linked.
-
HashMap's internal mechanism: Buckets and hashcodes
-
Lambda is: expression based function
-
Multi threading creates multi threads.
-
Singleton Pattern in Java: How to set up.
-
Can you name a few design patterns? and reasons for use cases.
-
Asynchronized programming in Java utilizes multi threads.
-
Design principles guide classes written
-
How do you handle synchronisation? Java provides mechanisms for thread synchronization.
-
Version control tools track code changes and what version you use.
-
JWT tokens are generated by your app to guarantee authentication.
-
Race conditions result from non synchronized code blocks.
-
Java code tested with JUnit.
-
2 ways to Mockito: Mock or Spy objects
-
Junit vs Mockito Scenarios
-
Deploy across different environments: tools used during packaging etc.
-
Different versions of same library in Maven: manage dependency versions
-
MySQL secured with secure credential management.
-
Authentication vs. Authorization
-
Load balancers distribute across nodes.
-
API gateway required to distribute and manage node instances
-
Low balancers balance load and make systems stable.
-
Distributive micro services divide applications across modules and microservices.
-
Service discovery roles in distributive service modules.
-
Circuit breaker design patterns ensure system stability
-
system.out.Println is: logging or displays data to the console.
-
Abstraction conception hides implementation details
-
Abstraction improves: code design
-
Abstraction hides code
-
Encapsulation allows data/behavior bundling
-
Check and unchecked exception catches errors at compile time
-
Given an array of size n-1 distinct nums between 1-n inclusive, find missing num
-
How would you check if a number is a power of 3 with bit manipulation.
-
Stacks can be made from scratch with Arrays as underlying dat structure
-
Data structures can be used with Names, Dates and retrieved by ID
-
calculate the max step of a binary tree? Use graph theory and tree transversal (DFS, BFS)
-
common value common value in two hash sets? Iterate and store the data, map, set, hashset.
-
Saga pattern manages distributed transactions.
-
API Gateways route requests.
-
Databases are used in design and development.
-
Please talk about normalization, 1NF, 2NF, 3NF and use cases.
-
OLAP and OLTP differ in purpose and data structure.
-
Complex SQL debugged
-
Talk about CRUD services = Controller
-
Handle CRUD ops in project by building REST API.
-
First design the APIs then use backend and frontend
-
Routing directs traffic.
-
REST controllers handle REST API requests.
-
Path variables capture dynamic URL parts.
-
Service discovery locates service instances.
-
WebLogic can replace Tomcat.
-
Constructor injection emphasizes immutability.
-
Implement security with Authentication and Authorization.
-
Docker containerizes applications.
-
MVC paradigm separates concerns.
-
URL action: DispatcherServlet
-
Persistence handled through JDBC and Hibernate.
-
Singleton guarantees a single instance.
-
Integration/Unit/Functional Tests must be utilized.
-
Mockito used for mocking.
-
Autoconfiguration and actuator features in Spring Boot.
-
Circuit breakers fail or block requests.
-
Boot differs from frameworks, it is more standalone.
-
Autowired components in Springboot
-
Log as singleton, otherwise issues may occur.
-
Spring boot features for new projects.
-
REST APIs should have lifecycles documented
-
Boot uses Dependency Injections
-
Spring Annotations - Controllers
-
Actuator: monitor or configure apps.
-
Cyclic dependency requires refactoring.
-
Lazy init: object on demand.
-
Dependency injection improves structure
-
ControllerAdvice handles exceptions globally.
-
Microservices architecture promotes independent services.
-
Web stack selected after assessing options.
-
Main features of Spring Boot: Autoconfiguration.
-
Set configuration properties.
-
Disable specific config.
-
Actuator monitors
-
Spring Boot more self-contained.
-
Transaction Management used in API design
-
Frameworks: simplify development.
-
Methods: autowiring and constructors
-
Components have different dependencies
-
Handler and controller dispatch requests
-
Optimize through profiling
-
Maintain scalability through architecture
-
Webflux handles web traffic.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.