0% found this document useful (0 votes)
9 views70 pages

Java Complete Notes

The JVM (Java Virtual Machine) enables platform-independent execution of Java programs by interpreting bytecode into native machine code. The document discusses two classes for handling strings: StringBuffer, which is thread-safe but slower, and StringBuilder, which is faster but not thread-safe. Additionally, it explains the concept of the String Constant Pool (SCP) and the importance of string immutability for maintaining data consistency.

Uploaded by

gourav.ojha.2141
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views70 pages

Java Complete Notes

The JVM (Java Virtual Machine) enables platform-independent execution of Java programs by interpreting bytecode into native machine code. The document discusses two classes for handling strings: StringBuffer, which is thread-safe but slower, and StringBuilder, which is faster but not thread-safe. Additionally, it explains the concept of the String Constant Pool (SCP) and the importance of string immutability for maintaining data consistency.

Uploaded by

gourav.ojha.2141
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

The JVM (Java Virtual Machine) is an abstract machine

that runs Java programs, enabling them to be platform-


independent ("Write Once, Run Anywhere") by
interpreting compiled Java bytecode into native machine
code for any operating system
Scanned with
class array string interface enum collectors
ECG3
StringBuffer ClassStringBuffer is a class that allows us to create
and modify a flexible, expandable sequence of characters. It is
thread-safe. Thismeans that it can be safely used when multiple
threads are accessing or modifying the string concurrently. But
due to synchronization, it is slower than StringBuilder.

StringBuilder ClassStringBuilder is similar to StringBuffer,


but it is not synchronized. Thismeans it is not thread-
safe. But it is much faster than StringBuffer and is
suitable for use in scenarios where thread safety is not
required (e.g., competitive coding, interview questions).

Java stores frequently used string literals in a special


memory area called the "String Constant Pool" (SCP) to
save heap space and improve performance. If strings were
mutable, a change made through one reference would
affect all other references pointing to the same object in the
pool, leading to unpredictable behavior and data
corruption. Immutability guarantees that shared objects
remain consistent.

You might also like