Data Type Java Tutorial

public class MainClass {
  public static void main(String[] args) {
    String s1 = "Java";
    String s2 = "Java";
    if (s1.equals(s2)) {
      System.out.println("==");
    }
  }
}
Sometimes you see this style.

if ("Java".equals (s1))
In the following code, if s1 is null, the if statement will return false without evaluating the second expression.

if (s1 != null && s1.equals("Java"))