Pages

JAVA

How to generate a random alpha-numeric string?

code for secure, easy

This works by choosing 130 bits from a cryptographically secure
random bit generator, and encoding them in base-32. 128 bits is
considered to be cryptographically strong, but each digit in a
base 32 number can encode 5 bits, so 128 is rounded up to the next
multiple of 5. This encoding is compact and efficient, with 5 random
bits per character. Compare this to a random UUID, which only has 3.4
bits per character in standard layout, and only 122 random bits in
total.
If you allow session identifiers to be easily guessable (too short,
flawed random number generator, etc.), attackers can hijack other's
sessions. Note that SecureRandom objects are expensive to initialize, so you'll want to keep one around and reuse it.

What is Difference between == operator and .equals() ?

== tests for reference equality (whether they are the same object)..equals() tests for value equality (whether they are logically "equal").
Consequently, if you want to test whether two strings have the same value you should use .equals().// These two have the same valuenew String("test").equals("test") // --> true

// ... but they are not the same objectnew String("test") == "test"// --> false

BUY ME A COFFEE

Follow by Email

Hi! Thank you

Hi! Thank you everyone who reading my article. My major is algorithms & programming. Right now I am working in India. I will like sharing to everyone with my works and if you do interesting with my works, please leave you comment on my blog. Any comments is welcoming.