Skip to main content

DATA TYPE AND OPERATOR IN JAVA



Data types in java:
            For storing different type of data we have data types. Java defines eight types of data: byte, short, int, long, float, double, char and boolean.

Integers:This group includes byte, short, int, and long, which are for signed and unsigned number including zero.
Floating-point numbers:This group includes float and double, which can store numbers with fractional precision.
Characters:This group includes char, which represents symbols in a characterset, like letters and numbers.
Boolean:This group includes boolean, which is a special type for representing true/false values.
NOTE: The data types mentioned above are primitive data types. Java also support reference data types like Array, Class and Interface.

1. Integers:

                        Java defines four integer types: byte, short, int, and long. All of these can have signed unsigned or zero value. Java does not support unsigned, positive-only integers.
Name    Width (in bits)        Range
long          64                           –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
int             32                            –2,147,483,648 to 2,147,483,647
short         16                            –32,768 to 32,767
byte          08                            –128 to 127
Note: Divide width with 8 to get size in Bytes; the table mentioned above is providing width and range of the integer data type. Width is the size the data type will occupy in the program if you write int a,b; than a and b both will occupy 32 bits (4 bytes) in memory.

1.1 byte

The smallest integer type is byte. This is a signed 8-bit type that has a range from –128 to 127
Ex. byte b1;
Variables of type byte are especially useful when we’re working with a stream of data from a network or file.

1.2 short

Short is a signed 16-bit type. It has a range from –32,768 to 32,767 so if you are sure that your value will not more than the range of Short data type than and only we recommended to use this.
Ex short s1,s2;

1.3 int

The most commonly used integer type is int. It is a signed 32-bit type that has a range from –2,147,483,648 to 2,147,483,647.
Ex.  int  a, b;

1.4 long

long is a signed 64-bit type and is useful for those occasions where an int type is not large enough to hold the desired value. The range of a long is quite large. This makes it useful when big, whole numbers are needed.

2. Floating-Point Types:

                                    Floating-point numbers, also known as real numbers, are used when evaluating expressions that require fractional precision.
For example, calculations such as square root, or transcendental such as sine and cosine, result in a value whose precision requires a floating-point type.
Name    Width in Bits          Approximate Range
double        64                           4.9e–324 to 1.8e+308
float            32                           1.4e-045 to 3.4e+038

2.1 float

            Float specifies a single-precision value that uses 32 bits of storage. Single precision is faster on some processors and takes half as much space as double precision, but will become imprecise when the values are either very large or very small. When you require to store floating point value use float and double.
Ex. float  r, pi;

2.2 double

                        Double precision, as denoted by the double keyword, uses 64 bits to store a value. Double
precision is actually faster than single precision on some modern processors that have been optimized for high-speed mathematical calculations.

3. Characters:

                        Data type used to store characters is char.

NOTE: However, C/C++ programmers beware: char in Java is not the same as char in C or C++. In C/C++, char is an integer type that is 8 bits wide. This is not the case in Java. Java uses Unicode to represent characters. Unicode defines a fully international character set that can represent all of the characters found in all human languages. In Java char require 16-bit. The range of a char is 0 to 65,536. There are no negative chars. The standard set of characters known as ASCII still ranges from 0 to 127. The extended 8- bit character set, ISO-Latin-1, ranges from 0 to 255. Since Java is designed to allow applets to be written for worldwide use, it makes sense that it would use Unicode to represent characters.

4. Boolean:

                        Java has a simple type, called boolean, for logical values. It can have only one of two possible values, true or false. This is the type returned by all relational operators, such as a < b.
Ex. boolean b; So here the value of b is either true or false.
Operator: It is a symbol that tells the computer to perform mathematical and logical calculation.
Java supports basically 6 types of operators.
1. Arithmatic operator
2. Bitwise operator
3. Relational operator
4. Boolean Logical operator
5. Assignment operator
6. Condetional operator

Selection Statements
If selection statements
Switch selection statement
Looping statements
Jump Statements



Anurag

Comments

Popular posts from this blog

JAVA Scrollbar, MenuItem and Menu, PopupMenu

ava AWT Scrollbar The  object  of Scrollbar class is used to add horizontal and vertical scrollbar. Scrollbar is a  GUI  component allows us to see invisible number of rows and columns. AWT Scrollbar class declaration public   class  Scrollbar  extends  Component  implements  Adjustable, Accessible   Java AWT Scrollbar Example import  java.awt.*;   class  ScrollbarExample{   ScrollbarExample(){               Frame f=  new  Frame( "Scrollbar Example" );               Scrollbar s= new  Scrollbar();               s.setBounds( 100 , 100 ,  50 , 100 );               f.add(s);   ...

Difference between net platform and dot net framework...

Difference between net platform and dot net framework... .net platform supports programming languages that are .net compatible. It is the platform using which we can build and develop the applications. .net framework is the engine inside the .net platform which actually compiles and produces the executable code. .net framework contains CLR(Common Language Runtime) and FCL(Framework Class Library) using which it produces the platform independent codes. What is the .NET Framework? The Microsoft .NET Framework is a platform for building, deploying, and running Web Services and applications. It provides a highly productive, standards-based, multi-language environment for integrating existing investments with next-generation applications and services as well as the agility to solve the challenges of deployment and operation of Internet-scale applications. The .NET Framework consists of three main parts: the common language runtime, a hierarchical set of unified class librari...

Standard and Formatted Input / Output in C++

The C++ standard libraries provide an extensive set of input/output capabilities which we will see in subsequent chapters. This chapter will discuss very basic and most common I/O operations required for C++ programming. C++ I/O occurs in streams, which are sequences of bytes. If bytes flow from a device like a keyboard, a disk drive, or a network connection etc. to main memory, this is called   input operation   and if bytes flow from main memory to a device like a display screen, a printer, a disk drive, or a network connection, etc., this is called   output operation . Standard Input and Output in C++ is done through the use of  streams . Streams are generic places to send or receive data. In C++, I/O is done through classes and objects defined in the header file  <iostream> .  iostream  stands for standard input-output stream. This header file contains definitions to objects like  cin ,  cout , etc. /O Library Header Files There are...