Java 8 Interview Questions Preparation Course
2.9 (7 ratings)
Instead of using a simple lifetime average, Udemy calculates a course's star rating by considering a number of different factors such as the number of ratings, the age of ratings, and the likelihood of fraudulent ratings.
311 students enrolled
Wishlisted Wishlist

Please confirm that you want to add Java 8 Interview Questions Preparation Course to your Wishlist.

Add to Wishlist

Java 8 Interview Questions Preparation Course

Learn Top 50 Interview Questions on Java 8. Get Success in your Interview.
2.9 (7 ratings)
Instead of using a simple lifetime average, Udemy calculates a course's star rating by considering a number of different factors such as the number of ratings, the age of ratings, and the likelihood of fraudulent ratings.
311 students enrolled
Last updated 8/2017
English
Curiosity Sale
Current price: $10 Original price: $100 Discount: 90% off
30-Day Money-Back Guarantee
Includes:
  • 2 hours on-demand video
  • 2 Articles
  • Full lifetime access
  • Access on mobile and TV
  • Certificate of Completion
What Will I Learn?
  • Learn important concepts of Java 8
  • Understand Java 8 features
  • Answer interview questions on Java 8
  • Demand higher salary or promotion based on the knowledge gained
View Curriculum
Requirements
  • Some Software Development Experience
  • Familiar with basic Java
Description

Java 8 is one of the major releases from Java with features like Streams, Lambdas etc. A lot of companies are looking for software developers proficient in Java 8 features.

This course contains basic to expert level Java 8 interview questions that an interviewer asks. Each question is accompanied with an answer so that you can prepare for job interview in short time. 

We have compiled this course after attending dozens of technical interviews in top-notch companies like- Google, Netflix, Amazon etc.

Often, these questions and concepts are used in our daily programming work. But these are most helpful when an Interviewer is trying to test your deep knowledge of Java 8 features.

What is the biggest benefit of this course to me?

Finally, the biggest benefit of this course is that you will be able to demand higher salary in your next job interview.

It is good to learn Java 8 for theoretical benefits. But if you do not know how to handle interview questions on Java 8, you can not convert your Java 8 knowledge into higher salary.

What are the topics covered in this course?

We cover a wide range of topics in this course. We have questions on Java 8 best practices, Security, Pact, Bulkhead Design Pattern etc.

How will this course help me?

By attending this course, you do not have to spend time searching the Internet for Java 8 interview questions. We have already compiled the list of the most popular and the latest Java 8 Interview questions. 

Are there answers in this course?

Yes, in this course each question is followed by an answer. So you can save time in interview preparation.

What is the best way of viewing this course?

You have to just watch the course from beginning to end. Once you go through all the videos, try to answer the questions in your own words. Also mark the questions that you could not answer by yourself. Then, in second pass go through only the difficult questions. After going through this course 2-3 times, you will be well prepared to face a technical interview in Java 8 topic.

What is the level of questions in this course?

This course contains questions that are good for a Fresher to an Architect level. The difficulty level of question varies in the course from a Fresher to an Experienced professional.

What are the sample questions covered in this course?

Sample questions covered in this course are as follows:

  1. What are the new features released in Java 8?
  2. What are the main benefits of new features introduced in Java 8?
  3. What is a Lambda expression in Java 8?
  4. What are the three main parts of a Lambda expression in Java?
  5. What is the data type of a Lambda expression?
  6. What is the meaning of following lambda expression?
  7. Why did Oracle release a new version of Java like Java 8?
  8. What are the advantages of a lambda expression?
  9. What is a Functional interface in Java 8?
  10. What is a Single Abstract Method (SAM) interface in Java 8?
  11. How can we define a Functional interface in Java 8?
  12. Why do we need Functional interface in Java?
  13. Is it mandatory to use @FunctionalInterface annotation to define a Functional interface in Java 8?
  14. What are the differences between Collection and Stream API in Java 8?
  15. What are the main uses of Stream API in Java 8?
  16. What are the differences between Intermediate and Terminal Operations in Java 8 Streams?
  17. What is a Spliterator in Java 8?
  18. What are the differences between Iterator and Spliterator in Java 8?
  19. What is Type Inference in Java 8?
  20. Does Java 7 support Type Inference?
  21. How does Internal Iteration work in Java 8?
  22. What are the main differences between Internal and External Iterator?
  23. What are the main advantages of Internal Iterator over External Iterator in Java 8?
  24. What are the applications in which we should use Internal Iteration?
  25. What is the main disadvantage of Internal Iteration over External Iteration?
  26. Can we provide implementation of a method in a Java Interface?
  27. What is a Default Method in an Interface?
  28. Why do we need Default method in a Java 8 Interface?
  29. What is the purpose of a Static method in an Interface in Java 8?
  30. What are the core ideas behind the Date/Time API of Java 8?
  31. What are the advantages of new Date and Time API in Java 8 over old Date API?
  32. What are the main differences between legacy Date/Time API in Java and Date/Time API of Java 8?
  33. How can we get duration between two dates or time in Java 8?
  34. What is the new method family introduced in Java 8 for processing of Arrays on multi core machines?
  35. How does Java 8 solve Diamond problem of Multiple Inheritance?
  36. What are the differences between Predicate, Supplier and Consumer in Java 8?
  37. Is it possible to have default method definition in an interface without marking it with default keyword?
  38. Can we create a class that implements two Interfaces with default methods of same name and signature?
  39. How Java 8 supports Multiple Inheritance?
  40. Can we access a static method of an interface by using reference of the interface?
  41. How can you get the name of Parameter in Java by using reflection?
  42. What is Optional in Java 8?
  43. What are the uses of Optional?
  44. Which method in Optional provides the fallback mechanism in case of null value?
  45. How can we get current time by using Date/Time API of Java 8?
  46. Is it possible to define a static method in an Interface?
  47. How can we analyze the dependencies in Java classes and packages?
  48. What are the new JVM arguments introduced by Java 8?
  49. What are the popular annotations introduced in Java 8?
  50. What is a StringJoiner in Java 8?
  51. What is the type of a Lambda expression in Java 8?
  52. What is the target type of a lambda expression ?
  53. What are the main differences between an interface with default method and an abstract class in Java 8?
Who is the target audience?
  • Software Engineer, Sr. Software Engineer, Member Technical Staff, Expert
  • DevOps Engineer, Operations Engineer
  • Software Architect, Development Manager, Director
  • Anyone who wants to learn Java 8 features
Students Who Viewed This Course Also Viewed
Curriculum For This Course
41 Lectures
01:51:30
+
Why should you learn Java 8?
2 Lectures 03:32

Disclaimer
00:38
+
Java 8 Interview Questions Part 1
5 Lectures 13:12

Q.    What are the new features released in Java 8?

The new features released in Java 8 are:

  • I.         Lambda Expression
  • II.         Stream API
  • III.         Date and Time API
  • IV.         Functional Interface
  • V.         Interface Default and Static Methods
  • VI.         Optional
  • VII.         Base64 Encoding and Decoding
  • VIII.         Nashorn JavaScript Engine
  • IX.         Collections API Enhancements
  • X.         Concurrency Enhancements
  • XI.         Fork/Join Framework Enhancements
  • XII.         Spliterator
  • XIII.         Internal Iteration
  • XIV.         Type Annotations and Repeatable Annotations
  • XV.         Method Parameter Reflection
  • XVI.         JVM Parameter Changes


Preview 02:45

Q.    What are the main benefits of new features introduced in Java 8?

The main benefits of Java 8 features are:

  • I.         Support for functional programming by Lambda and Streams
  • II.         Ease of high volume data processing by Streams
  • III.         Ease of use by getting Parameter names through Reflection
  • IV.         Reusable code with enhanced Collection APIs
  • V.         Smart exception handling with Optional
  • VI.         Control on JVM with new Parameters
  • VII.         Enhanced encryption support with Base 64
  • VIII.         Faster execution with Nashorn JavaScript engine support


What are the main benefits of new features introduced in Java 8?
03:01

Q.   What is a Lambda expression in Java 8?

Lambda expression is an anonymous function. It is like a method that does not need any access modifiers, name or return value declaration. It accepts a set of input parameters and returns result.

Lambda expression can be passed as a parameter in a method. So we can treat code in Lambda expression as data. This piece of code can be passed to other objects and methods.


What is a Lambda expression in Java 8?
02:24


Q.    What are the three main parts of a Lambda expression in Java?

Three main parts of a Lambda expression are:

  • I.         Parameter list: A Lambda expression can have zero or more parameters. Parameter list is optional to Lambda.
  • II.         Lambda arrow operator: “->” is known as Lambda arrow operator. It separates the list of parameters and the body of Lambda.
  • III.         Lambda expression body: The piece of code that we want to execute is written in Lambda expression body.
What are the three main parts of a Lambda expression in Java?
02:34

Q.    What is the data type of a Lambda expression?

A Lambda expression fulfills the purpose of passing code as data.

The data type of a Lambda expression is a Functional interface.

In most of the cases this is java.lang.Runnable interface.


Q.   What is the meaning of following lambda expression?

( e -> System.out.println( e ) );

This Lambda expression takes a parameter e and prints it via System.out.


What is the data type of a Lambda expression?
02:28
+
Java 8 Interview Questions Part 2
5 Lectures 16:37

Q.    Why did Oracle release a new version of Java like Java 8?

The main theme of Java 8 is support for functional programming. With increase in Database size and growth of multi-code CPU servers, there is need for Java to support such large-scale systems.

With new features of Java 8, it is possible to create functional programs to interact efficiently with Big Data systems. Support for Streams is very helpful in this regard.

Lambda expressions are very useful for cloud computing where we can pass code as data and run the same code on multiple servers.

Optional is a best practice that is borrowed from Google Guava library for handling the exceptional cases. This has made programs more robust with support for edge cases.

Preview 03:24

Q.    What are the advantages of a lambda expression?

We can pass a lambda expression as an object to a method. This reduces the overhead involved in passing an anonymous class.

We can also pass a method as a parameter to another method using lambda expressions.

What are the advantages of a lambda expression?
02:47

Q.    What is a Functional interface in Java 8?

A Functional interface in Java is an interface that has exactly one abstract method.

It can have default methods with implementation. A default method is not abstract.

In Java 8, java.lang.Runnable and java.util.concurrent.Callable are two very popular Functional interfaces. 


Q.   What is a Single Abstract Method (SAM) interface in Java 8?

A Functional interface is also known as Single Abstract Method Interface, since it has exactly one abstract method.


Q.   How can we define a Functional interface in Java 8?

To define a Functional interface in Java 8, we can create an Interface with exactly one abstract method.

Another way is to mark an Interface with annotation @FunctionalInterface. Even with the annotation we have to follow the rule of exactly one abstract method.

The only exception to this rule is that if we override java.lang.Object class’s method as an abstract method, then it does not count as an abstract method.


What is a Functional interface in Java 8?
03:01

Q.    Why do we need Functional interface in Java?

Functional Interfaces are mainly used in Lambda expressions, Method reference and constructor references.

In functional programming, code can be treated as data. For this purpose Lambda expressions are introduced. They can be used to pass a block of code to another method or object.

Functional Interface serves as a data type for Lambda expressions. Since a Functional interface contains only one abstract method, the implementation of that method becomes the code that gets passed as an argument to another method. 


Q.   Is it mandatory to use @FunctionalInterface annotation to define a Functional interface in Java 8?

No, it is not mandatory to mark a Functional interface with @FunctionalInterface annotation.

Java does not impose this rule.

But, if we mark an interface with @FunctionalInterface annotation then Java Compiler will give us error in case we define more than one abstract method inside that interface.

Why do we need Functional interface in Java?
03:15

Q.    What are the differences between Collection and Stream API in Java 8?

Main differences between Collection and Stream API in Java 8 are:

  • I.         Version: Collection API is in use since Java 1.2. Stream API is recent addition to Java in version 8.
  • II.         Usage: Collection API is used for storing data in different kinds of data structures. Stream API is used for computation of data on a large set of Objects.
  • III.         Finite: With Collection API we can store a finite number of elements in a data structure. With Stream API, we can handle streams of data that can contain infinite number of elements.
  • IV.         Eager vs. Lazy: Collection API constructs objects in an eager manner. Stream API creates objects in a lazy manner.
  • V.         Multiple consumption: Most of the Collection APIs support iteration and consumption of elements multiple times. With Stream API we can consume or iterate elements only once.
What are the differences between Collection and Stream API in Java 8?
04:10
+
Java 8 Interview Questions Part 3
5 Lectures 17:01

Q.    What are the main uses of Stream API in Java 8?

Main uses of Stream API in Java 8 are:

  • I.         It helps in using data in a declarative way. We can make use of Database functions like Max, Min etc., without running a full iteration.
  • II.         It makes good use of multi-core architectures without worrying about multi-threading code.
  • III.         We can create a pipeline of data operations with Java Stream that can run in a sequence or in parallel.
  • IV.         It provides support for group by, order by etc. operations.
  • V.         It supports writing for code in Functional programming style.
  • VI.         It provides parallel processing of data. 
What are the main uses of Stream API in Java 8?
03:18


Q.    What are the differences between Intermediate and Terminal Operations in Java 8 Streams?

Main differences between Intermediate and Terminal Stream operations are as follows:

  • I.         Evaluation: Intermediate operations are not evaluated until we chain it with a Terminal Operation of Stream. Terminal Operations can be independently evaluated.
  • II.         Output: The output of Intermediate Operations is another Stream. The output of Terminal Operations is not a Stream.
  • III.         Lazy: Intermediate Operations are evaluated in lazy manner.  Terminal Operations are evaluated in eager manner.
  • IV.         Chaining: We can chain multiple Intermediate Operations in a Stream. Terminal Operations cannot be chained multiple times.
  • V.         Multiple: There can be multiple Intermediate operations in a Stream operation. There can be only one Terminal operation in Stream processing statement.
Preview 03:33

Q.   What is a Spliterator in Java 8?

A Spliterator is a special type of Iterator to traverse and partition the elements of a source in Java. A source can be a collection, an IO channel or a generator function.

A Spliterator may traverse elements individually or sequentially in bulk. 


Q.   What are the differences between Iterator and Spliterator in Java 8?

Main differences between Iterator and Spliterator are as follows:

  • I.         Spliterator can be used with Streams in Java 8. Where as,  Iterator is just used with Collection.
  • II.         Spliterator uses Internal Iteration to iterate Streams. Iterator uses External Iteration to iterate Collections.
  • III.         Spliterator can iterate Streams in Parallel as well as Sequential manner. Iterator only iterates in Sequential manner.
  • IV.         Spliterator can traverse elements individually as well as in bulk. Iterator only iterates elements individually. 
What is a Spliterator in Java 8?
02:26

Q.    What is Type Inference in Java 8?

A Java compiler can see each method’s invocation and it declaration to determine what are type arguments required for invocation.

By Type Inference, Java can determine the types of the arguments as well as the type of the result being returned.

Type inference algorithm also tries to find the most specific type that can work with all types of arguments. 

Q.   Does Java 7 support Type Inference?

Yes, Java 7 supports Type Inference. In Java 8, Oracle has enhanced the Type Inference concept. Now it can be used to define Lambda expressions, functions and Method references.


What is Type Inference in Java 8?
03:15

Q.    How does Internal Iteration work in Java 8?

In an Iterator, the fundamental question is that which party controls the iteration. Is it Iterator or the Collection on which iterator runs.

When a Collection controls the iterator, then it is called External Iteration. When the Iterator controls the iteration then it is called Internal Iteration.

In case of Internal Iteration, the client hands over an operation to Iterator and the Iterator applies the operation to all the elements in aggregate.

Internal Iteration is easier to implement, since the Iterator does not have to store the state of the collection. 


Q.   What are the main differences between Internal and External Iterator?

Main differences between Internal and External Iterator are as follows:

  • I.         An Internal Iterator controls the iteration itself. In an External Iterator collection controls the iteration.
  • II.         Internal Iterator can iterate elements in individually as well as in
  • III.         Bulk (like forEach). External iterator iterates element one by one.
  • IV.         Internal Iterator does not have to iterate elements only sequentially. External Iterator always iterates sequentially.
  • V.         Internal Iterator supports declarative programming style that goes well with functional programming. External Iterator follows imperative style OOPS programming.
  • VI.         Some people consider Internal Iterator code more readable than that of External Iterator.


How does Internal Iteration work in Java 8?
04:29
+
Java 8 Interview Questions Part 4
5 Lectures 14:23


Q.    What are the main advantages of Internal Iterator over External Iterator in Java 8?

Some of the main advantages of Internal Iterator are:

  • I.         Internal Iterator is based on Functional programming, therefore it can work on declarative style code.
  • II.         There is no need to sequentially iterate elements in Internal Iterator.
  • III.         Code is more readable and concise in Internal Iterator.
  • IV.         Internal Iterator supports concurrency and parallel processing.


Q.   What are the applications in which we should use Internal Iteration?

We need Internal Iterator in applications that require high performance, parallel processing, fast iteration and bulk operations support.

Also in Internal Iteration applications, we do not have much control over iteration. The other features like parallel processing etc. become more important.


Q.   What is the main disadvantage of Internal Iteration over External Iteration?

Internal Iteration has many advantages over External Iteration. But it has one big disadvantage. Since Java API is responsible for iterating in Internal iterator, developer does not get any control over iteration. 

What are the main advantages of Internal Iterator over External Iterator?
02:42


Q.    Can we provide implementation of a method in a Java Interface?

Before Java 8, it was not allowed to provide implementation of a method in an Interface.

Java 8 has introduced the flexibility of providing implementation of a method in an interface. There are two options for that:

  • I.         Default Method: We can give default implementation of a method.
  • II.         Static Method: We can create a static method in an interface and provide implementation. 


Q.   What is a Default Method in an Interface?

In Java 8, we can provide implementation of a method in an Interface and mark this method with Default keyword.

In this way, this implementation of the method becomes default behavior for any class implementing the interface.

Can we provide implementation of a method in a Java Interface?
02:32

Q.    Why do we need Default method in a Java 8 Interface?

Default methods in an Interface provide backward compatibility feature in Java 8.

Let say there is an interface Car that is implemented by BMW, Chevrolet and Toyota classes. Now a Car needs to add capability for flying. It will require change in Car interface. Some of the car classes that do not have flying capability may fail. Therefore a Default Implementation of flying methods is added in Car interface so that cars with no flying capability can continue to implement the original Car interface.

Why do we need Default method in a Java 8 Interface?
03:38


Q.    What is the purpose of a Static method in an Interface in Java 8?

A Static method in an Interface is utility or helper method. This is not an object level instance method. Some of the uses of Static method in an Interface are:

  • I.         Single Class: There is no need to create a separate Utils class for storing utility or helper methods. We can keep these methods in same interface.
  • II.         Encapsulation: With Static methods, complete behavior of a Class is encapsulated in same class. There is no need to maintain multiple classes.
  • III.         Extension: It is easier to extend a Class/API. If we extend a collection ArrayList, we get all the methods. We need not extend Collections class also.
What is the purpose of a Static method in an Interface in Java 8?
02:55

Q.    What are the core ideas behind the Date/Time API of Java 8?

There are three core ideas behind the Date/Time API of Java 8:

  • I.         Immutable-value classes: The new API avoids thread-safety and concurrency issues by ensuring that all the core classes are immutable and represent well-defined values.
  • II.         Domain-driven design: The new API is modeled on precise domain with classes that represent different use cases for Date and Time. The emphasis on domain-driven design offers benefits like clarity and understandability.
  • IV.         Separation of chronologies: The new API allows people to work with different calendar systems. It supports the needs of users in different areas of the world likes Japan or Thailand that don’t follow ISO-8601.
What are the core ideas behind the Date/Time API of Java 8?
02:36
+
Java 8 Interview Questions Part 5
5 Lectures 11:52

Q.    What are the advantages of new Date and Time API in Java 8 over old Date API?

Some of the advantages of Java 8 Date Time API over existing Date API are:

Concurrency: Existing Date Time classes (such as java.util.Date and SimpleDateFormatter) are not thread-safe. This does not work well in concurrent applications. In new Date Time API, developer does not have to deal with concurrency issues while writing date-handling code.

Better Design: Date/Time classes prior to Java 8 have poor API design. For example, years in java.util.Date start at 1900, months start at 1, and days start at 0. It is not very intuitive. Java 8 Date Time API handles it very well.

No need for 3rd Party Libraries: With the popularity of third-party Date/Time libraries like Joda Time, Java has to make its native Date/Time API comparable. Now we can use the Java API instead of using 3rd party libraries.


What are the advantages of new Date and Time API in Java 8 over old Date API?
02:40


Q.    What are the main differences between legacy Date/Time API in Java and Date/Time API of Java 8?

Main difference between legacy Date/Time API and Java 8 Date/Time API are:

  • I.         Old API is not Thread safe. Java 8 API is Thread safe.
  • II.         Old API has many mutable objects. New Java 8 API is based on Immutable objects.
  • III.         Performance of old API is not good. New Java 8 Date/Time API gives better performance.
  • IV.         Old API is less readable and maintainable. New Java 8 API is very well designed and is more readable.
  • V.         Old API has month values from 0 to 11. New API has months from 1 to 12.
What are the main differences between legacy Date/Time API and Java 8 Date API?
02:20


Q.    How can we get duration between two dates or time in Java 8?

In Java8, we have a new class Duration that provides the utility of computing duration between two dates.

We can call the static method Duration.between(date1, date2) to get the time period in hours, mins, days etc. between date1 and date2.

How can we get duration between two dates or time in Java 8?
02:09

Q.    What is the new method family introduced in Java 8 for processing of Arrays on multi core machines?

Java 8 has enhanced the Arrays class with methods that can run efficiently on multi core machines.

These methods start with keyword parallel.

Egg. Arrays.parallelSetAll(), Arrays.parallelSort() etc.

This parallel set of methods provides parallel processing of Arrays that can run Java code very fast on a multi core machine.


What is the new method family introduced in Java 8 for processing of Arrays?
02:16

Q.    How does Java 8 solve Diamond problem of Multiple Inheritance?

In Multiple Inheritance if a class extends more than one classes with two different implementation of same method then it causes Diamond problem.

Consider following example to see problem and solution for Diamond problem in Java 8:

public interface BaseInterface{  

  default void display() { //code goes here }

}

public interface BaseOne extends BaseInterface { }

public interface BaseTwo extends BaseInterface { }

public class ChildClass implements BaseOne, BaseTwo { }

In the above code, class ChildClass gives compile time error. Java Compiler cannot decide which display method should it invoke in ChildClass.

To solve this problem, Java SE 8 has given the following remedy:

public interface A{  

  default void display() { //code goes here }

}

public interface B extends A{ }

public interface C extends A{ }

public class D implements B,C{

  default void display() {

    B.super.display();      

  }

}

public interface BaseInterface{  

  default void display() { //code goes here }

}

public interface BaseOne extends BaseInterface { }

public interface BaseTwo extends BaseInterface { }

public class ChildClass implements BaseOne, BaseTwo {

            default void display(){

            BaseOne.super.display();

}

 }

The method invocation at BaseOne.super.display(); solves the Diamond problem as it resolves the confusion for compiler.



How does Java 8 solve Diamond problem of Multiple Inheritance?
02:27
+
Java 8 Interview Questions Part 6
5 Lectures 14:52


Q.    What are the differences between Predicate, Supplier and Consumer in Java 8?

The subtle difference between Predicate, Supplier and Consumer in Java 8 is as follows:

  1. Predicate is an anonymous function that accepts one argument and returns a result.
  2. Supplier is an anonymous function that accepts no argument and returns a result.
  3. Consumer is an anonymous function that accepts one argument and returns no result.


What are the differences between Predicate, Supplier and Consumer in Java 8?
02:26

Q.    Is it possible to have default method definition in an interface without marking it with default keyword?

No, we have to always mark a default method in interface with default keyword.

If we create a method with implementation in an interface, but do not mark it as default, then we will get compile time error.

Q.   Can we create a class that implements two Interfaces with default methods of same name and signature?

No, it is not allowed to create a class that implements interfaces with same name default methods.

It will give us compile time error for duplicate default methods.

Is it possible to have default method definition in an interface?
02:21

Q.   How Java 8 supports Multiple Inheritance?

In Multiple Inheritance a class can inherit behavior from more than one parent classes.

Prior to Java 8,  a class can implement multiple interfaces but extend only one class.

In Java 8, we can have method implementation within an interface. So an interface behaves like an Abstract class.

Now if we implement more than one interface with method implementation in a class, it means we are inheriting behavior from multiple abstract classes. That is how we get Multiple Inheritance in Java 8.


Q.   In case we create a class that extends a base class and implements an interface. If both base class and interface have a default method with same name and arguments, then which definition will be picked by JVM?

In such a scenario, JVM will pick the definition in base class.


Q.   If we create same method and define it in a class , in its parent class and in an interface implemented by the class, then definition will be invoked if we access it using the reference of Interface and the object of class?

In all the cases, method defined in the class will be invoked.


Q.   Can we access a static method of an interface by using reference of the interface?

No, a static method of interface has to be invoked by using the name of the interface.



How Java 8 supports Multiple Inheritance?
04:10

Q.    How can you get the name of Parameter in Java by using reflection?

Java 8 has introduced a method Parameter.getName() to get the name of a parameter by using reflection.

Before using this feature, we need to turn on this feature in Java compiler.

To turn on this feature, just run javac with –parameters argument.

To verify the availability of this feature, we can use Parameter. isNamePresent() method.


How can you get the name of Parameter in Java by using reflection?
02:14

Q.    What is Optional in Java 8?

Optional is a container object that may have a null or non-null value. If it has a value then isPresent() method returns true.

It a value is present, we can call get() method to get the value. Else we will get nothing.

It is very useful in handling data that has null values.


Q.   What are the uses of Optional?

Some of the uses of Optional in Java are:

  • We can use Optional to avoid NullPointerException in an application.
  • Optional performs Null check at compile time, so we do not get run time exception for a null value.
  • Optional reduces the codebase pollution by removing unnecessary null checks.
  • Optional can also be used to handle default case for data when a value is null. 


Q.   Which method in Optional provides the fallback mechanism in case of null value?

In case, an Optional has null value, we can use orElseGet() method as fallback mechanism. If we implement orElseGet() method, it will be invoked when the value of Optional is null. 

What is Optional in Java 8?
03:41
+
Java 8 Interview Questions Part 7
5 Lectures 11:31

Q.    How can we get current time by using Date/Time API of Java 8?

In Java 8 we can use Clock class to get the current time. Instead of using old method System.currentTimeMillis(), we can create a Clock object and call millis() method to get the current time in milliseconds.

We can also call instant() method on Clock object to get the current time in a readable format.


How can we get current time by using Date/Time API of Java 8?
02:23

Q.    Is it possible to define a static method in an Interface?

Yes, from Java 8, an Interface can also has a static method.

Is it possible to define a static method in an Interface?
02:07

Q.    How can we analyze the dependencies in Java classes and packages?

Java 8 comes with a new command line tool jdeps that can help in analyzing the package-level and class-level dependencies.

We can pass a jar file name or a class name as an argument to this tool. It will list all the dependencies of that jar or class.

How can we analyze the dependencies in Java classes and packages?
02:20

Q.    What are the new JVM arguments introduced by Java 8?

In Java 8, PermGen space of ClassLoader is removed.  It has been replaced with MetaSpace.

Now we can set the initial and maximum size of MetaSpace.

The JVM options -XX:PermSize and –XX:MaxPermSize are replaced by -XX:MetaSpaceSize and -XX:MaxMetaspaceSize respectively in Java 8.

What are the new JVM arguments introduced by Java 8?
02:27

Q.    What are the popular annotations introduced in Java 8?

Some of the popular annotations introduced in Java 8 are:

@FunctionalInterface: This annotation is used to mark an interface as Functional Interface. As mentioned earlier, A FunctionalInterface can be used for lambda expressions.

@Repeatable: This annotation is used for marking another annotation. It indicates that the marked annotation can be applied multiple times on a type.


What are the popular annotations introduced in Java 8?
02:14
+
Java 8 Interview Questions Part 8
4 Lectures 08:36

Q.    What is a StringJoiner in Java 8?

StringJoiner is a new class in Java 8 that can be used to create a String. It can construct a sequence of characters separated by a delimiter. It can also optionally add a prefix and suffix to this sequence. We can use this sequence to get a String.

E.g.

The String "[One:Two:Three]" may be constructed as follows:

 StringJoiner sj = new StringJoiner(":", "[", "]");

 sj.add("One").add("Two").add("Three");

 String desiredString = sj.toString();


What is a StringJoiner in Java 8?
02:20


Q.    What is the type of a Lambda expression in Java 8?

The type of a lambda expression depends on the context it is being used.

A lambda is like a method reference. It does not have a type of its own. Generally, a Lambda is an instance of a Functional Interface. 


Q.   What is the target type of a lambda expression ?

The target type of a lambda expression represents a type to which the expression can be converted.

The target type for a lambda expression is a functional interface.

The lambda expression must have same parameter type as the parameter in the function of the interface. It must also return a type compatible with the return type of function.

What is the type of a Lambda expression in Java 8?
02:20


Q.    What are the main differences between an interface with default method and an abstract class in Java 8?

An interface with a default method appears same as an Abstract class in Java. But there are subtle differences between two.

  • I.         Instance variable: An interface cannot have instance variables. An abstract class can have instance variables.
  • II.         Constructor: An interface cannot have a constructor. An abstract class can have constructor.
  • III.         Concrete Method: An interface cannot have concrete methods other than default method. An abstract class is allowed to define concrete methods with implementation.
  • IV.         Lambda: An interface with exactly one default method can be used for lambda expression. An abstract class cannot be used for lambda expression.
Main differences between an interface with default method and an abstract class.
02:34

Bonus Lecture: What next?
01:22
About the Instructor
KnowledgePowerhouse !
3.7 Average rating
183 Reviews
3,539 Students
18 Courses
Top most career courses! 18 Courses, 3300+ students!

I am a Software Architect with expertise in Cloud Computing, Amazon Web Services, Microservices, Data Science, Hadoop, Spark, Machine Learning and Java architecture. Learning, using and sharing Technology is my passion.

I have built systems that are running enterprise software of companies across the world. I have gained a lot of knowledge by working hands-on on these large scale software projects.

With these courses I aim to share my knowledge with the future Software Engineers, Developers, Leaders and Architects . 

I am sure the knowledge in these courses can give you extra power to win in life.

All the best!!