JAVA

JAVA

S.P

Primitive and reference types

The new keyword

In most cases, an object of a reference type can be created using the new keyword.
String language = new String("java");


Comparisons

So, you do not need to use comparison operators when you want to compare the values. The correct way to compare content is to invoke the special method equals.

String s1 = new String("java");
String s2 = new String("java");
String s3 = s2;
System.out.println(s1.equals(s2)); // true
System.out.println(s2.equals(s3)); // true


Array

In Java, an array has the following important features:

  • an array is a reference type;
  • all array's elements are stored in the memory sequentially ;
  • each element of the array is accessed by its numerical index, the first element has the index 0;
  • the last element is accessed by the index equal to array size - 1;
  • it is possible to create an array to store elements of any type.

int[] array; // declaration's form 1
int[] numbers = { 1, 2, 3, 4 }; // an array of 1, 2, 3,
int n = ...; // n is a length of an array





Report Page