The high level pattern for the RESTful URI is http(s)://myserver.com:8080/app-name/{version-no}/{domain}/{rest-reource-convetion} For example: http(s)://myserver.com:8080/accounting-services/1.0/forecasting/accounts to list … Read more ›...
The high level pattern for the RESTful URI is http(s)://myserver.com:8080/app-name/{version-no}/{domain}/{rest-reource-convetion} For example: http(s)://myserver.com:8080/accounting-services/1.0/forecasting/accounts to list … Read more ›...
Q1. What do you know about model 0, model 1 and model 2 MVC design patterns? A1. In the model 0 pattern, which is also known as the model-less pattern, business logic is embedded in the JSP pages. The model 0 pattern is fine for a very basic JSP page,...
Q1. What’s wrong with Servlets? What is a JSP? What is it used for? What do you know about model 0 (aka MVC0), model 1 (aka MVC1) and model 2 (aka MVC2) patterns? In “model 2” architecture, if you set a request attribute in your JSP, … Read more ›...
Q1. Why is it important to understand the difference between the “JVM memory model” and the computer “hardware memory model”? A1. 3 reasons why it is important to understand the JVM memory model and computer hardware memory model are: 1) JVM memory model and the physical hardware memory model architectures...
Q01. What is a category theory from a functional programming language perspective?
A01. The category theory is all about abstracting complexities in computations. OO is good for abstracting over Data, and FP is good for abstracting over behavior.
Composition
“f” and “g”
…
HashMap & HashSet are not only one of the frequently used data structures, but also one of the popular interview topics. Q1. How does a HashMap store data? A1. As key/value pairs. You can store and retrieve values with the keys. … Read more ›...
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
package com.read.file; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.stream.Stream; public class MyFileReader { public static void main(String[] args) { Path file = Paths.get("C:\\Users\\akumaras\\workspace\\test\\src\\com\\read\\file\\readme.txt"); try { //Java 8: Stream class Stream<String> lines = Files.lines( file, StandardCharsets.UTF_8 ); for( String line : (Iterable<String>) lines::iterator ) { System.out.println("read=" + line); } } catch (Exception e){ e.printStackTrace(); } } } |
Output:
|
1 2 |
read=A big brown fox read=jumped over the fence |
#1 double colon notation ::
The new double colon (::) operator that Java 8 has to convert a normal method into lambda expression. So,
Instead of:
|
1 |
list.forEach(n -> System.out.println(n)); |
You can do:
|
1 |
list.forEach(System.out::println); |
#2 Why is stream::iterator used?
…
Q01: How does Java 14+ improve on ubiquitous NullPointerException?
A01: Prior to Java 14, it is harder to find the root cause of the exception. Often you have to debug with break points to identify which variable is null. The JVM will print out only the method,
…
FP error handling – checked exceptions The code below breaks the flow of execution as the input “ABC” throws a checked exception – “NumberFormatException”.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
package com.fp.eg6; import java.util.stream.Stream; public class CheckedExceptionWithFPMain { public static void main(String[] args) { Stream.of("1", "ABC", "2") .map(Integer::parseInt) .forEach(System.out::println); // throws checked exception // java.lang.NumberFormatException // For "ABC" } } |
Outputs:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
1 Exception in thread "main" java.lang.NumberFormatException: For input string: "ABC" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.lang.Integer.parseInt(Integer.java:580) at java.lang.Integer.parseInt(Integer.java:615) at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948) at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151) at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174) at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418) at com.fp.eg6.CheckedExceptionWithFPMain.main(CheckedExceptionWithFPMain.java:11) |
What if you want to just mark all the inputs that throw a “NumberFormatException” … Read more ›...
Design principles interview questions & answers for Java developers so that you can expand your OOP skills to design robust Java apps Q25. What are the SOLID design principles? A25. SOLID is an abbreviation for 5 design principles. SRP (Single Responsibility Principle) If you have a class with calculation logic,...
Q1. What is HATEOAS? How does it provide state transition, scalability, and loose coupling? A1. HATEOAS (Hypermedia as the Engine of Application State) is considered the final level of REST. This means that each link is presumed to implement the standard REST verbs of GET, … Read more ›...
What is UTC? which stands for Coordinated Universal Time. The diagram below shows the standard time offsets of different countries. Some places observe daylight saving time (DST) during their respective summer periods. For example,
Los Angeles (i.e LA) UTC –
…
Q01. What do you understand by the terms functors, monads, and applicatives ? A01. Functors, Monads, and Applicatives are concepts or patterns that abstract complexities in computations, and are NOT interfaces or classes. You can think of them as container type classes like List<T>, Option<T>, … Read more ›...
I have a good news, I got job offer. I like to share with you from my bottom of my heart feeling thankful to you.