how to print the duplicate letters in a string?

on Thursday, July 17, 2014
Below Code may help you for this.

package general;

public class PrintDuplicateLetterInString {

public static void main(String[] args) {

//String ip="navneet";
String ip="aaaa";
char [] input = ip.toCharArray();
System.out.println("Duplicate Characters are as follows:");
for(int i=0;i<ip.length();i++)
{
for(int j=i+1;j<ip.length();j++)
{
if(input[i]==input[j])
{
System.out.println(input[j]);
break;
}
}
}


}

}

How to get operating system information in Java

on Wednesday, July 16, 2014
Below code may help you to get Operating System information:

               // it gives operating system info
String osname = System.getProperty("os.name");
System.out.println(osname);

// it gives all the information regarding system
Properties prop = System.getProperties();
                  Set<Object> keySet = prop.keySet();
                  for(Object obj : keySet){
                     system.out.println("System Property:                                                                                                            {"+obj.toString()+","+System.getProperty(obj.toString())+"}");

Can we compile a java file with a different name than the class

yes, we compile a java file with a different name than the class, provided that there should not be any public class in that file.

If there is any public class in file then in that case you have to give that name as file name. But if your class does not contain any public class then you can give any name to you class.

Please refer below example to make it more clear:

file name : sample.java

class A
{
   public static void main(String args[])
   {
      System.out.println("hi in Class A");
   }
}
class B
{
   public static void main(String args[])
   {
     System.out.println("hello in class B");
   }
}


then compile it with(windows) : javac sample.java

then run it : java A

output :  hi in Class A

then run it : java B

output :  hello in class B


Please check and confirm.

How to Get Current Date/ System Date(sysdate) in Java

In Java, you can get the current date time via following two classes: 
1. Date
2.Calendar
Moreover,  you can use SimpleDateFormat class to convert the date into user friendly format.

Please refer below code to understand it properly.

                1. Date with SimpleDateFormat Class

                DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
Date date = new Date();
String currentDate = dateFormat.format(date);
System.out.println(currentDate);

               2. Calendar with SimpleDateFormat Class

                DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
Calendar cal = Calendar.getInstance();
String currentDate=dateFormat.format(cal.getTime());
System.out.println(currentDate);

Also you can use the following code:

                 Calendar cal = null;
              String currentDate = "";
               cal = Calendar.getInstance();
               currentDate = javaCalendar.get(Calendar.DATE) +
                                      "/" + (javaCalendar.get(Calendar.MONTH) + 1) +
                                     "/" + javaCalendar.get(Calendar.YEAR);
 System.out.println(currentDate);

How to Avoid Displaying 'null' in jsp

Many a times it may happen that if data is coming as a null from the database then in that case if we simply set those value into bean without any check then we will get null on our jsp pages.

So in order to avoid those situations you can check for the values that are coming from the database and if those values are null then you can make them as an empty string.

Please look at the below example to make it more clear.

if(resultSet.getString("EMAIL_ID")!=null && !("".equalsIgnoreCase(resultSet.getString("EMAIL_ID"))))
{
          raiseTktDtlsBean.setEmailId(resultSet.getString("EMAIL_ID"));
}
else
{
         raiseTktDtlsBean.setEmailId(resultSet.getString(""));
}

Here, In the above code as you can see that if the column named EMAIL_ID contains null value for that record then in that case we have set empty string in the bean for displaying on the web page.

Like this you can do for the all the columns which contains null value.

How To Prevent Cut, Copy and Paste for Textbox in HTML

on Tuesday, July 15, 2014
For this simply you have to add below code:

for preventing copy:
oncopy="return false"

example:
<input type="textbox" name="password" id="password" oncopy="return false" />

for preventing cut:
oncut="return false"

example:
<input type="textbox" name="password" id="password" oncut="return false" />

for preventing paste:
onpaste="return false"

example:
<input type="textbox" name="password" id="password" onpaste="return false" />

How To Create Jar File in Eclipse

To Prevent From Throwing Null Pointer Exception

Always write string before the string variable while using equals function.
example:
if("".equals(variable))
rather than
if(variable.equals(""))

Here if the string variable is null then it will throw Null Pointer Exception.
So for best practice always write string before the string variable while using equals function.