0

How i will run this piece of java code????

import java.io.Console;
import java.util.Arrays;

/**
 *
 * @author User
 *
 */

public class login{
    boolean authenticate(String u,char[] c){
        boolean x = false;
        if(u=="soumitra"&&c.toString()=="paas")
        {  x=true;}

        return x;

    }
public boolean login()

{int MAX_LOGINS=2;
  Console con = System.console();
  boolean auth = false;

  if (con != null)
  {
    int count = 0;
    do
    {
      String uname = con.readLine("Enter your username: ");
      char[] pwd = con.readPassword("Enter %s's password: ", uname);
      auth = authenticate(uname, pwd); // authenticate login info
      Arrays.fill(pwd, ' '); // delete password from memory
      con.writer().write("\n\n");  // output a couple of newlines
    } while (!auth && ++count < MAX_LOGINS);
  }
  return auth;
}
public static void  main(String args[]){
    login obj=new login();
    obj.login();

}
}

tried to run in Netbeansby rightclicking >>run....

got... run: BUILD SUCCESSFUL (total time: 0 seconds)

2
  • Possible duplicate of stackoverflow.com/questions/2159655/… Commented Aug 10, 2011 at 16:25
  • 1
    You shouls also have a look at java naming convention..good habit when learning. login should start as uppercase Commented Aug 10, 2011 at 16:35

3 Answers 3

1

assuming the code is in a file named login.java...

compile with:

javac login.java

should produce login.class, run with:

java login
Sign up to request clarification or add additional context in comments.

Comments

1

Oracle has a tutorial. Try this in a terminal:

  javac login.java
  java login

Comments

0

The Output window is typically also your console window. Try making your Output window visible.

For C++, there is an option in Netbeans for where Console should read from.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.