AgerNic.com
WEB DEVELOPER SITE, HTML, CSS, PHP, SQL
HTML Tutorial

Java Type Casting


Java Tutorial » Java Type Casting

Converting the value of one data type as int, long, float, double, etc. to another data type named typecasting.
There are 13 types of type conversion in Java

In this tutorial, we target on the major 2 types.
1. Widening Type Casting - (automatically) - converting a smaller type to a larger type size
2. Narrowing Type Casting - (manually) - converting a larger type to a smaller size type

Widening Type Casting


Example: Converting int to double
public class Main {
public static void main(String[] args) {
// create int type variable
int my_number = 24;
System.out.println("The integer value of my number is: " + my_number);

// convert into double type
double data = my_number;
System.out.println("The double value of my number: " + data);
}
}
Output:
The integer value of my number is: 24
The double value of my number: 24.0


Narrowing Type Casting


Example: Converting double into an int
public class Main {
public static void main(String[] args) {
// create double type variable
double my_number = 24.98;
System.out.println("The double value of my number: " + my_number);

// convert into int type
int data = (int)my_number;
System.out.println("The integer value of my number: " + data);
}
}
Output:
The double value of my number: 24.98
The integer value of my number: 24


Converting the value of one data type (short, char, int , float , double , etc.) to another data type is known as typecasting.

Java Type Casting objects, string to int, example, rules, double to int, parent to child, syntax, object, error
Java Type Casting - java

Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


0
Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


HTML Image tag, code...
How to code in HTML...
HTML text tag...
HTML text, how to display...
Container responsive styles...
HTML container tag...
HTML container...
Send forgot password by mail or message ...
PHP MySQL simple login system...
Check for duplicate username live or ema...
How to create simple search engine using...
Diseño de sitio web CSS Layout...
Diseño de caja flexible CSS3...
Botones en CSS...
ID y Clase, Diferencias entre Class e Id...
Esquina redondeada CSS...
Tamaño de caja css box-sizing: border-b...
Alineación CSS...
Altura y Anchura CSS...
Bordes CSS...