ycliper

Популярное

Музыка Кино и Анимация Автомобили Животные Спорт Путешествия Игры Юмор

Интересные видео

2025 Сериалы Трейлеры Новости Как сделать Видеоуроки Diy своими руками

Топ запросов

смотреть а4 schoolboy runaway турецкий сериал смотреть мультфильмы эдисон
Скачать

✔ Java Data Type Conversions and Castings (Part 1) Programming Tutorial | (Video 131)

Автор: Rex Jones II

Загружено: 2020-08-24

Просмотров: 110

Описание: Java Data Type Conversions and Castings (Part 1)

► Free Selenium PDF Book: https://www.rexjones2.com/book-seleni...
► Free Java PDF Book: https://www.rexjones2.com/book-part-1...
► All Paperback & eBooks: http://tinyurl.com/Rex-Allen-Jones-Books

Social Media Contact
✔ YouTube    / rexjonesii  
✔ Twitter   / rexjonesii  
✔ LinkedIn   / rexjones34  
✔ GitHub https://github.com/RexJonesII/Free-Vi...
✔ Facebook   / jonesrexii  

► Download Code & Transcript via Website = https://www.rexjones2.com/part-1-data...
► Download Code & Transcript via GitHub = https://github.com/RexJonesII/Free-Vi...

► Transcript
In this session, let’s talk about Data Type Conversions and Data Type Casting. Both involve changing the Data Type from one data type to a different data type. However, the difference depends on their compatibility. A Data Type Conversion happens automatically with compatible data types. If the data types are then we must apply a Data Type Casting. We are not changing the value but only converting the value.

In Eclipse, let’s start with a Data Type Conversion which can also be called // Widening Conversion. Widening Conversion is when a smaller data type is converted to a larger data type. It gets wide from small to large. For numeric data types, the precision goes from byte, short, int, long, float, double. Byte is the smallest numeric data type and double is the largest data type. If our data types are from left to right then the compiler automatically convert the types.

2 things must happen for an automatic conversion. Both data types must be compatible and the destination type must be larger than the source type. Look what happens when the destination is smaller. int destination = . int is a whole number and smaller than the source 34.56. 34.56 is a double. Therefore, the error message states “Type mismatch: cannot convert from double to int“. Let’s add a comment // Cannot Convert From double to int
Now, look what happens for the automatic conversion.

We write
int source1 = 34 / double destination1 = source1. source1 is smaller than destination1 because int has a lower precision than double. Let’s print the values:
sysout(“Original (int) Value: ” + source1)
sysout(“Widening Conversion (int to double): ” + destination1) Let’s Run

Original (int) Value is 34 and Widening Conversion (int to double) is 34.0. The value on the right which is source1 automatically converted to the double data type destination1 on the left. So, we see 34.0

Next, is Data Type Casting which can also be called // Narrowing Conversion. This type of conversion happens when the destination type is smaller than the source type. We write double source2 = 34.999 / int destination2 = 34.999. This is the same error from last time: “Type mismatch: cannot convert from double to int“. We have to explicitly carry out the conversion by casting the data type. Casting takes place when we send an instruction to the compiler to convert the data type. The cast () always happen before the value. Therefore, we place int for int inside the parenthesis.

A person might think the value 34.999 will round up to 35 but that’s not true. It will convert to an int value. However, the decimal and 999 will cast off and not be shown. Let me change 34.999 to source2 and add some print statements. sysout(“-------”)
sysout(“Original (double) Value: ” + source2) /
sysout(“Narrowing Conversion (double to int): ” + destination2)

Let’s Run. Original (double) Value is 34.999. The Narrowing Conversion (double to int) cast off .999 and only show 34.

In the next video, I am going to convert an object to a variable and convert a String class to a numeric value. You can connect with me on LinkedIn, follow me on Twitter, and subscribe to my YouTube channel. See you next time.

#JavaDataTypeConversion #JavaDataTypeCasting #JavaTutorials #Java

Не удается загрузить Youtube-плеер. Проверьте блокировку Youtube в вашей сети.
Повторяем попытку...
✔ Java Data Type Conversions and Castings (Part 1) Programming Tutorial | (Video 131)

Поделиться в:

Доступные форматы для скачивания:

Скачать видео

  • Информация по загрузке:

Скачать аудио

Похожие видео

✔ Part 2: Java Data Type Conversions and Castings - Programming Tutorial | (Video 132)

✔ Part 2: Java Data Type Conversions and Castings - Programming Tutorial | (Video 132)

Python  - Полный Курс по Python [15 ЧАСОВ]

Python - Полный Курс по Python [15 ЧАСОВ]

Set and HashSet in Java - Full Tutorial

Set and HashSet in Java - Full Tutorial

Create a C# Application from Start to Finish - Complete Course

Create a C# Application from Start to Finish - Complete Course

Relax Your Soul and Boost Positivity ~ Deep Chill Music mix and Chill-out Ambient

Relax Your Soul and Boost Positivity ~ Deep Chill Music mix and Chill-out Ambient

⚡️Атака ВСУ под Санкт-Петербургом || Немедленная переброска войск

⚡️Атака ВСУ под Санкт-Петербургом || Немедленная переброска войск

Японец по цене ВАЗа! Оживляем пацанскую мечту :)

Японец по цене ВАЗа! Оживляем пацанскую мечту :)

4 Hours Chopin for Studying, Concentration & Relaxation

4 Hours Chopin for Studying, Concentration & Relaxation

Почему Путин не согласен

Почему Путин не согласен

I made the PC I couldn't buy

I made the PC I couldn't buy

© 2025 ycliper. Все права защищены.



  • Контакты
  • О нас
  • Политика конфиденциальности



Контакты для правообладателей: [email protected]