Core Java Concepts
12 December 2024 09:28
Difference between abstract
class and interface
What are default and static Default Methods: Allow interfaces to have method implem
methods in interfaces, and Static Methods are class methods Can be called without
why were they introduced? variables and other static methods.
static Static Variables: it's a class variable
Static Methods are class methods Can be called without
variables and other static methods.
Static Blocks runs once when the class is loaded
Static Nested Classes
What are method references Method references (::) are shortcuts to call methods using t
and how are they used? They make code cleaner and more readable
What are the main features Java 8 introduced several key features:
introduced in Java 8? • Lambda Expressions: Enables functional programmin
• Functional Interfaces: Interfaces with a single abstrac
• Streams API: For processing collections in a functiona
• Default and Static Methods: Add methods to interfac
• Optional: A container for optional values to avoid nul
• New Date/Time API: Better date and time manageme
• Executor Service
What is a lambda expression in A lambda expression is a concise way to represent an anon
Java 8, and why is it useful? It’s useful for writing short, clean code, especially in functio
Syntax: (parameters) -> expression
mentations
t creating an instance of the class. They can only access static
t creating an instance of the class. They can only access static
the ::(double colon) operator
ng.
ct method (e.g., Runnable).
al style.
ces without breaking implementations.
ll checks.
ent.
nymous function.
onal interfaces
• Optional: A container for optional values to avoid nul
• New Date/Time API: Better date and time manageme
• Executor Service
What is a lambda expression in A lambda expression is a concise way to represent an anon
Java 8, and why is it useful? It’s useful for writing short, clean code, especially in functio
Syntax: (parameters) -> expression
What is a functional interface, A functional interface is an interface with exactly one ab
and can you give an example? 1. Single Abstract Method (SAM):
Explain the Streams API in Java The Streams API is used to process collections in a function
8 reducing.
What are the Streams Terminal Operation (produce a result and end the pipeline)
function's types ? Non Terminal Operation (They are lazy no computation is p
distinct() sorted() map() filter()
Explain the difference between • map: Transforms each element of the stream into exactly
map and flatMap in the Example: Converting a list of strings to their lengths.
Streams API • flatMap: Transforms each element into zero, one, or mul
the results into a single stream.
Example: Converting a list of sentences into a flat list of w
Optional Class It's a container object which may or may not cont
NullPointerExceptions.
Reactive Programming Java reactive programming it's a programming par
multiple tasks at the same time (concurrent) and c
completed in a specific order (asynchronous) witho
What is code refactoring, and Code refactoring means improving code structure and read
why is it important? maintain, reduces technical debt, and improves performanc
ll checks.
ent.
nymous function.
onal interfaces
bstract method, used in functional programming.
nal style. It allows operations like filtering, mapping, and
) findFirst() count() reduce() forEach() collect()
performed until a terminal operation is invoked) skip()
y one output element. It’s a one-to-one mapping.
ltiple elements (a one-to-many mapping) and then flattens
words.
tain a non-null value. Helping to avoid
radigm that allows system or a program to manage
can perform tasks that may not need to be
out wasting resources or time.
dability without changing its behavior. It makes code easier to
ce.