Câu hỏi phỏng vấn Strings
Câu hỏi

Why is char[] preferred o...

Câu trả lời

Here are a few reasons why char[] is preferred over String for storing passwords:

Security

  • Strings are immutable in Java, meaning once a String object is created, its value cannot be changed. This means the password remains in memory even after it's no longer needed.
  • Strings are also often cached by the JVM and can end up in various logs, dumps, etc. exposing the password.
  • char[] on the other hand can be overwritten with zeros after use, securely removing the password from memory.

Performance

  • Strings are more heavyweight objects compared to char arrays. Creating and destroying Strings has more overhead.
  • Strings ...
senior

senior

Gợi ý câu hỏi phỏng vấn

middle

Mentions some pros and cons of immutable vs mutable Strings

expert

When to use Ropes over StringBuilders?

expert

Compare Strings vs Ropes from the Performance Analysis

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào