200+ Java Fullstack developer questions

  1. Write Fibonacci series programming and explain logic
  2. how auto wiring works in spring
  3. write a program for dependency injection
  4. how security is implemented in your project.
  5. difference between filter and map in java streams.
  6. Explain about your current project.
  7. How to read the file and display total count of each word.
  8. How angular Makes calls to spring boot
  9. What is spring profile
  10. There is a list with emp objects with duplicate name, age attributes. How to retrieve uniques names.
  11. What Technologies used in last project.
  12. Abstract class and encapsulation.
  13. What is HashMap? how it works.
  14. what is inter thread communication
  15. what ArrayList ? extends object and ArrayList? super object means
  16. what is splice and slice
  17. difference between == and ===
  18. Write a Java 8 program to get the sum of all numbers present in a list?
  19. what FlatMap?
  20. write a prog ..how to sort emp obj in java8
  21. Given the list of employees, find the employee with name “R”.
  22. Angular Routing process
  23. Difference Between constructor vs ngOnInit in Angular
  24. how to find which datatype is created in JavaScript
  25. what is id in CSS
  26. how to create a singleton object
  27. what is static method, static block and static class
  28. what will happen if we add final to a method
  29. what is @path and path param, path variable
  30. what is multi catch block
  31. what is subquery and when we use it
  32. how to use service in angular
  33. difference between @Input and @Output in angular
  34. what is event emitter
  35. what is @beanpropertyrowmapper
  36. Handle cross horizon resource sharing-angular, how can u candle hash code, equal
  37. sql query, highest salary- department wise
  38. Routing in Angular
  39. import and export in ngModule
  40. what is ngModule
  41. directives and use of them in angular
  42. routes in angular
  43. what is children attribute in routes in angular
  44. Hibernate OneToMany and ManyToOneMapping example
  45. How to return a single user if userId passed or list of users if userId not passed in JPA
  46. Micro services communication
  47. Autorization and authentication process in current project
  48. String reverse program
  49. Spring JPA Example
  50. Factory design pattern
  51. Singleton Design pattern and real time usage and implementation
  52. How to prevent singleton object from clone?
  53. Synchronous and asynchronous requests, how to consume angular http request and services
  54. Springcloud config
  55. publishing a service in spring cloud
  56. diff b\w rest and soap
  57. what is the new in the current java version compared with previous versions?
  58. What is the lambda expression?
  59. What is a functional interface and it’s example?
  60. How many ways to create a thread and it’s life cycle?
  61. What are streams in java?
  62. What is the difference between a hashset and concurrenthashset?
  63. Difference between hashmap and concurrenthashmap
  64. What is LinkedHashMap
  65. What is a static method in java?
  66. How the static class locking works?
  67. what is a singleton design pattern and how do you create it?
  68. What are directives in angular?
  69. What are pipes in angular?
  70. How do components communicate with each other and data transfer among them?
  71. What is DDL and DML??
  72. What is the difference between Truncate and Delete?
  73. What is the difference between function and procedure?
  74. What is immutable class
  75. Method to find missing number in a Array list with value from 0-100. (number 7 and are missing)
  76. find the number of integer appear in a array list having duplicates
  77. Explain Quick sort
  78. Serialization
  79. what is executer framework and cachethreadpool
  80. How hashMap works internally
  81. Spring & Microservice
  82. What is microservice and its architecture
  83. How to handle situation if one of microservice fails
  84. What is API gateway
  85. What is client side load balancing
  86. Spring life cycle
  87. What is dependency Injection
  88. Annotation used in circuit breaker implementation
  89. Microservice design patterns
  90. fast iterate and safe iterate
  91. How you read file from angular
  92. difference between get and load in hibernate
  93. Spring JPA CRUD Repository
  94. jdbcTemplate methods
  95. difference between Observer and subscribe in angular
  96. Spring boot and hibernate integration steps
  97. How you read properties file from springboot
  98. sql query for one to many mapping.
  99. Functional interface.
  100. Design patterns used Realtime in your application.
  101. Java Multithreading – wait & notify, Obtaining lock.
  102. Static and Dynamic Overloading.
  103. Spring security its annotations.
  104. Java 1.8 features.
  105. Angular Observable subscribe and unsubscribe.
  106. what happens when we call a void method in a system.out.println()?
  107. What is Resource(Request) and Response in Restful services?
  108. how can I return custom data instead of JSON or XML content for a Rest response?
  109. what are stream(s) in java and few operations on them like comparison
  110. difference between comparable and comparator
  111. why Clonable is not implemented by Collection interface, reason?
  112. Components in angular
  113. What is the life cycle of components in angular
  114. Sharing data between components in Angular
  115. Type Script compilation process
  116. Angular life cycle
  117. what are gate in angular
  118. in how many ways I can sort my employee object with the given set of columns, explain?
  119. How to create schedulers in java
  120. How we implement batch import and export functionality in spring.
  121. How to maintain session in server side.
  122. Lifecycle process of angular
  123. How to reload header and footer menu based on particular left menu routing
  124. Box model in CSS
  125. Pseudo selector in CSS
  126. Difference between display block & display inline-block
  127. Difference between position absolute and position relative
  128. What is the internal implementation of HashMap?
  129. What is the algorithm/datastructure used to get an emlement from HashMap?
  130. How to make HashMap synchronized
  131. Difference between HashMap & concurrent hash map
  132. Authenticate client side in angular
  133. Time difference calculation in angular
  134. How to create Generic class in angular
  135. Difference between Post and PUT
  136. Stored Procedures
  137. Monolithic architecture and Microservice Architecture
  138. java 8 new features
  139. List of collections used
  140. How exceptions are handled
  141. Throw and Throws
  142. Final, Finally, Finalize
  143. Spring IOC
  144. Spring boot advantages
  145. JPA repository
  146. First level second level cache in hibernate
  147. Union vs Union all
  148. Spring security
  149. Spring transactions
  150. Custom directives
  151. Get and post in angular
  152. employee has id, name, salary. Find the list of employees where the employee name starts with “n” using java8?
  153. can you the same in ArrayList and array?
  154. Vulnerability checking process in the front end
  155. Have you worked on Cross Site Scripting?
  156. What are the challenged faced in Cross Site Scripting?
  157. Have you worked in Custom annotation creation in Java?
  158. if yes? Could you explain the implementation of custom annotation?
  159. Where thread class variables will get store in Memory?
  160. What are the different databases you worked?
  161. Did you face any query performance issues? how did you increase the performance of the query?
  162. What is index and query of it?
  163. What is the data structure used to create an index?
  164. How can you handle the errors in Spring Boot?
  165. Can you explain what are the dependencies required to create REST application in Spring Boot? what other classes needs to be created to perform CURD operations and it’s flow?
  166. How you worked on application security?
  167. angular life cycle hooks
  168. Explain insertion sort logic
  169. Write query to get 3rd highest salary of employee
  170. How to get the average value of integers using streams
  171. What are method references
  172. What are for lambda expressions introduced and what is the advantage
  173. explain proxy pattern
  174. how to find duplicate user object user {name, age}
  175. What is observable
  176. What is cluster index
  177. What is the deployment procedure of Micro services
  178. Explain service discovery pattern
  179. What is containerization
  180. how to import module and service in Angular
  181. Difference between monolithic and microservices architecture.
  182. Difference between Spring and Spring boot
  183. Explain about Spring boot starter
  184. Spring security
  185. @Springboot application
  186. Gates in angular
  187. Life cycle of angular hooks
  188. How to pass the data between components.
  189. Structural and behavioral directives
  190. Multi threading concepts
  191. Architecture of the current project where you are working
  192. Architecture of angular application
  193. Difference between soap and Rest
  194. Questions on GIT code checkout process
  195. Questions on Front end security concepts
  196. Code deployment procedure
  197. Load balancing concepts related to services
  198. REST and SOAP justification for usage
  199. Questions based on resume and projects explanation Why ? What ?
  200. How we used if we mention any technology

Java : Lambda Expression

What is Lambda expression?

As per Wikipedia, lambda expression also called as anonymous function. It’s a function without name and does not belong to any class. Lambda expression is introduced as part of Java 8 features.

A traditional method or function in java has these main parts.

  • Name
  • Parameter list
  • Body
  • Return type

A lambda expression in java has these main parts.

  • No Name: as this is anonymous function there is no name needed
  • Parameter list
  • Body: this is the main part of the function
  • No return type: you don’t need to mention the return type in lambda’s expression. The java 8+ compiler is able to infer the return type by checking the code.

Program of using lambda expression without any parameters:

@FunctionalInterface
interface NoParamInterface{
    String printHelloWorld();
}

public class NoParamLambdaTest{
    public static void main(String[] args) {
        NoParamInterface noParamInterface= () -> "Hello World";
        System.out.println(noParamInterface.printHelloWorld());
    }
}

Program of using Lambda expression with single parameter:

@FunctionalInterface
interface SingleParam{
    int incrementBy10(int x);
}

public class SingleParamLambdaTest {
    public static void main(String[] args) {
        SingleParam singleParam = (x) -> x+10;
        System.out.println(singleParam.incrementBy10(5));
    }
}

Program of using Lambda expression with multiple parameters:

@FunctionalInterface
interface MultiParam{
    String concat(String x, String y);
}

public class MultiParamLambdaTest {
    public static void main(String[] args) {
        MultiParam multiParam = (x, y) -> x+" "+y;
        System.out.println(multiParam.concat("Hello", "World"));
    }
}

Program of using Lambda expression with Runnable interface:

public class RunnableExample {

    public static void main(String[] args) {
        //Traditional way of implementation
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                int sum=0;
                for(int i=0;i<10;i++)
                    sum +=i;
                System.out.println("Traditional : "+sum);
            }
        };
        new Thread(runnable).start();

        //Implementing using lambda
        Runnable runnable1 = () -> {
            int sum=0;
            for(int i=0;i<10;i++)
                sum +=i;
            System.out.println("Lambda : "+sum);
        };
        new Thread(runnable1).start();

        //Implementing Thread with Lambda
        new Thread(()->{
            int sum=0;
            for(int i=0;i<10;i++)
                sum +=i;
            System.out.println("Thread with Lambda : "+sum);
        }).start();
    }
}

Program of using Lambda expression with Callable interface:

import java.util.Arrays;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.IntStream;

public class CallableExample {
    public static int[] array = IntStream.range(0,5000).toArray();
    public static int count = IntStream.range(0,5000).sum();

    public static void main(String[] args) throws InterruptedException, ExecutionException {
        Callable<Integer> callable1 = () -> {
            int sumOfEven=0;
            for(int i=0;i<array.length;i++){
                if(i%2 == 0)
                    sumOfEven = sumOfEven + i;
            }
            return sumOfEven;
        };

        Callable<Integer> callable2 = () -> {
            int sumOfOdd=0;
            for(int i=0;i<array.length;i++){
                if(i%2 == 1)
                    sumOfOdd = sumOfOdd + i;
            }
            return sumOfOdd;
        };

        ExecutorService executorService = Executors.newFixedThreadPool(2);
        System.out.println("Sum of Even of given range: "+executorService.invokeAny(Arrays.asList(callable1)));
        System.out.println("Sum of Odd of given range: "+executorService.invokeAny(Arrays.asList(callable2)));
        executorService.shutdown();

        System.out.println("Count of the given range is : "+count);
        System.out.println("Sum of Odd and Even is equals to count");
    }
}

StringJoiner vs StringBuffer vs Collectors.Joining() Performance Test

In this article we are sharing the program to identify which is the best performance provider out of StringJoiner, StringBuffer, StringBuilder and Collectors.joining() while joining/appending String.

import java.util.ArrayList;
import java.util.List;
import java.util.StringJoiner;
import java.util.stream.Collectors;
public class PerformanceTest {
	public static void main(String[] args) {
		List<String> l = new ArrayList<>();
		for(int i=0;i<1000;i++) {
			l.add("12345"+i);
		}
		long start = System.currentTimeMillis();
		usingStringJoiner(l);
		long middle = System.currentTimeMillis();
		System.out.println("Time taken by StringJoiner : "+(middle - start));
		usingStringBuffer(l);
		long end = System.currentTimeMillis();
		System.out.println("Time taken by StringBuffer : "+(end-middle));
		usingCollectors(l);
		long end1 = System.currentTimeMillis();
		System.out.println("Time taken by Collectors.joining() : "+(end1 - end));
		usingStringBuilder(l);
		System.out.println("Time taken by StringBuilder : "+(System.currentTimeMillis() - end1));
	}
	
	private static void usingStringJoiner(List<String> list) {
		StringJoiner sj = new StringJoiner("|");
		list.stream().filter(code -> code != null).forEach(code -> sj.add(code));
		String s = sj.toString();
		System.out.println(s);
	}
	
	private static void usingStringBuffer(List<String> list) {
		StringBuffer buf = new StringBuffer();
		list.stream().forEach(code -> buf.append(code).append("|"));
		String output = buf.toString();
		if (output.endsWith("|")) {
			output = output.substring(0, output.length() - 1);
		}
		System.out.println(output);
	}
	
	private static void usingCollectors(List<String> list) {
		String str = list.stream().collect(Collectors.joining("|"));
		System.out.println(str);
	}
	
	private static void usingStringBuilder(List<String> list) {
		StringBuilder builder = new StringBuilder();
		list.stream().forEach(code -> builder.append(code).append("|"));
		String output = builder.toString();
		if (output.endsWith("|")) {
			output = output.substring(0, output.length() - 1);
		}
		System.out.println(output);
	}
}

Time taken by StringJoiner : 49
Time taken by StringBuffer : 2
Time taken by Collectors.joining() : 4
Time taken by StringBuilder : 3

If you observe the above statistics of StringJoiner and Collectors.joining(), StringJoiners are taking 49 milliseconds to complete the task where Collectors.joining() is taking only 4 milliseconds which is 45 milliseconds lesser. Here one point I would like to bring to your notice is, StringJoiner is used in the implementation of joining() in Collections. But, when I use StringJoiner externally, it is taking more time than how joining() performing.

public static Collector<CharSequence, ?, String> joining(
CharSequence delimiter, CharSequence prefix, CharSequence suffix) {
    return new CollectorImpl<>(
            () -> new StringJoiner(delimiter, prefix, suffix),
            StringJoiner::add, StringJoiner::merge,
            StringJoiner::toString, CH_NOID);
}

StringJoiner internally uses StringBuilder to store value.

/*
 * StringBuilder value -- at any time, the characters constructed from the
 * prefix, the added element separated by the delimiter, but without the
 * suffix, so that we can more easily add elements without having to jigger
 * the suffix each time.
 */
private StringBuilder value;

/* preparing StringBuiler object in StringJoiner */
private StringBuilder prepareBuilder() {
  if (value != null) {
    value.append(delimiter);
  } else {
    value = new StringBuilder().append(prefix);
  }
  return value;
}

StringBuilder has been used across all the methods of StringJoiner to perform various operations. There is one more option of using StringUtils.join() method to perform similar operation. I would like to suggest to use StringBuffer than StringUtils because it internally uses the StringBuffer only to store value.