Posts Tagged String

Utilizarea sirurilor de caractere in limbajul de programare C++

In limbajul de programare C++, un sir de caractere se defineste in doua moduri:

  • vector de caractere – zona de memorie de lungime prestabilita care se rezerva la momentul compilarii aplicatiei;
  • pointer – contine adresa de memorie unde se stocheaza sirul de caractere; de regula, aceasta zona de memorie este alocata la momentul executiei aplicatiei.

Read the rest of this entry »

, , ,

No Comments

How to convert a byte array to a Hex String in Java

When processing binary values it is very difficult to read or to display them because any printing function generates a String value.  The problem with this approach is that not all byte values can be interpreted as a printable char (i.e. the 0 binary value represents the NUL symbol; for more details check ASCII Codes + HTML Codes and Special Characters) and the resulting String will not contain all the byte values or it will not be accurate. Moreover in Java a char is stored on 2 bytes.

In this post we will see how to convert a byte array to a Hex String in a Java application. The solution is useful because:

  • printing binary values in base 2 or base 10 format can become difficult to read as the value can have multiple digits;
  • is easier to read values in hexadecimal base;
  • it is easier to check or compare values in hexadecimal base.

Read the rest of this entry »

,

1 Comment

Tutorial Java SCJP – #12 Immutable, String and Integer

Immutable objects are objects that don’t change their value once they are created. The most known immutable object in Java is String. Besides String, there is another immutable object, and this is Integer (the class and not the primitive) which has an interesting behavior for values between -128 and 127 . Read the rest of this entry »

,

3 Comments

Tutorial Java SCJP – #11 How to use String, StringBuilder and StringBuffer

The most used data types for variables in any programming language are boolean values, numeric primitive values and “strings” (or arrays) of characters. In contrast with C or C++, in Java handling strings is different because:

  • in Java every char is a 16 bit Unicode value, and not 1 byte;
  • in Java, strings values are managed by String objects;
  • in Java, the syntax allows you to use Strings as primitive data types (you can use = operator to initialize them)
  • in Java, Strings are immutable objects, meaning that once are created, they can’t change their value.

Read the rest of this entry »

,

3 Comments