- 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 ?
CoderLog
Monday, November 17, 2014
Interview Questions
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:-
100 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...... ^_^
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");
}
}
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");
}
}
Labels:
binding,
child,
downcasting,
dynamic,
extends,
inheritance,
java,
override,
parent,
polymorphism,
reference,
runtime,
upcasting
Tuesday, June 26, 2012
Comparison BetweenTwo Dates
var startDate = "02/01/2013";
var endDate = "02/01/2012";
var stDate = startDate.split("/")
var enDate = endDate.split("/")
var stdate = stDate[1] //date
var stmnth = stDate[0]-1 //month
var stYr = stDate[2] //year
var endate = enDate[1] //date
var enmnth = enDate[0]-1 //month
var enyr = enDate[2] //year
var strtDate = new Date();
var endDate = new Date();
strtDate.setFullYear(styr,stmnth,stdate);
endDate.setFullYear(enyr, enmnth, endate)
if(strtDate>endDate){
alert("Start date is greater than end date.")
}
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>
<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
or
java.util.Date = java.text.DateFormat.getDateInstance().parse(date String); |
SimpleDateFormat format = new SimpleDateFormat( "dd.MM.yyyy" ); Date date = format.parse( myString ); |
Subscribe to:
Posts (Atom)