* If you want to use a variable, you must specifically state its type. To declare a variable typeyou simply use the type followed by the name of the variable. Consider the following examples
isMale boolean ;
* You can also declare multiple variables of a type in a phrase like the following example:
Int age, yrsEmployed, numChildren ;
Allocation Variable Initialization and
* Once you have declared the type of a variable, you are free to initiate and allocating to it some value.
* Allocation initialization works and just as it did in Perl. You simply use a variable name = some value. For example, consider the following code :
age = 28 ;
* Of course, you can declare variables and assign values to them, at the same time, with the following syntax: < >
Int age = 28 ;
Casting (Change from one type to another)
* What happens if you want to multiply 2 x 1.5, or more generally, int x double ? Will the result be an int or a double or something ?
more * Well, if in doubt, Java converted to less restrictive type to be sure. Therefore, in the example above, the result will be a double-double since it is less restrictive .
* The following chart shows how the rates are chaste, if possible .
byte -> short -> int -> length -> float
* But what if it goes the other way? Suppose you have two doubles and you want to make a product int
* To make this kind of caste, you only have to perform a mission using the type to be caste in parentheses before the value that is caste. Consider the following example in which the caste of a double to a double :
int d = 123456;
int i = (int) * d ;
In this case, you will be assigned a value of “123 Strings “.
As you notice, in Java, there is no type of variable called chain. However, despite Java does not have a specific type, which provides a class called predefined string that you can use instead .
* We will talk more about the classes and use them in later sections. However, it would be nice to at least enter the string class here so we can use it in the meantime .
* For an instance of string, you just use the same syntax as you would if it were a :
type String s = “Hello cyberspace “;
* The channels have very few methods that allow you to manipulate all sentidosl. To read about these methods, simply use the online documentation. We will talk about how to make efficient use of the documentation theonline a little later, but you should know you can find it in the package java.lang .