Java Tutorials
Java BufferedReader: How to Read File in Java with Example
How to read a file in Java? Java provides several mechanisms to read from File. The most useful...
Variable in Java is a data container that stores the data values during Java program execution. Every variable is assigned data type which designates the type and quantity of value it can hold. Variable is a memory location name of the data. The Java variables have mainly three types : Local, Instance and Static.
In order to use a variable in a program you to need to perform 2 steps
In this tutorial, you will learn-
To declare a variable, you must specify the data type & give the variable a unique name.
int a,b,c; float pi; double d; char a;
To initialize a variable, you must assign it a valid value.
Example of other Valid Initializations are
pi =3.14f; do =20.22d; a=’v’;
You can combine variable declaration and initialization.
There are 8 primitive types: byte, short, int, long, char, float, double, and boolean Integer data types
byte (1 byte) short (2 bytes) int (4 bytes) long (8 bytes)
char (2 bytes)
Logical
boolean (1 byte) (true/false)
| Data Type | Default Value | Default size |
|---|---|---|
| byte | 0 | 1 byte |
| short | 0 | 2 bytes |
| int | 0 | 4 bytes |
| long | 0L | 8 bytes |
| float | 0.0f | 4 bytes |
| double | 0.0d | 8 bytes |
| boolean | false | 1 bit |
| char | '\u0000' | 2 bytes |
Points to Remember:
A variable of one type can receive the value of another type. Here there are 2 cases -
Case 1) Variable of smaller capacity is be assigned to another variable of bigger capacity.
This process is Automatic, and non-explicit is known as Conversion
Case 2) Variable of larger capacity is be assigned to another variable of smaller capacity
How to read a file in Java? Java provides several mechanisms to read from File. The most useful...
Example#1: JavaScript Multiplication Table Create a simple multiplication table asking the user...
Training Summary Java is the most popular programming language & is the language of choice for...
What is OOPS? Object-Oriented Programming System (OOPs) is a programming concept that works on the...
Java has had several advanced usage application including working with complex calculations in...
Following is a step by step guide to download and install Eclipse IDE: Step 1) Installing Eclipse Open...