JAVA EXAMPLE PROGRAMS

JAVA EXAMPLE PROGRAMS

Publish Your Article Here

Java Data Types

Java is a strongly typed language. Part of java's safety and robustness comes from this fact. You can broadly classify java primitive data types as given below:

Integers

Java defines 4 integer types. These include both positive and negative numbers.

Type Size Reference Example
byte 8 bits byte x,y,z;
short 2 bytes short x;
int 4 bytes int num;
long 8 bytes long millise;

Floating point numbers

Floating point numbers are very useful when we are evaluating expressions that require fractional precisions. Java defines 2 types of floating point numbers, they are float, and double.

Type Size Reference Example
float 4 bytes float percentage;
double 8 bytes double distance;

Characters

In java we store characters by using char data type. Size of character is 2 bytes.

Example:

char a='c';

Booleans

In java we use boolean for logical values, it can represent either true or false.

Example:

boolean isNumber=false;

Next Page: Variables

Knowledge Centre
Where can we use serialization?
Whenever an object has to sent over the network, those objects should be serialized. Also if the state of an object is to be saved, objects need to be serilazed.
Famous Quotations
I respect faith, but doubt is what gets you an education.
-- Wilson Mizner

About Author

I'm Nataraja Gootooru, programmer by profession and passionate about technologies. All examples given here are as simple as possible to help beginners. The source code is compiled and tested in my dev environment.

If you come across any mistakes or bugs, please email me to [email protected].

Most Visited Pages

Other Interesting Sites

Reference: Java™ Platform Standard Ed. 7 - API Specification | Java™ Platform Standard Ed. 8 - API Specification | Java is registered trademark of Oracle.
Privacy Policy | Copyright © 2022 by Nataraja Gootooru. All Rights Reserved.