Biến (variable) trong Java
Biến (variable) là một vùng nhớ trong máy tính dùng để lưu trữ giá trị (thường lưu trữ trên RAM máy tính). 
 
Cú pháp khai báo biến (declare variable syntax)
data_type variable_name = value; 
Trong đó: 
	data_type: kiểu dữ liệu của biến 
	variable_name: tên biến 
	value: giá trị của biến 
 
Ví dụ: 
// Khai báo 3 biến tên "a", "b", "c"
// - Có kiểu dữ liệu số nguyên int
// - Không có giá trị ban đầu
int a, b, c;
// Khai báo 2 biến tên "diem_lt", "diem_th"
// - Có kiểu dữ liệu số nguyên int
// - Có gán giá trị ban đầu
int diem_lt = 10, diem_th = 3;
// Khai báo biến tên "B"
// - Có kiểu dữ liệu byte
// - Có giá trị ban đầu
byte B = 22;
// Khai báo biến tên "kytu"
// - Có kiểu dữ liệu char
// - Có giá trị ban đầu
char kytu = 'c'; 
 
Quy tắt đặt tên biến (variable's name rule)
Tên biến cần tuân theo các quy tắt sau: 
	- Không bắt đầu bằng số.
 
	- Không chứa các ký tự đặc biệt như (!@#$%^&*()+-*/...).
 
	- Không đặt tên trùng với các từ khóa (keywords) của java.
 
	- Phân biệt HOA thường.
 
 
 
Các từ khóa trong Java (java keywords)
| Sr.No | 
Reserved Words & Description | 
 
| 1 | 
abstract
 As per dictionary, abstraction is the quality of dealing with ideas rather than events. 
 | 
 
| 2 | 
assert
 assert keyword is used in Java to define assertion. An assertion is a statement in Java which ensures the correctness of any assumptions which have been done in the program. 
 | 
 
| 3 | 
boolean
 boolean datatype is one of the eight primitive datatype supported by Java. It provides means to create boolean type variables which can accept a boolean value as true or false. 
 | 
 
| 4 | 
break
 The break statement in Java programming language has the following two usages − 
	- 
When the break statement is encountered inside a loop, the loop is immediately terminated and the program control resumes at the next statement following the loop. 
 
	- 
It can be used to terminate a case in the switch statement. 
 
 
 | 
 
| 5 | 
byte
 byte datatype is one of the eight primitive datatype supported by Java. It provides means to create byte type variables which can accept a byte value. 
 | 
 
| 6 | 
case
 case keyword is part of switch statement which allows a variable to be tested for equality against a list of values. 
 | 
 
| 7 | 
catch
 An exception (or exceptional event) is a problem that arises during the execution of a program. 
 | 
 
| 8 | 
char
 char datatype is one of the eight primitive datatype supported by Java. 
 | 
 
| 9 | 
class
 Java is an Object-Oriented Language. As a language that has the Object-Oriented feature. 
 | 
 
| 10 | 
const
 final keyword is used to define constant value or final methods/classes in Java. 
 | 
 
| 11 | 
continue
 The continue keyword can be used in any of the loop control structures. 
 | 
 
| 12 | 
default
 default keyword is part of switch statement which allows a variable to be tested for equality against a list of values. 
 | 
 
| 13 | 
do
 A do...while loop is similar to a while loop, except that a do...while loop is guaranteed to execute at least one time. 
 | 
 
| 14 | 
double
 double datatype is one of the eight primitive datatype supported by Java. 
 | 
 
| 15 | 
if
 An if statement can be followed by an optional else statement, which executes when the Boolean expression is false. 
 | 
 
| 16 | 
enum
 The Java Enum class is the common base class of all Java language enumeration types. 
 | 
 
| 17 | 
extends
 extends is the keyword used to inherit the properties of a class. Following is the syntax of extends keyword. 
 | 
 
| 18 | 
final
 final keyword is used to define constant value or final methods/classes in Java. 
 | 
 
| 19 | 
finally
 finally keyword is used to define a finally block. The finally block follows a try block or a catch block. A finally block of code always executes, irrespective of occurrence of an Exception. 
 | 
 
| 20 | 
float
 float datatype is one of the eight primitive datatype supported by Java. It provides means to create float type variables which can accept a float value. 
 | 
 
| 21 | 
for
 A for loop is a repetition control structure that allows you to efficiently write a loop that needs to be executed a specific number of times. 
 | 
 
| 22 | 
goto
 goto statement is not supported by Java currrenly. It is kept as a reserved keyword for future. As an alternative, Java supports labels with break and continue statement. 
 | 
 
| 23 | 
if
 An if statement consists of a Boolean expression followed by one or more statements. 
 | 
 
| 24 | 
implements
 Generally, the implements keyword is used with classes to inherit the properties of an interface. 
 | 
 
| 25 | 
import
 import keyboard is used in context of packages. 
 | 
 
| 26 | 
instanceof
 instanceof keyword is an operator which is used only for object reference variables. 
 | 
 
| 27 | 
int
 int datatype is one of the eight primitive datatype supported by Java. 
 | 
 
| 28 | 
interface
 An interface is a reference type in Java. It is similar to class. It is a collection of abstract methods. 
 | 
 
| 29 | 
long
 long datatype is one of the eight primitive datatype supported by Java. 
 | 
 
| 30 | 
native | 
 
| 31 | 
new | 
 
| 32 | 
package
 Packages are used in Java in order to prevent naming conflicts, to control access, to make searching/locating and usage of classes, interfaces, enumerations and annotations easier, etc. 
 | 
 
| 33 | 
private
 Methods, variables, and constructors that are declared private can only be accessed within the declared class itself. 
 | 
 
| 34 | 
protected
 The protected access modifier cannot be applied to class and interfaces. 
 | 
 
| 35 | 
public
 A class, method, constructor, interface, etc. declared public can be accessed from any other class. 
 | 
 
| 36 | 
return | 
 
| 37 | 
short
 By assigning different data types to variables, you can store integers, decimals, or characters in these variables. 
 | 
 
| 38 | 
static
 The static keyword is used to create variables that will exist independently of any instances created for the class. 
 | 
 
| 39 | 
strictfp | 
 
| 40 | 
super
 The super keyword is similar to this keyword. 
 | 
 
| 41 | 
switch
 A switch statement allows a variable to be tested for equality against a list of values. 
 | 
 
| 42 | 
synchronized | 
 
| 43 | 
this
 this keyword is a very important keyword to identify an object. Following are the usage of this keyword. 
 | 
 
| 44 | 
throw
 If a method does not handle a checked exception, the method must declare it using the throws keyword. 
 | 
 
| 45 | 
transient
 Serialization is a concept using which we can write the state of an object into a byte stream so that we can transfer it over the network (using technologies like JPA and RMI). 
 | 
 
| 46 | 
try
 A method catches an exception using a combination of the try and catch keywords. 
 | 
 
| 47 | 
void | 
 
| 48 | 
volatile | 
 
| 49 | 
while
 A while loop statement in Java programming language repeatedly executes a target statement as long as a given condition is true. 
 | 
 
 
 
Kiểu dữ liệu nguyên thủy (primitive data types) trong Java
Trong Java cung cấp các kiểu dữ liệu nguyên thủy (primitive data types) - mà có thể làm nền tảng để kết hợp thành các kiểu dữ liệu phứt hợp sau này như sau: 
	- byte
 
	- short
 
	- int
 
	- long
 
	- float
 
	- double
 
	- boolean
 
	- char
 
 
Nhóm kiểu dữ liệu số nguyên
1. Kiểu dữ liệu (data type)  byte trong Java
	- Là số nguyên có độ dài 8-bit.
 
	- Min value: 
-128 (-2^7) 
	- Max value: 
127 (2^7 - 1) 
	- Default value: 
0 
	- Ví dụ:
 
 
byte a = 100;
byte b = -33; 
  
2. Kiểu dữ liệu (data type)  short trong Java
	- Là số nguyên có độ dài 16-bit.
 
	- Min value: 
-32,768 (-2^15) 
	- Max value: 
32,767 (2^15 - 1) 
	- Default value: 
0 
	- Ví dụ:
 
 
short a = 10000;
short b = -20000; 
3. Kiểu dữ liệu (data type)  int trong Java
	- Là số nguyên có độ dài 32-bit.
 
	- Min value: 
-2,147,483,648 (-2^31) 
	- Max value: 
2,147,483,647 (2^31 - 1) 
	- Default value: 
0 
	- Ví dụ:
 
 
int tong_so_luong = 230000000;
int b = -22222222; 
4. Kiểu dữ liệu (data type)  long trong Java
	- Là số nguyên có độ dài 64-bit.
 
	- Min value: 
-9,223,372,036,854,775,808 (-2^63) 
	- Max value: 
9,223,372,036,854,775,807 (2^63 - 1) 
	- Default value: 
0L 
	- Ví dụ:
 
 
long a = 1000000000L;
long b = -20000000L; 
Nhóm kiểu dữ liệu số thực
5. Kiểu dữ liệu (data type)  float trong Java
	- Là số thực có độ dài 32-bit.
 
	- Min value: 
1.4E^-45f 
	- Max value: 
3.4028235^+38f 
	- Default value: 
0 
	- Ví dụ:
 
 
float diem_lt = 6.5f;
float gia_tien = 1999.99f; 
  
6. Kiểu dữ liệu (data type)  double trong Java
	- Là số thực có độ dài 64-bit.
 
	- Min value: 
4.9^-324d 
	- Max value: 
1.79769313486231570^+308d 
	- Default value: 
0 
	- Ví dụ:
 
 
double thanh_tien = 125000000.964535d; 
Nhóm kiểu dữ liệu Logic (đúng/sai)
7. Kiểu dữ liệu (data type)  bool trong Java
	- Có độ dài 1-bit.
 
	- Chỉ bao gồm 2 giá trị: 
true hoặc false 
	- Default value: 
false 
	- Ví dụ:
 
 
bool da_dang_nhap = false;
bool co_hoa_don = true; 
Nhóm kiểu dữ liệu Ký tự (characters)
8. Kiểu dữ liệu (data type)  char trong Java
	- Có độ dài 1 ký tự unicode 16-bit.
 
	- Min value: 
\uffff 
	- Max value: 
\u0000 (0) 
	- Default value: 
\u0000 
	- Ví dụ:
 
 
char kytu = 'c';
char letter = '\u0051';
System.out.println(letter);
char letter1 = '9';
System.out.println(letter1);
        
char letter2 = 65;
System.out.println(letter2);
9. Kiểu dữ liệu (data type) bỗ trợ xâu chuỗi  String trong Java
	- Trong Java có hỗ trợ kiểu dữ liệu tập hợp xâu các chuỗi: 
java.lang.String 
	- Default value: 
"" 
	- Ví dụ:
 
 
String hoten = "Duong Nguyen Phu Cuong";
String diachi = "123 Ly Tu Trong, Quan Ninh Kieu, TP Can Tho"; 
  
  
  
  
  
  
  
  
                       |