Enter your E-mail Address below for Free E-mail Alerts right Into your Inbox: -

Showing posts with label interview questions. Show all posts
Showing posts with label interview questions. Show all posts

Wednesday

Apple Interview Questions for Software Engineer

Apple Interview Questions for Software Engineer



Apple the Tech Giant, To work for Apple is a dream for 

every software engineer. Like Google Apple will go for some 

tricky questions to hire you because they need the right one.


  1. "Describe an interesting problem and how you solved it."
  2. "What brings you here today?"
  3.  "You have a 100 coins laying flat on a table, each with a head side and a tail side. 10 of them are heads up, 90 are tails up. You can't feel, see or in any other way find out which side is up. Split the coins into two piles such that there are the same number of heads in each pile."
  4. "What would you want to do 5 years from now?"
  5.  "Why do you want to join Apple and what will you miss at your current work if Apple hired you."
  6. "Describe yourself, what excites you?"
  7. "Have you ever disagreed with a manager's decision, and how did you approach the disagreement? Give a specific example and explain how you rectified this disagreement, what the final outcome was, and how that individual would describe you today."
  8. "Are you creative? What's something creative that you can think of?"
  9. "Given an iTunes type of app that pulls down lots of images that get stale over time, what strategy would you use to flush disused images over time?"
  10. “If you have 2 eggs, and you want to figure out what's the highest floor from which you can drop the egg without breaking it, how would you do it? What's the optimal solution?”

Tuesday

Infosys Interview Experience 2015 - Tell us your experience online

Infosys Interview Experience 2015 - Tell us your experience online

Hi , I am 3 years experienced java developer. I attended the Infosys Interview at Trivandrum SEZ on February 2015. The Interview Process is as follows.

I applied  for the Sr.Software Engineer post by seeing the opening in TimesJob.com. I have been called for the interview,before they asked me to fill the application form.Documents need to be carried for the Interview.

Documents Needed:

  1. Your Filled Application Hard Copy
  2. Id Proof
  3. Photograph
  4. Call Letter.
Interview Process:
  1. Technical Interview: A panel of 2 people interviewed me. They asked me to introduce myself and asked about my project. As I am a Java Developer then they asked about the basics and advanced concepts in java and Oracle. After then they asked me to wait outside.After some time HR came and taken me to the next round.
  2. HR Interview: In HR Interview he only asked me about the salary and the joining details.The he told me that they will call me within 7-10 working days.But till no call.
If anybody have the experience please share here as comment for others to help. 

Sunday

Difference between Maven and Ant and Jenkins and Hudson

Difference between Maven and Ant and Jenkins and Hudson

Commonly Maven and Ant are java build tools. Main difference between Maven and Ant is Maven supports Dependency Management.You can setup your CI environment using Jenkins or Hudson and automatically build, test and deploy your Java project. Now last, main difference between Jenkins and Hudson, both are originate from same source code but one is closed source while other is open source.

All are Java build tools supports unit testing and project management.The out put of build is .JAR,.WAR or .EAR files.
Main difference between ANT and Maven is that In ANT you need to define every thing i.e. source directory, build directory, target directory etc while Maven adopts principle of Convention over configuration. Which means Maven has predefined project structure i.e. standard directory for source files, test files and resources.

Maven VS Ant:
Maven comes after Ant and it offers more functionality than Ant. The key factors of Maven over Ant are as follows.

  1. Versioning managed by bean
  2. Maven provides Conventions
  3. Extensibility and reusability
  4. Better Quality
  5. Less Time Spent
Differences:
  1. Less Configuration needed.It works on principle of Convention over configuration.
  2. Maven supports dependency management. All the jar files are stored in a repository.It automatically downloads dependency during build process.But Ant stores it in a ${lib}.
  3. Maven offers a consistent and common interface to build Java projects.By looking the pom.xml you can easily understood the path and what are the project dependencies.




Thursday

Java Exception Interview Questions

Java Exception Interview Questions

Java Exceptions is a large topic and lot of topics are need to be covered. Here i will give you some introduction about Exceptions in Java.
What is Exception in Java?
                                               An Exception is a programming error. Exceptions are of two types. Checked Exceptions and Unchecked Exceptions. An Error is not an Exception.

  1. What is an Exception in Java? :  Exception is a programming error in Java.Exceptions are inherited from Throwable,exception,Runtime. Exceptions are handled by try and catch statements.
  2. Difference between Checked and Unchecked Exception in Java: Checked Exceptions are handled by try and catch. They occur at Compile time.ex:- IOException Unchecked Exceptions are those programming errors. ex:- Nullpointer exception.
  3. Is it necessary to follow try with catch block: No it's not necessary to have a catch block after try. you can also use finally after try block.
  4. What is the difference between throw and throws in Java: 

1)throw is used to explicitly throw an exception.
 throws is used to declare an exception.
    
2)checked exceptions can not be propagated with throw only.
checked exception can be propagated with throws.

3)throw is followed by an instance.
throws is followed by class.

4)throw is used within the method.
throws is used with the method signature.

5)You cannot throw multiple exception
You can declare multiple exception e.g. public void method()throws IOException,SQLException.


6. How to write Custom Exception in Java: A Custom Exception is an User Defined Exception. It should inherit the Exception base class.
package com.sis.crm.exception.util;

public class AlreadyExistException extends Exception{
@Override
public String getMessage() {
return super.getMessage();
}

public AlreadyExistException(String message, Throwable exception) {
super((exception != null && (message == null || message.length() == 0)) ? exception.getMessage() : message, exception);
}

@Override
public String toString() {
return super.toString();
}

}

7. What is the difference between Final,Finalize, and Finally keyword in Java:  Final keyword is used for creating immutable class in java. Finalize keyword is used for Garbage Collection in Java. Finally keyword is used to execute some code that is to close some resources etc. example if an error occurs in try block and error occurs in catch block, and finally is used to close some database connection etc.

10 Best programming Practices for Java Naming Conventions

10 Best programming Practices for Java Naming Conventions

Each and Every Programmer are well and best in coding, are they aware of how to code and how the naming conventions must follow.There are best practices and bad practices. Best practices are the one that has to be followed while coding and bad practices are the that has to be avoided while coding. Best Coding reflects your ability in programming. Best Naming Conventions increases the readability and the software quality. These are common regardless of the Programming language. Java, C++,.Net all should follow the naming Conventions.

Java Naming Conventions for Variables,Methods,Class etc...

These are the Naming Conventions came across years of programming practices. lets look at some of the Naming Conventions.

  1. Give Meaningful Names:
                                                Always give names that are meaningful and related to the program. It allows easy understanding of the need for the variable and use of this variable. eg:- joiningDate. if it's given jDate, it's not able to easily understand. it can be followed for variable names,Class,methods and packages.

2. Prefer shorter names rather than longer one:
                                                                               You should prefer shorter names rather than longer names. If it's shorter then it's easy to read and understand.

3. Follow Java Naming Conventions:
                                                              Java also provides some naming conventions. for example here are some of the naming conventions.  Class name should start with Uppercase letter. ex:- Employee. Variables should start with lowercase letter and second word should be uppercase letter(CAMEL CASE). Constants are all Upper Case letters. ex:- MAX_LIMIT.

4. Avoid Pointless Names:
                                             For example variables like abc,temp, etc. It's a bad programming practice.

5. Follow Classical Programming Convention:
                                                                             As already mentioned Pointless Names are bad programming practices. But you can use simple variables like 'i' , 'j'.

while(i<n)
{
n++;
}

                                                                  
6. Avoid Clusters in Programming:
                                                         For example "_test" etc are need to be avoided.you should use meaningful and unique names.

7. Avoid Duplication:
                                    Avoid usage of similar names. For example employee and employees are same but it will leads to complication. These are encountered while code reviews.

Sunday

How to convert a map to list in Java with example

How to convert a map to list in Java with example

Before doing this you must have clear idea of List and Map in Java. List is an Interface implementing the Collection Interface.List allows duplicate values.Some Classes implementing List Interfaces are ArrayList,LinkedList etc.Map is not a Collection.Some Classes implementing the Map Interfaces are HashMap,TreeMap etc.

Logic:
  1. First we have to convert the Map into a Set using entryset.
  2. Second we have to convert Set into List.
Example:

public class HelloWorld{

public static void main(String[] args) {
HashMap<String, Integer> mapOne = new HashMap<String, Integer>();

mapOne.put("one", 1);
mapOne.put("two", 2);
mapOne.put("three", 3);
mapOne.put("four", 4);
mapOne.put("five", 5);
        
        Set<Entry<String, Integer>> set = mapOne.entrySet();
        List<Entry<String, Integer>> list = new ArrayList<Entry<String, Integer>>(set);
        Iterator<Entry<String, Integer>> it = list.iterator();
        
        while (it.hasNext()) {
            Entry<String, Integer> entry = it.next();
            System.out.println("Map Converted to List : " + entry);
        }
}
}


Output:
Map Converted to List : two=2
Map Converted to List : five=5
Map Converted to List : one=1
Map Converted to List : four=4
Map Converted to List : three=3

Difference between method overloading and method overriding in Java

Difference between method overloading and method overriding in Java

This is one of the important tricky programming interview questions asked in Java. Here are the basic differences between method overloading and method overriding in Java.


  1. Method Overloading occurs while compile time and Method Overriding occurs while runtime.
  2. Method Overloading occurs in same class and sub class, but overriding occurs only in subclass.
  3. Static methods can be overloaded, but you can't override static methods.
  4. For overloading method signature has to be changed, but for overriding it's not needed.
  5. Private and final methods can be overloaded but cannot override.

Static Blocks in Java

3. Static blocks in Java:
                                       Static blocks are called before the main block is called.It can initialize the static data members.

Example:

public class HelloWorld{

static double pi = 3.14;

 static{System.out.println("static block is invoked");}  
public static void main(String[] args) {
System.out.println("main block");
}

Static Methods in Java

2. Static Methods:
                              Static Methods belongs to the Class rather than the object.Static methods can be invoked without the need of objects.Statics variables can be modified by static methods.

Example:


public class HelloWorld{
static double pi = 3.14;
     static void calc(double a) {
pi = a;
System.out.println("Value pi is: "+a);
}
public static void main(String[] args) {
HelloWorld.calc(55.3);//accessing the static method
}
}

Thursday

How to check a file is hidden in Java

How to check a file is hidden in Java

In Java to check whether a file is hidden in location we can use the below mentioned program. It checks whether the specified file is hidden or not.


It uses the isHidden() method on File object.

Possible Exceptions are IOException and SecurityException.


package com.jobberindia;
import java.io.File;
import java.util.*;
public class HelloWorld {

public static void main(String[] args) {

    File file = new File("c:/filename.txt");

    if(file.isHidden()){
    System.out.println("The file is hidden");
    }else{
    System.out.println("The file is not hidden");
    }
}
}



Wednesday

What is Map in Java?

What is Map in Java?

Other than List and Set Map is used to Store Key and Value Pair.The key is unique and values are duplicate allowed. Map implement the collection Interface. It allows only one null value which is stored in the zeroth index.

These are the some of the classes implements the Map<K,V> Interface.  HashMap, Hashtable, IdentityHashMap, LinkedHashMap.

Example:

public class HelloWorld {

public static void main(String[] args) {
List<String> list = new ArrayList<String>();
       list.add("Hello");
       list.add("World");
       list.add("Hello1");
       list.add("World2");
       Map<Integer,String> map = new HashMap<Ineger,String>();
     
       for(int i=0;i<list.size();i++)
       {
       map.put(i, list.get(i));
       }
     
        System.out.println("Data stored in mainlist "+map.get(2));

}


}

What is List in Java?


What is List in Java? 

List implements the Collection<E>, Iterable<E> Interfaces.

public interface List<E>
extends Collection<E>.
List in Java allows to store objects by storing them in each index. Other than Set List allows Duplication of elements.To store an element in List use the add() method and to get a value use get() method.

Some Classes implementing List Interface are ArrayList,LinkedList etc.

List throws these Exceptions:


UnsupportedOperationException
ClassCastException
NullPointerException
IllegalArgumentException
IndexOutOfBoundsException

Example:

package com.jobberindia;
import java.util.*;
public class HelloWorld {
public static void main(String[] args) {
// TODO Auto-generated method stub
        List<String> list = new ArrayList<String>();
        list.add("Hello");
        list.add("World");
        list.add("Hello1");
        list.add("World2");
        System.out.println("Data stored in mainlist "+list);
System.out.println("Size of list before removing "+list.size());
ArrayList<String> subList = new ArrayList<String>(list.subList(1, 2));
System.out.println("Data stored in sublist "+subList);
System.out.println("Size of list before removing "+subList.size());
}

}

Difference between List and Set and Map

Difference between List and Set and Map

List,Set,Map are the basic collection interfaces, although Map doesn't inherit Collection Interface, it belongs to the Collection in Java.

What is List in Java? 

List implements the Collection<E>, Iterable<E> Interfaces.

public interface List<E>
extends Collection<E>.


List in Java allows to store objects by storing them in each index. Other than Set List allows Duplication of elements.To store an element in List use the add() method and to get a value use get() method.

Some Classes implementing List Interface are ArrayList,LinkedList etc.

List throws these Exceptions:




UnsupportedOperationException
ClassCastException
NullPointerException 
IllegalArgumentException
IndexOutOfBoundsException 
Example:
package com.jobberindia;
import java.util.*;
public class HelloWorld {
public static void main(String[] args) {
// TODO Auto-generated method stub
        List<String> list = new ArrayList<String>();
        list.add("Hello");
        list.add("World");
        list.add("Hello1");
        list.add("World2");
        System.out.println("Data stored in mainlist "+list);
System.out.println("Size of list before removing "+list.size());
ArrayList<String> subList = new ArrayList<String>(list.subList(1, 2));
System.out.println("Data stored in sublist "+subList);
System.out.println("Size of list before removing "+subList.size());
}

}
What is Set in Java?

Set implements the Collection<E>, Iterable<E> Interfaces.

public interface Set<E>
extends Collection<E>

Set in Java allows to store objects by storing them in each index. Other than Set Set doesn't allows Duplication of elements.To store an element in Set use the add() method.

Example:



package com.jobberindia;
import java.util.*;
public class HelloWorld {

 public static void main(String[] args) {
        Set<String> set = new TreeSet<String>();

        set.add("Hello");
        set.add("World");
        set.add("Hello1");
        set.add("World2");
        set.add("Hello3");
        set.add("World4");
        System.out.println("Data stored in mainlist "+set); 
 }
}

Some Classes implementing List Interface are TreeSet,HashSet etc.

What is Map in Java?

Other than List and Set Map is used to Store Key and Value Pair.The key is unique and values are duplicate allowed. Map implement the collection Interface. It allows only one null value which is stored in the zeroth index.
These are the some of the classes implements the Map<K,V> Interface.  HashMapHashtableIdentityHashMapLinkedHashMap.
Example:
public class HelloWorld {
public static void main(String[] args) {
List<String> list = new ArrayList<String>();
list.add("Hello");
list.add("Hello1");
list.add("World");
Map<Integer,String> map = new HashMap<Ineger,String>();
list.add("World2");
map.put(i, list.get(i));
for(int i=0;i<list.size();i++)
{ }
}
System.out.println("Data stored in mainlist "+map.get(2)); }
Difference between List VS Set VS Map Interface:
  1. List allows duplicate values.
  2. List allows any number of null values.
  3. Set doesn't allows duplicate values.
  4. Set allows one null value.
  5. Map allows one null key value.
  6. List maintains the insertion order.
  7. Set and Map doesn't maintain the insertion order.
  8. Map stores key and value pair.
Based on your usage select these interfaces carefully.


How to get sublist from an ArrayList in Java

How to get sublist from an ArrayList in Java


We already studied about ArrayList in Java. Now we can see how to sublist an ArrayList. the scenario occurs when a ArrayList contains data that is to be displayed into two areas.
For this we use subList(arg1,arg2);
Example:
/** * author: JOBBERINDIA
 */
package com.jobberindia;
import java.util.*;
/**
 * @author user
 *
 */
public class HelloWorld {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
        List<String> list = new ArrayList<String>();
     
        list.add("Hello");
        list.add("World");
        list.add("Hello1");
        list.add("World2");
        list.add("Hello3");
        list.add("World4");
     
        System.out.println("Data stored in mainlist "+list);
System.out.println("Size of list before removing "+list.size());
ArrayList<String> subList = new ArrayList<String>(list.subList(1, 2));
System.out.println("Data stored in sublist "+subList);
System.out.println("Size of list before removing "+subList.size());
}
}


OutPut:
Data stored in mainlist [Hello, World, Hello1, World2, Hello3, World4]Size of list before removing 6Data stored in sublist [World]
Size of list before removing 1
Possible Errors are IndexOutOfBoundException and IllegalArgumentException.

Sunday

Arrays in java

Arrays in java

Arrays are one of the important feature of java. Arrays are used to store some objects that commonly share some properties. Arrays Provides lot of functionalists. for more about arrays see


  1. Arrays
  2. Arrays
  3. Arrays
  4. Arrays

public final class Test {

void comparaeAll()
{
int arr[] = {10, 20, 30, 40, 50};
      for(int i=0; i < arr.length; i++)
      {
            System.out.print(" " + arr[i]);              
      }
}
}


Tuesday

How String Comparison works in java or Facts about String in java

How String Comparison works in java or Facts about String in java

String is the one of the mostly used feature in java. All java programmers came across this that what i am going to explain here. But they didn't care about it means they are not interested to know how java works...:).

Let me consider a simple program.

public static void main(String args[])
{
String s1 = "hai how r u";
        String s2 = "hai how r u";
        String s3 = new String(s1);
        
        if(s1==s2){
            System.out.println("s1 == s2 : TRUE");
        } else {
            System.out.println("s1 == s2 : FALSE");
        }
        if(s1.equals(s2)){
            System.out.println("s1.equals(s2) : TRUE");
        } else {
            System.out.println("s1.equals(s2) : FALSE");
        }
        
        if(s1==s3){
            System.out.println("s1 == s3 : TRUE");
        } else {
            System.out.println("s1 == s3 : FALSE");
        }
        if(s1.equals(s3)){
            System.out.println("s1.equals(s3) : TRUE");
        } else {
            System.out.println("s1.equals(s3) : FALSE");
        }


}

Frankly just answer this program without seeing the output. Did you know how the below output comes, what are the things gone innerside.

Output:-

s1 == s2 : TRUE
s1.equals(s2) : TRUE
s1 == s3 : FALSE

s1.equals(s3) : TRUE

In java If you create a String it just looks inside the String pool to verify whether any other literals are there with the same value, then its reference is given to the new one.Otherwise a new reference is given to the new literal.

Thus the "==" operator compares the reference(memory location) and values and return true.The equals also compares the value and returns true.

But the s3 is created by new keyword hence it occupies a new location in java heap. thus the "==" operator fails but the equals operator succeeds.

Why we should avoid "==" operator for comparing Integer objects in java

Why we should avoid "==" operator for comparing objects in java

The autoboxing is the technology introduced since java 5. Autoboxing in the sense converting  primitive types to its wrapper classes.
eg:- int to Integer. for more see  autoboxing and unboxing in java.

During comparison the Integer is converted into its primitive types. Even if the two have the same value it should return false because "==" also compares the reference, and it may be two objects in the java heap.

public static void main(String args[])
{
Integer i1 =260;
Integer i2 = 260;
if (i1 == i2) { System.out.println("i1 and i2 is equal"); }
else { System.out.println("i1 and i2 is not equal "); }


}

here it will print false because i1 and i2 are two objects in the heap and reference are different, so better to avoid "==" operator for comparing Integer Objects.

Overriding equals() and hashCode() methods in java

Overriding equals() and hashCode() methods in java

equals() and hashCode() are two methods of java.lang.Object. The main use of equals() method is to compare the two objects. If the value and the two reference variables are pointing to the same memory location it returns true.

Normally the equals of method is used in HashMap. Also used in HashSet to avoid duplicates.

1) Reflexive : Object must be equal to itself.
2) Symmetric : if z.equals(x) is true then x.equals(z) must be true.
3) Transitive : if z.equals(x) is true and z.equals(y) is true then y.equals(x) must be true.
4) Consistent : multiple invocation of equals() method must result same value until any of properties are modified. So if two objects are equals in Java they will remain equals until any of there property is modified.
5) Null comparison : comparing any object to null must be false and should not result in NullPointerException.

hashCode() and equals();-

  1. If two objects are equal then their hashcode are equal.
  2. If two objects are not equal then their hashcode is also different.
Code Example:-

/**
 * 
 */
package in.jobberindia;

/**
 * @author user
 *
 */
public class EqualsOverRide {
private int id; 
private String fName;
private String lName;
/**
* @return the id
*/
public int getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(int id) {
this.id = id;
}
/**
* @return the fName
*/
public String getfName() {
return fName;
}
/**
* @param fName the fName to set
*/
public void setfName(String fName) {
this.fName = fName;
}
/**
* @return the lName
*/
public String getlName() {
return lName;
}
/**
* @param lName the lName to set
*/
public void setlName(String lName) {
this.lName = lName;
}
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((fName == null) ? 0 : fName.hashCode());
result = prime * result + id;
result = prime * result + ((lName == null) ? 0 : lName.hashCode());
return result;
}
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof EqualsOverRide)) {
return false;
}
EqualsOverRide other = (EqualsOverRide) obj;
if (fName == null) {
if (other.fName != null) {
return false;
}
} else if (!fName.equals(other.fName)) {
return false;
}
if (id != other.id) {
return false;
}
if (lName == null) {
if (other.lName != null) {
return false;
}
} else if (!lName.equals(other.lName)) {
return false;
}
return true;
}

}