Sunday, December 23, 2018

Data types JAVA

Data types JAVA

Data types 

Java has two categories of data types, namely object-oriented data types and simple. Object-oriented data types defined by the class, while simple is the basic data types that are owned by as many as eight Java simple data types, known as primitive data types. The primitive data types are as follows:

This type of data
Information
boolean
Presenting the true / false value
byte
8-bit integer
char
Character
double
Double-precision floating-point
float
Single-precision floating-point
int
Integer (bil. Round)
long
Long Integer
short
Short integer

Data Type Integer

Java defines integer data types consisting of byte, short, int and long with each range of values ​​are the following:

Type
width bits
The range of values
byte
8
-128 to 127
short
16
-32.768 to 32,767
int
32
-2,147,483,648 to 2,147,483,647
long
64
-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

Integer Coding Examples JAVA:
1public class DataInteger {
2public static void main(String[] args){ long ci,im;
3im=5280 * 12;
4ci=im*im*im;
5System.out.println("Ada "+ci+" kubik inchi dalam mil kubik.");
6}
7}

Coding Examples JAVA
coding results of integer data types


Floating-Point Data Types

This data type in Java consists of float and double, each having a different bit width, the float (32 bit) and double (64-bit). Generally the double data type is often used by these functions in Java.

Examples of Floating-Point Coding JAVA:
1public class floatingPoint {
2public static void main(String args[]){ double x,y,z;
3x=8; y=5;
4z=Math.sqrt(x*x+y*y);
5System.out.println("Nilai Hypotenusa adalah " +z);
6}
7}

Floating-Point Coding JAVA
coding results of floating-point data types

Character Data Types

Unlike programming languages ​​other data type char with a width of 8-bit, but Java uses Unicode (characters used by many languages ​​in the world, for example arabic, starch, etc.) for each character of his, so the bit width of each character is 16 -bit.

Character Coding Examples JAVA:
1public class ContohChar {
2public static void main(String[] args){ char c;
3c='H';
4System.out.println("C berisi "+c); c++;
5System.out.println("Sekarang C berisi "+c); c=89;
6System.out.println("C berisi "+c);
7}
8}

Character Data Types
java coding results with data type character


Boolean Data Types

Boolean type presents a true / false value. JAVA Coding examples for the use of boolean type is as follows:
01public class ContohBoolean {
02public static void main(String[] args){ boolean b;
03b=true;
04System.out.println("b bernilai "+b); b=false;
05System.out.println("b bernilai "+b);
06if(b)
07System.out.println("b pasti bernilai true");
08else
09System.out.println("b pasti bernilai false");
10System.out.println("7 < 9 adalah "+(7 9));
11}
12}

Boolean Data Types
coding results using boolean type

Literals (constants)

Literal refers to a fixed rate that is served and can be understood by humans, such as the 100 or the character 'b' (enclosed in quotation marks, while a string enclosed in quotes). By default writing numbers in Java is an integer, but if you want a long type, use the literal L at the end of the number, eg 12L (12 long integer value).

Hexadecimal and Octal

Writing hex numbers start with 0x, for example 0x2F. For octal numbers begin with the number 0, for example 023.

Characters circuit Escape

For special characters outside of the standard characters, for example the character Carriage Return, Tab, Line Feed and forth using the symbol '\'.

Escape circuit
Information
\ '
single quote
\ "
Double quote
\\
backslash
\ r
carriage return
\ n
New line
\ f
Form feed
\ t
horizontal tabs
\ b
Backspace
\ ddd
Octal constant (where ddd is an octal constant)
\ uxxxx
Hexadecimal constant (where xxxx is a hexadecimal constant)

string Literal

Value strings in Java flanked by using quotation (quotation). 
Coding example JAVA String Literal:
1public class ContohStringLiteral {
2public static void main(String[] args){
3System.out.print("Ini merupakan baris pertama, kemudian disusul dengan \n baris kedua!\n");
4System.out.print("Contoh penggunaan \"backslash\" '\\'.\n"); System.out.print("Tabulasi Tab1\tTab2\tTab3");
5}
6}

string Literal
coding results with java string literals


Reviewer: FajarYusuf.Com
ItemReviewed: Data types JAVA

Seseorang yang ingin membagi pengalaman dan ilmu yang berguna untuk para pembaca FajarYusuf.Com :)

TENTANG SITUS

SITUS INI ADALAH SITUS PEMBELAJARAN PEMROGRAMAN DAN JUGA PEMAHAMAN TERHADAP TEKNOLOGI KOMPUTER. KALIAN BISA MENGIKUTI PEMBELAJARAN PEMROGRAMAN DENGAN BERTAHAP PADA MATERI YANG SUDAH SAYA SEDIAKAN, JIKA ADA MATERI YANG MEMBINGUNGKAN SILAKAN LAKUKAN KOMENTAR PADA MATERI YANG ANDA TANYAKAN ATAU KALIAN BISA MENGHUBUNGI SAYA DIHALAMAN KONTAK.