Page 26 - JAVA Programming
P. 26
25
Java Strings
The String data type is used to store a sequence or array of characters
(text). But in Java, a string is an object that represents an array or
sequence of characters. The java.lang.string is the class is used for
creating a string object. String literals should be enclosed within
double-quotes. The difference between a character array and a string
is that in the string a special character ‘\0’ is present.
Java Arrays
An Array in Java is a single object which can store multiple values of
the same data type. Arrays are homogeneous data structures that store
one or more values of a specific data type and provide indexes to
access them. A particular element in an array can be accessed by its
index.
A two-step process of creating an array: Creating an array involves
two steps which are:
1. Array Declaration
2. Array Initialization
Java Objects
It is a basic unit of Object-Oriented Programming which represents the
real-world entities. An object is an instance of a class. It defines the
state and behaviour of real-life entities.
• State: It represents the attributes and properties of an object.
• Behaviour: Methods define the behaviour of an object. It also
reflects the communication of one object with the other objects.
• Identity: It gives a unique name to an object which allows one
object to interact with other objects.
For example, An object ‘Dog’ has states like name, breed, colour, size,
age, and functions like bark, eat, run, sit.