java


run java code with System.console class


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)
assuming the code is in a file named login.java...
compile with:
javac login.java
should produce login.class, run with:
java login
Oracle has a tutorial.
Try this in a terminal:
javac login.java
java login
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.

Related Links

Checked or Unchecked Exception [duplicate]
java/groovy socket write timeout
Java tree classes
Is there the console function in Eclipse?
Java Hash Collection
How to make the output text attribute value as a hyperlink?
Parse Pdf File and write content in word file using java
How to initialize a value in web.xml from a JNDI variable?
Truncate String on closest word boundary
Java HTTP Snooper(Proxy) Does Not Forward Server Response
How to find unit tests not part of any suite?
Java Web Starter AMI
Using an enum as a mapkey results in a RAW in the database
call system text editor
Java code for getting current time
reusable condition/expression classes

Categories

HOME
minimum-spanning-tree
single-sign-on
hp-exstream
webstorm
youtube-dl
cross-browser
serverspec
podio
gitpitch
gnupg
spring-xd
mapserver
messages
event-handling
ghc
telephony
jsdoc
invantive-sql
apache-metamodel
excel-vba-mac
p-value
javacv
spark-jobserver
buck
opentype
ejabberd-module
procdump
delicious-api
exuberant-ctags
ioio
xmlreader
html5-fullscreen
revolution-slider
suricata
file-format
web-mining
serverside-rendering
g-code
nomethoderror
sencha-touch-2.3
google-datalayer
jsch
osx-mavericks
jquery-nestable
logparser
mu
aurelia-validation
recursive-datastructures
kbuild
knpmenubundle
qtwebview
gcsfuse
color-profile
blacklist
time-and-attendance
sts-springsourcetoolsuite
azure-virtual-network
thrust
ubuntu-10.04
revolution-r
uid
kendonumerictextbox
pervasive-sql
libressl
coveralls
service-accounts
nsight
notify
operator-precedence
applescript-objc
bitcoinj
jubula
terminal-services
geos
runtime.exec
ril
mylyn
hungarian-algorithm
jquery-mobile-dialog
hamiltonian-cycle
frameset
newtonscript
ocx
regsvr32
postgresql-performance
joyent
f#-powerpack
android-sdk-2.1
google-friend-connect
iweb
backcolor
virtual-functions
defensive-programming
zune
w3wp

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App