Skip to main content

Posts

Showing posts from January, 2015

File searching in your system through in Java

File searching through java Input    : File Name and the directory to which searching Output : List of files Main Class : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 package com . rakesh . codetalk . fileSearch ; import java.io.BufferedReader ; import java.io.File ; import java.io.InputStreamReader ; import java.util.ArrayList ; /** * @author Rakesh KR * @since December 2K14 */ public class FileSearchBO { public static void main ( String argv []) throws Exception { FileSearchDTO fileSearchDTO = new FileSearchDTO (); FileSearchDAO fileSearchDAO = new FileSearchDAO (); BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in )); System . out . println ( "Enter the fileName to be searched : " ); fileSearchDTO . setFileNameToSearch ( br . readLine ()); System . out . println ( "Enter the dir

Compare Strings in JAVA

==  tests for reference equality. .equals()  tests for value equality. equals()  method is present in the  java.lang.Object  class and it is expected to check for the equivalence of the state of objects!. That means, the contents of the objects. Whereas the  ==  operator is expected to check the actual object instances are same or not. Example Consider two different reference variables  str1  and  str2   str1 = new String ( "abc" ); str2 = new String ( "abc" ); if you use the  equals() System . out . println (( str1 . equals ( str2 ))? "TRUE" : "FALSE" ); You will get the output as  TRUE if you use  == System . out . println (( str1 == str2 )? "TRUE" : "FALSE" ); Now you will get the  FALSE  as output because both  str1  and  str2  are pointing to two different objects even though both of them share the same string content. It is because of  new String()  everytime a new object is created.