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.



 

14 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
  7. nice blog.java is one of the most programming language. It is very useful for learn.You can also read: Java Training

    ReplyDelete
  8. Usually I never comment on blogs but your article is so convincing that I never stop myself to say something about it. This paragraph gives clear idea for the new viewers of blogging, Thanks you. You’re doing a great job Man, Keep it up.
    Java Training in Noida

    ReplyDelete
  9. It is very good blog and useful for students and developer,Thanks for sharing


    Core Java Online Training

    ReplyDelete
  10. great blog,thank you for providing such a excellent information..keep sharing more..
    java training
    java training in Hyderabad

    ReplyDelete
  11. The information which you have provided is very good. It is very useful who is looking for Java online training Bangalore

    ReplyDelete
  12. Thanks for sharing this valuable post with us.

    Java Training in Gurgaon

    ReplyDelete
  13. I believe there are many more pleasurable opportunities ahead for individuals that looked at your site.
    Java training in chennai

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...