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 value

new String("test").equals("test") // --> true

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

// ... neither are these
new String("test") == new String("test") // --> false

// ... but these are because literals are interned by
// the compiler and thus refer to the same object

"test" == "test" // --> true


You almost always want to use.equals(). In the rare situation where you know you're dealing with interned strings, you can use ==.
 

Note: equals() exactly Compares this String to another String, BUT equalsIgnoreCase() Compares this String to another String, ignoring case considerations.



 

6 comments:

  1. I want to learn everything about Java and object oriented java all, Cheat Codes Let Me Hold You (Turn Me On)

    ReplyDelete
  2. Please how do i know where to embed various script or edit the script of a plugin to my taste. Thanks

    ReplyDelete
  3. One day i will be a bad a** Jscript programmer

    ReplyDelete
  4. I have read your blog its very attractive and impressive. I like it your blog.

    Java Training in Chennai Core Java Training in Chennai Core Java Training in Chennai

    Java Online Training Java Online Training Core Java 8 Training in Chennai Core java 8 online training JavaEE Training in Chennai Java EE Training in Chennai

    ReplyDelete
  5. Java Training Institutes Java Training Institutes Java EE Training in Chennai Java EE Training in Chennai Java Spring Hibernate Training Institutes in Chennai J2EE Training Institutes in Chennai J2EE Training Institutes in Chennai Core Java Training Institutes in Chennai Core Java Training Institutes in Chennai

    Java Online Training Java Online Training Java Online Training Java Online Training Java Online Training Java Online Training

    ReplyDelete
  6. How do I Zip Download the whole in the template without editing it

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...