java how to use max method

java.lang.Math;

int mx = Math.max(2, 3) // return 2

March 7, 2010 Posted Under: Uncategorized   Read More

java how to find array length

String[] mystr = {"c++", "java", "php"}
 
int leng = mystr.length
 
System.out.format("The Java array length is %d", leng);
March 7, 2010 Posted Under: Java   Read More

Java Generating random numbers

Generating random numbers is simple. Provided as part of the java.util package, the Random class makes it easy to generate numbers. Start by creating an instance of the Random class

// Create an instance of the random class
Random r = new Random();

Now, you must request a number from the generator. Supposing we wanted an integer number, we’d call the nextInt() method.

// Get an integer
int number = r.nextInt();

Often you’ll want numbers to fall in a specific range (for example, from one to ten). We can use the modulus operator to limit the range of the numbers. This will give us the remainder of the number when divided by ten (giving us a range -9 to +9). To eliminate negative numbers, if the number is less than one we’ll add ten to it. This gives us random numbers between one and ten!

// Accept only up to ten
int random_number = number % 10;
if (random_number < 1) random_number = random_number + 10;

Creating random numbers in an application or applet really isn’t that difficult. Just remember to limit the range of your numbers, and to import the java.util.Random class.

March 6, 2010 Posted Under: Java   Read More

Generating random numbers in Java

you need header

java.util.Random;Random diceRoller = new Random();

 for (int i = 0; i < 10; i++) { int roll = diceRoller.nextInt(6) + 1; System.out.println(roll); 

} 

March 6, 2010 Posted Under: java random number   Read More

How to create root user password in MySql

1) kill your mysqld

2) mysqld_safe –skip-grant-table

3) login as:   mysql  –user=root mysql

4) update mysql.user set password=PASSWORD(‘new-pass’) WHERE User=’root’;

5) flush privileges;

6) exit;

you are done!

August 2, 2009 Posted Under: mysql   Read More

How to use strace on linux

strace -f -o my.x  app

October 24, 2008 Posted Under: strace on linux   Read More

How to add new user in MySql

login as root:

>mysql  -u root -p

>*******

mysql>GRANT ALL PRIVILEGES ON *.* TO 'cooluser'@'localhost'

             IDENTIFIED BY 'some_pass' WITH GRANT OPTION;

October 7, 2008 Posted Under: mysql   Read More

find out the size of directory in Linux

what command to use to find out the size of directory in linux?

//assume u want to know the size of mydir

du -h  mydir | grep mydir$

October 5, 2008 Posted Under: linux command   Read More

Emacs Tutorial for beginning!

C-x C-f open a new file

C-x C-s save the current file
C-x C-c exit the emacs (but save files first)

#command line Emacs

emacs -nc

#Open Split Horizonal Window

Ctrl-2

#Open Split Veritcal Window

Ctrl-3

#Maximize Window

Ctrl-0 

September 30, 2008 Posted Under: Emacs commands   Read More

How to start Emacs in console mode?

Here is the command to start Emacs in mode! since emacs has the worst font!

 in console,

emacs -nc

September 30, 2008 Posted Under: emacs in console mode   Read More