String class methods

String class methods

List of methods which present in String class.

1. char charAt(int index)
return character from the specified index position.
2. int compareTo(Object o)
Compare string with another object.
3. int compareTo(String anotherString)
Compare two strings and return integer output
1 means first string is greater than second string,  -1 means first string is less than second string, 0 means both strings are equal.
4. int compareToIgnoreCase(String str)
compare two string with case insensitive.
5. String concat(String str)
concat two strings.
6. boolean contentEquals(StringBuffer sb)
return true if and only if the sequence of string is same as the specified string buffer.
7. boolean endsWith(String suffix)
return true if string ends with specified suffix.
8. boolean equals(Object anObject)
Compare the string with specified object.
9. boolean equalsIgnoreCase(String anotherString)
Compare the string with another string with case insensitive.
10. byte getBytes()
Encode the string in sequence of byte.
11. int hashCode()
return the hash code for the string.
12. int indexOf(int ch)
return index position of first occurrence of specified character.
13. int indexOf(int ch, int fromIndex)
return index position of first occurrence of specified character start from specified index.
14. int indexOf(String str)
return index of first occurrence of specified string.
15. int lastIndexOf(int ch)
return index of last occurrence of specified characters.
16. int length()
return the length of string.
17. boolean matches(String regex)
return true when string matches with given regular expression.
18. String replace(char oldChar, char newChar)
replacing all all character with new character in a string.
19. String replaceAll(String regex, String replacement)
replace each substring of string which matches with given regular expression from new string.
20. String[] split(String regex)
split string around matches of given regular expression.
21. String trim()
return string omitted leading and trailing white spaces.
22. String toUpperCase() 
Convert all the characters of a string in upper case.
23. String toString()
Conversion of object in to string.
24. String substring(int beginIndex)
return substring from the string start from specified index.
25. String substring(int beginIndex, int endIndex)
return substring from the string from specified start and end index.

What is the Difference between Method overloading and Overriding ?

What is the Difference between Method overloading and Overriding ?

Method Overloading :

Method overloading is the example of compile time polymorphism.

Some of the limitation in Java when we are declare the method within the class. We can't declare two methods in a class which have same name and signature and parameters.

So that we can overload such method by following process :

We can use same method name for both the methods but we are required to pass the parameters different to those methods.

It depends on type of argument, No. of argument, Sequence of argument.

Method Overriding :

Method overriding is performed in such case when we have two different classes and they are linked each other through Inheritance.

Both the classes contains method which have same name, signature and Argument.
What is the difference between Error and Exception in Java ?

What is the difference between Error and Exception in Java ?

Error :

It is Generated at compile time and reported by program at compile time only. They are like as missing some of the symbols which are required as per java programming.

Some of the statement which are showing declaration error, missing semicolon (;) error etc.

Exception : 

If the error which is generated at the time of run time which is called Exception. Exception are not the programming error. They generated due to input provided at run time and depends on the inputs only.

If sometime we can see the FileNotFoundException which is generated at run time because compile time doesn't check the content which we provided to program.
Getting started with PrimeFaces.

Getting started with PrimeFaces.

PrimeFaces is a lightweight library with one jar, zero-configuration and no required dependencies. You just need to download PrimeFaces, add the primefaces-{version}.jar to your classpath and import the namespace to get started.

  1. <html xmlns=""  
  2.     xmlns:h=""  
  3.     xmlns:f=""  
  4.     xmlns:p="">  
  6.     <h:head>  
  8.     </h:head>  
  10.     <h:body>  
  12.         <p:spinner />  
  14.     </h:body>  
  15. </html>  
How to apply rating bar in android

How to apply rating bar in android

Step 1 :

Put below code in your layout file :

<RatingBar    android:id="@+id/ratingBar"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:layout_gravity="center"    android:numStars="5"    android:progressTint="@android:color/holo_orange_light"    android:layout_marginTop="10dp"    android:stepSize="1.0"    android:rating="0" />

here define the components which we are used :

ratingBar - id of RatinBar Component.

numStars - how many starts which you show for rating

progressTint  - Color of starts when we select for rating.

stepSize - when we click one time how may count we measure.

rating  - initial rating which we show on rating bar.

When we are using this RatingBar in Activity class so following methods are useful.

setRating - for any rating.

getRating  - get the current rating from the RatingBar.
Android back button event with example

Android back button event with example

Android device back button is to navigate from current activity to previous activity. In that case we are using below code for handing event on back button.

Declare variable in class :

1. boolean doubleBackToExitPressedOnce = false;

2. put code after onCreate method on an activity.

 public void onBackPressed() {
        if (doubleBackToExitPressedOnce) {

        this.doubleBackToExitPressedOnce = true;
        Toast.makeText(this, "Please click BACK again to exit", Toast.LENGTH_SHORT).show();

        new Handler().postDelayed(new Runnable() {

            public void run() {
                doubleBackToExitPressedOnce = false;
        }, 2000);