1.
What's New in JDK
8
a.
Lambda Expressions
b.
Functional Interfaces
c.
Default methods
d.
Static...
Thursday, 19 October 2017
Thursday, 21 September 2017
Java Algorithms Trees
A tree will have a root node on its top and it has child and child have child.
Node with out child are called leaf.
A Binary Tree contains nodes with two children always.Each node has left node and right node.
Binary search tree is a binary tree having specific ordering. Here always left node contains lesser and right node...
Wednesday, 20 September 2017
Java Algorithms Bubble Sort
Bubble Sort is the simplest sorting algorithm that works by repeatedly
swapping the adjacent elements if they are in wrong order.
Getting each element one by one and comparing it with adjacent elements and swapping the positions.
public void bubbleSort() {
int temp, firstValue, secondValue;
int[] arr = { 1, 90, 25, 22, 4, 50 };
printArray(arr);
for (int i = 0; i < arr.length; i++) {
...
Java Algorithms Linear Search
A linear search traverse down a list, one item at a time, without jumping.
public String linearSearchForValue(int value) {
String indexesWithValue = "";
for (int i = 0; i < size; i++) {
if (theArray[i] == value) {
indexesWithValue += i + " ,";
}
}
return indexesWithValue;
}
.sk-code {
background-color: #ebebeb !important;
padding: 0px 6px 5px 18px !important;
...
Travesrse Matrix Diagonally in Java
A matrix will be in M x N format.So what we need to do is, get value of indexes from 0,0 to M,N.
Itreate the two dimensional array in diagonally as follow
50 36 22
31 88 87
27 73 95
After diagonal traverse the output will be.
50
31 36
27 88 22
73 87
95
Consider the above output
50
31 36
27 88 22
These elements start from left to right top
Need to iterate for 0 to M-1 using for loop and display corresponding...
Tuesday, 19 September 2017
Traverse the matrix as spiral in Java

A matrix will be in M x N format.So what we need to do is, get value of indexes from 0,0 to m,n.
Itreate the two dimensional array in spiral mode as follow
we need to traverse matrix and remove the row/column which already traversed.
We are not going to delete the elements instead we will limit it by defining boundaries.
Boundaries...
Monday, 18 September 2017
Traverse the matrix in Java
Traverse the matrix in Java
A matrix will be in M x N format.
So what we need to do is, get value of indexes from 0,0 to m,n.
Itreate the two dimensional array as follow
take 0(i) and traverse j till j < N
take 1(i) and traverse j till j < N
.
.
till M(i) and traverse j till j < N
PrimeNumberCheck.java
...
Check number is prime or not
To check the given number is prime or not.
Prime Numbers:
A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.
It means the remainder of divison of N with numbers from 2 to N/2 should be grater than zero.
Lets take 6
6%2=0, 6%3=0...from 2 to 3(2 to 6/2)
here remainder is zero. So 6 is not prime number.
Lets take 5 now
5%2=1
here remainder is greater...
Friday, 15 September 2017
Order of Execution in java Inheritance
Order of Execution
Parent Static Block
Child Static Block
Parent Normal Block
Parent Constructor
Child Normal Block
Child Constructor
Child method invoked
Animal.java
public class Animal {
static {
System.out.println("Animal Static Block ");
}
public Animal() {
System.out.println("Animal Consuctor");
}
{
System.out.println("Animal Normal Block");
}
public...
Java Spring Interview Questions
Load application Context on Spring?
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
Autowired
@Autowired
private ApplicationContext appContext;
Spring bean scopes: session and globalSession
GlobalSession is something which is connected to Portlet applications. When your application works in Portlet container it is built of some amount of portlets. Each portlet has its...
Write a code to create deadlock in java
public class DeadLockEx {
private String str1 = "SPRING";
private String str2 = "HIBERNATE";
public static void main(String[] args) {
DeadLockEx app = new DeadLockEx();
app.t1.start();
app.t2.start();
}
Thread t1 = new Thread("Thead 1") {
public void run() {
while (true) {
synchronized (str1) {
synchronized (str2) {
System.out.println(str1 + str2);
...
Java Oops Interview Questions
Implementing two interfaces in a class with same method. Which interface method is overridden?
interface A{
int f();
}
interface B{
int f();
}
class Test implements A, B{
public static void main(String... args) throws Exception{
}
@Override
public int f() { // from which interface A or B
return 0;
}
}
If a type implements two interfaces, and each interface define a method that has...
Tuesday, 12 September 2017
Two Sum on arrays
Given an array of integers, return indices of the two numbers such that they add up to a specific target.
Example:
Given nums = [ 3, 4, 5, 2, 10, 8, 9 ]
target = 19
Because nums[4] + nums[6] = 10 + 9 = 19, return [4, 6]
Approach:
step1. take 3 and then add 3 with all other elements
step2. take 4 and then add 4 with all other elements.Continue same till 9
TwoSum.java
...