Monthly Archives: September 2017

Partial Injection in Constructor Injection in Spring

What is Partial Injection? Suppose we have three dependencies say String, int and long and we provide values only for two dependencies i.e. for String and int. So if the container automatically satisfies the third dependency then it is known as Partial Injection. Container takes default value for undefined dependencies. Partial Injection in Constructor Injection: In constructor injection, partial… Read More »

Java Interview Program (3)

Problem Statement: Given two arrayLists of same length:- input 1: {12,1,32,3} input 2: {0,12,2,23} Retrieve the odd position elements form input 1 and even position elements from input 2. Put the retrieved elements into the new arrayList  say output at the same positions from where they are retrieved from. output: {0,1,2,3} Consider 0th position as even position. Solution: Result:

Partial Injection in Setter Injection in Spring

What is Partial Injection? Suppose we have three dependencies say String, int and long and we provide values only for two dependencies i.e. for String and int. So if the container automatically satisfies the third dependency then it is known as Partial Injection. Container takes default value for undefined dependencies. Partial Injection in Setter Injection: In setter injection, partial… Read More »

Java Interview Program (2)

Problem Statement: Given three strings say input 1, input 2 and input 3:- input 1: “GeniusRajkumarDev” input 2: “Raj” input 3: “Dev” Return 1 if input 2 comes before input 3 in input 1 else return 2 output: 1 Solution: Result:

How to print output in quotes in Java?

To print constants in quotes: To print constants in quotes, write them inside “\”constant\””. To print variables in quotes: To print variables in quotes, write them inside “\””+variable+”\””. Example: Result:  

Setter Injection overrides the values injected by Constructor Injection in Spring

Setter injection overrides Constructor injection: If we write both setter injection and constructor injection for the same property then setter injection will override the values provided by constructor injection. Example: Create a Dynamic Web Project in Eclipse IDE Add the following jars:- commons-logging.jar spring-beans.jar spring-core.java Create MyFactory.java Create SIOverrides.java Create User.java Create applicationContext.xml Result: Run User class as… Read More »

Java Interview Program (1)

Problem Statement: Given two integer arrays, merge the common elements into a new array and find the sum of the elements. input 1: {1,2,3,4} input 2: {3,4,5,6} common elements: {3,4} output:7 Logic: Solution: Result:

How to post/highlight code in WordPress

SyntaxHighlighter Evolved: This plugin allows you to post the source code with the highlighted syntax. If no value is provided to lang attribute, by default it will consider it as a plain text which means there will be no highlighting. All you need to do is to write your code like this: SyntaxHighlighter Evolved supports following languages: java javafx… Read More »