// if s is null, Java won't try to test the length of s if ( s != null && s.length() > 0 ) { out.println( "non empty string" ); }