Need java help

import java.util.Scanner;

public class calc {
public static void main(String[] args){
Scanner ob=new Scanner(System.in);
System.out.println("Print username");


String name = ob.nextLine();
if(name == "luke"){
System.out.println("The Username is a correct");
}else{
System.out.println("Incorrect username");
}
System.out.println("Enter the value of a");
int a=ob.nextInt();

System.out.println(name);
System.out.println(a);

ob.close();
}
}

When i type in luke after it says "Print username"

it says "Incorrect username"

when it should say "The username is correct"

== does not really work on strings.

use something like .equals()

if (name.equals("luke")){

I'm also pretty noob so forgive me if this doesn't fix it.

http://pastebin.com/3CXkPCxt

Tech Noob is correct replace == with .equals()

that part drives me insane! C/C++/C# all allow == to work on strings. but nooooooo not java. but yeah, for comparing strings use .equals which i think is annoying

In C it is strcmp and friends...

That’s because in Java == is for object reference comparison.  String in Java is an Object, like everything else that is not a primitive.

When you use == to compare two String values, what you are asking is are these two Java Objects the same Object.  And unless you are comparing String literal values, or references to String literal values, this is false.  This behavior is consistent for all objects in Java whether they are SDK objects or user created objects.

You could argue that C# is the one that is inconsistent, since you can use == to compare string values, but you have to use .equal to compare other objects.

And C/C++ is the same as Java.  If you assign two char* variables to be the same string literal, then you can use ==. if you create new strings, then you cannot use ==.

In C++, if you use std::string, then you can use == to compare string values, but that is because of operator overloading.  std::string overloads the == operator, allowing you to compare two std::string values. 

If you want to use == to compare Java String values, you can.  You just have to intern all of the String values.  But if you forget to do it once, your whole comparison logic will be flawed.