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
What is adapter class?
An adapter class provides the default implementation of all methods in an event listener interface. Adapter classes are very useful when you want to process only few of the events that are handled by a particular event listener interface. You can define a new class by extending one of the adapter classes and implement only those events relevant to you.
Famous Quotations
Insanity: doing the same thing over and over again and expecting different results.
-- Albert Einstein

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.