Posts

Showing posts from August, 2012

Explain the difference between abstract class and interfaces with an example for each.

Explain the difference between abstract class and interfaces with an example for each.The differences between abstract class and interface are as follows:
Abstract Class Interface Can have abstract methods and concrete methods Can have only method signatures and static final members All methods are not by default public All methods by default abstract and public An abstract class can extend another abstract class An interface can extend another interface but not a class The extended class can override the methods of its super class and its hierarchy An implementing class can implement multiple interfaces All abstract methods must have abstract access modifier All methods in an interface must not have abstract access modifier The following examples illustrate the differences:
abstract class Shape
{
       abstract void area();
       abstract void perimeter();
       void someMethod() // concrete method
       {
              ..
       }
}
interface Shape
{
       void area();

Android Interview Questions and Answers

Image
Android Interview Questions and Answers Describe Android Application Architecture.
Android Application Architecture has the following components:
• Services – like Network Operation
• Intent – To perform inter-communication between activities or services
• Resource Externalization – such as strings and graphics
• Notification signaling users – light, sound, icon, notification, dialog etc.
• Content Providers – They share data between applications
Describe a real time scenario where android can be used?
Imagine a situation that you are in a country where no one understands the language you speak and you can not read or write. However, you have mobile phone with you.
With a mobile phone with android, the Google translator translates the data of one language into another language by using XMPP to transmit data. You can type the message in English and select the language which is understood by the citizens of the country in order to reach the message to the citizens.
What’s the difference between f…

Hello world in eclipse Or How to create class file in eclipse

Image
Right click on the source folder then select new, then click class then next popup will be show.
Type package name just like com.swain.cell.java.example. Type class name just like Hello(Class name should be stating with capital letter). Then finish.  
// amazon ebay shopbob.com hotels.com canon newegg.com 
Hello.java
package com.swain.cell.java.example;
publicclassHello {
/**         * @param args         */ publicstaticvoid main(String[] args) { // TODO Auto-generated method stub               System.out.println("hello world");
       }
}
Right click on the programme then popup will be show then select run as then java Application.

Output
Hello world



How to create java project in eclipse

Image
Select file menu then select new then select project then another popup will be show.  
// amazon ebay shopbob.com hotels.com canon newegg.com 


Type project name then click finish.

This is a java project folder structure.


String palindrome

Output:
StringPalindrome.java
package com.swain.cell;
publicclassStringPalindrome { publicstaticvoid main(String args[])           {              String original="Himanshu";              String rev=""; int length = original.length(); for ( int i = length - 1 ; i >= 0 ; i-- )                 rev = rev + original.charAt(i); if (original.equals(rev))                 System.out.println(original+" is a palindrome."); else                 System.out.println(original+" is not a palindrome.");           } }


// amazon ebay shopbob.com hotels.com canon newegg.com

how to count selected Character from a sentence in java

Output:
C contents  3 times.
DuplicateCharacter.java
package com.swain.cell;
import java.util.HashMap;
publicclass DuplicateCharacter {
/**         * @param args         */ publicstaticvoid main(String[] args) { // TODO Auto-generated method stub
        String str = "Character duplicate word example java"; char selectedchar='C'; char ch1[]=str.toUpperCase().toCharArray();         HashMap<Character,Integer> hm=new HashMap<Character,Integer>(); for(int i=0; i<ch1.length; i++)         { char ch=ch1[i];             hm.put(ch,(hm.get(ch)==null?1:hm.get(ch)+1));         }         System.out.println(selectedchar+" contents  " + hm.get(selectedchar)+ " times.");        }

how to count selected word in string using java

Output:
java contents  3 times.
package com.swain.cell;
import java.util.HashMap; import java.util.StringTokenizer;
publicclassDuplicateString {
/**         * @param args         */ publicstaticvoid main(String[] args) { // TODO Auto-generated method stub
        String str = "java java android android java example";         String selectedword="java";         StringTokenizer t = new StringTokenizer(str);         HashMap<String,Integer> hms=new HashMap<String,Integer>(); while(t.hasMoreTokens())               {                      String word = t.nextToken();                       hms.put(word,(hms.get(word)==null?1:hms.get(word)+1));               }               System.out.println(selectedword+" contents  " + hms.get(selectedword)+ " times.");

How to count duplicate characters from a sentence in java

Output :
DuplicateCharacter.java
package com.swain.cell;
import java.util.HashMap;
publicclassDuplicateCharacter {
/**         * @param args         */ publicstaticvoid main(String[] args) { // TODO Auto-generated method stub
        String str = "Character duplicate word example java"; char ch1[]=str.toCharArray();         HashMap<Character,Integer> hm=new HashMap<Character,Integer>(); for(int i=0; i<ch1.length; i++)         { char ch=ch1[i];             hm.put(ch,(hm.get(ch)==null?1:hm.get(ch)+1));         }         System.out.println("No of Characters are : "+hm.toString());        }
}