Monday, November 17, 2014

Interview Questions


  • 8 balls , 7 correct 1 heavy. What will be  the minimum value of iterations to find faulty ball ??
  • 8 balls , 7 correct 1 faulty [ don't know light or heavy ] . What will be  the minimum value of iterations to find faulty ball ??
  • In an array of integer, find pair of 2 numbers such that the sum is equal to k.
  • What is time complexity in Map for get and put operations ?
  • How to make class immutable ? 
  • What are patterns you know ?
  • What is singleton pattern ?
  • How mysql saves data ?
  • What are the optimization techniques in mysql ?
  • What are cons in using hibernate ?
  • How do you implement caching in hibernate ?
  • What is difference in GET and POST ?
  • How can you index a column in table  ?
  • What is generics ? 
  • What did you used to implement Web-services  ?
  • How will you find kth minimum number in array of integers ? 

Thursday, June 5, 2014

Java Programs For Various Series

Fibonacci Series :- 

Code :- 


import java.util.Scanner;


public class Fibonacci {


public static void main(String arg[]){

Scanner in = new Scanner(System.in);
int n = in.nextInt();

for (int i = 0; i <= n; i++) {
           System.out.print(fibonacci(i) + " ");
}
 
in.close();
}


public static int fibonacci(int n) {

      if (n == 0) {
          return 0;
      } else if (n == 1) {
          return 1;
      } else {
          return fibonacci(n - 1) + fibonacci(n - 2);
      }
  }
}



Output:-

10

0 1 1 2 3 5 8 13 21 34 55




Saturday, March 1, 2014

On The Cloud [AWS]

I was assigned to setting up new server on AWS and i was pretty much excited while i started working on it. Being a java guy, i am having no knowledge of working with servers, but let see:-

Setting up ISPConfig 3:-

Just followed the instruction given on this article. And yeah ISPConfig is installed.

Successfully generated SPF

Now i am stuck with DKIM, i have to set my mail server and i used Postfix for it, but my ClaimAV is real pain in the arse. I have created DKIM key and all other settings but now mail delivery is stopped. :'(

Dammn itt. I had no SWAP on AWS that is why it was failing.
I found out via:-
free -m

I added swap space by help of this link :-

SWAPFILE=/mnt/swapfile.swap
dd if=/dev/zero of=$SWAPFILE bs=1M count=512
mkswap $SWAPFILE
swapon $SWAPFILE


and voila its working......  ^_^

Sunday, September 22, 2013

Java inheritance concept

Interviewers loves to trap candidates in inheritance and overridding concepts. So here is the solution. Just copy the code below and you will understand all about it as soon as you run this code. Let me know in case of any confusion.  ;)

P.S.:- Be careful for the "**".




public class InheritanceConcept {

public InheritanceConcept() {
System.out.println("Inside Polymorphism Constructor");
}

public static void main(String args[]) {

Parent p = new Parent();
Child c = new Child();

Parent pCast = new Child();
// Child cCast = (Child) new Parent(); //Class Cast Exception **Downcasting

p.ParentsMethod(); //inside ParentsMethod
p.OverriddenMethod(); //inside Parent's OverriddenMethod

c.ParentsMethod(); //inside ParentsMethod
c.ChildsMethod(); //inside ChildsMethod
c.OverriddenMethod(); //inside Child's OverriddenMethod

pCast.ParentsMethod(); //inside ParentsMethod
pCast.OverriddenMethod(); //inside Child's OverriddenMethod **Runtime Polymorphism/Dynamic Binding

}
}

class Parent{

Parent(){
System.out.println("Inside Parent's Constructor");
}

void OverriddenMethod(){
System.out.println("inside Parent's OverriddenMethod");
}

void ParentsMethod(){
System.out.println("inside ParentsMethod");
}
}

class Child extends Parent{

Child(){
System.out.println("Inside Child's Constructor");
}

void OverriddenMethod(){
System.out.println("inside Child's OverriddenMethod");
}

void ChildsMethod(){
System.out.println("inside ChildsMethod");
}
}

Tuesday, June 26, 2012

Comparison BetweenTwo Dates


Monday, June 11, 2012

Select Option Ops

<html>
<body>

<select id="slct" onchange="slct();">
  <option value="1">Volvo</option>
  <option value="2">Saab</option>
  <option value="3">Mercedes</option>
  <option value="4">Audi</option>
</select>

<script>
function slct(){

    var selObj = document.getElementById('slct');
    var selIndex = selObj.selectedIndex;

    alert(selIndex);
    alert(selObj.options[selIndex].value);
    alert(selObj.options[selIndex].text);
}
</script>


</body>
</html>

Tuesday, May 22, 2012

Codelets

#Convert String to Date in Java


java.util.Date = java.text.DateFormat.getDateInstance().parse(date String);
or


SimpleDateFormat format = new SimpleDateFormat( "dd.MM.yyyy" );
Date date = format.parse( myString );