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
Transient and Volatile Modifiers
Transient: The transient modifier applies to variables only and it is not stored as part of its object's Persistent state. Transient variables are not serialized.

Volatile: Volatile modifier applies to variables only and it tells the compiler that the variable modified by volatile can be changed unexpectedly by other parts of the program.
Famous Quotations
Before you go and criticize the younger generation, just remember who raised them.
-- Unknown Author

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 © 2017 by Nataraja Gootooru. All Rights Reserved.