JMockit offers a set of utility fields for making argument matching more generic. 1) anyX fields like anyInt, anyBoolean, anyString, etc. There is one for each primitive type, and the corresponding wrapper class, … Read more ›...
JMockit offers a set of utility fields for making argument matching more generic. 1) anyX fields like anyInt, anyBoolean, anyString, etc. There is one for each primitive type, and the corresponding wrapper class, … Read more ›...
In the previous post entitled Java Tree structure interview questions and coding questions — Part 1, we looked at a very simple Tree structure. In this example, let’s look at a more complex tree structure with generics. Q. Write classes for a Tripple tree structue as shown below? … Read...
Q. What is wrong with the following code snippet?
|
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 29 30 31 32 33 34 35 36 37 38 39 |
import java.util.HashMap; import java.util.Map; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; public class WhatIsWrong implements Runnable { //shared by threads final static Map<String, String> map = new HashMap<String, String>(); public static void main(String[] args) throws InterruptedException { ExecutorService pool = Executors.newFixedThreadPool(100); for (int i = 0; i < 100; i++) { WhatIsWrong wiw = new WhatIsWrong(); pool.submit(wiw); } pool.shutdown(); pool.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS); } @Override public void run() { for (int i = 0; i < 1000000; i++) { map.put(Thread.currentThread().getName(), "wow-" + i); Object retrieved = map.get(Thread.currentThread().getName()); if(retrieved == null) { System.out.println("Race conmdition detected!!! Map is in inconsistent state"); } } } } |
A. It is NOT thread-safe as a “HashMap” is not thread-safe as per the Java API, and race conditions can leave the “map” in “inconsistent state“. … Read more ›...
List, Set, Map, and Queue(access the ends FIFO or LIFO) are the basic Java data structure interfaces for which there are different implementations to cater for different usage patterns. Java data structure interview questions are very popular, … Read more ›...
The scenario based questions are very popular with the job interviewers, and some scenario based questions are related to decoupling and asynchronous (aka non-blocking) processing in Java with message queues/topics, database tables where one process inserts data and another process consumes the inserted data, and Future objects in Java multi-threading....
Step 1: Setup Java, Maven, and SonarQube
1. Java: Latest possible version. Setting up Java, Maven, and eclipse.
2. Maven 3: For building. Setting up Java, Maven, and eclipse.
3. SonarQube: For code quality.
…
A distributed system consists of multiple software components that are on multiple computers (aka nodes), but run as a single system. These components can be stateful, stateless, or serverless, and these components can be created in different languages running on hybrid environments, using open-source technologies, open standards, and interoperability.
Q01.
…
Q01. Can you describe a business domain of a Telecom company offering multiple services to its customers? A01. A Telecom company will have entities such as Customer, Account, Subscriptions & Products representing a business domain. 1) Each customer entity has a name, … Read more ›...
Java Web Services interview Questions & Answers Links: 6 Java RESTful Web services Interview | 11 SOAP Web service interview | 5 JAXB interview Questions & Answers | Java Web Services interview Questions & Answers Q1. … Read more ›...
Q. Complete the method “Set getAllCombinations(String input) ” where input is any string and the method should return all possible combinations of a given string.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.Set; public class WordPermutations { public static Set<String> getAllCombinations(String input) { throw new RuntimeException("Complete the given code"); } public static void main(String[] args) { Collection<String> words = getAllCombinations("abc"); for (String word : words) System.out.println(word); } } |
For example: “abc” will have a permutation of 3! … Read more ›...
JMockit offers a set of utility fields & methods for making argument matching more generic. This extends 09: JMockit interview Q&As & examples on matching of argument values 1) anyX fields like anyInt, anyBoolean, … Read more ›...
This is an extension to Java Tree structure interview and coding questions — Part 2, and adds functional programming and recursion. Step 1: The Tree interface with get( ) method that returns either a Triple tree or Leaf data. … Read more ›...
Example #1 Wiring JDBC Datasource
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
@Configuration @ImportResource("application.yml") public class AppConfig { @Autowired private Environment environment; @Bean public DriverManagerDataSource datasource() { DriverManagerDataSource ds = new DriverManagerDataSource(); ds.setDriverClassName(environment.getRequiredProperty("spring.datasource.driver-class-name")); ds.setUrl(environment.getRequiredProperty("spring.datasource.url")); ds.setUsername(environment.getRequiredProperty("spring.datasource.username")); ds.setPassword(environment.getRequiredProperty("spring.datasource.password")); return ds; } } |
application.yml where the datasource properties are read from.
|
1 2 3 4 5 6 7 8 9 10 11 12 |
############ # Datasource properties ############ spring: datasource: driver-class-name: com.sybase.jdbc4.jdbc.SybDataSource url: jdbc:sybase:Tds:mydbhost:5700/my_db username: user password: pwd |
Example #2 Wiring JDBC Datasource with JNDI
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
@Configuration @ImportResource("application.yml") public class AppConfig { @Autowired private Environment environment; @Bean public DataSource dataSource() { final JndiDataSourceLookup jndiLookup = new JndiDataSourceLookup(); final String dataSourceJndi = environment.getRequiredProperty("spring.datasource.jndi"); return jndiLookup.getDataSource(dataSourceJndi); } } |
Example #3 Wiring the JPA persistence unit processors Callback interface for post-processing a JPA PersistenceUnitInfo. … 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.