The behavior of the objects of the StringBuilder class is different from that of String objects as regards their modification. String objects are immutable, so each time you perform an operation that changes the, value, a new object with the new value is created, while the original doesn’t change.… (Read the full article)
Category Archives: OCAJP7
Java OCAJP7: modifica di oggetti StringBuilder
Il comportamento degli oggetti della classe StringBuilder è diverso da quello degli oggetti String per quanto riguarda la loro modifica. Gli oggetti String sono immutabili, per cui ogni volta che si esegue un’operazione di modifica su di essi, viene creato un nuovo oggetto con il nuovo valore,… (Read the full article)
Java OCAJP7: boolean variable initialization
In Java is possible to initialize a boolean variable during its declaration with the result of an expression evaluation. For example we can use the result of two integer literals comparison to initialize our boolean variable.
public class JavaCertification { public static void main(String[] args)… (Read the full article)
Java OCAJP7: String indexOf method
There are four overloaded version of the indexOf method in the class String:
- public int indexOf(int ch)
- public int indexOf(int ch, int fromIndex)
- public int indexOf(String str)
- public int indexOf(String str, int fromIndex)
The two versions that define a second parameters use it as the index from … (Read the full article)
Java OCAJP7: variables name
In Java a variable identifier must follow the following rules:
- Must start with a letter, a ‘$’ or an ‘_’
- Cannot start with a number
- After the first characters can appear letters, numbers, underscores or ‘$’
The following snippet gives an edge case of variable… (Read the full article)
Java OCAJP7: array initialization
Let’s take a look at this simple snippet that could hide a trap:
public class JavaCertification { public static void main(String [] args) { int a[] = {1, 2, 3, 4, }; System.out.println("Number of elements: " + a.length); } }
We see that in the initialization of the array there is an extra comma after… (Read the full article)
Java OCAJP7: Tutto su String, StringBuilder, uguaglianza fra stringhe e Java String Pool
In Java le stringhe possono essere rappresentate tramite oggetti della classe String oppure oggetti delle classi StringBuilder e StringBuffer. La differenza tra queste ultime due risiede nel fatto che StringBuilder non è thread-safe mentre StringBuffer lo è. StringBuilder offre quindi performance… (Read the full article)