Variables in Java | Java Variables - Java Tutorial 12
Notes for You:: Variables in Java.
- is a named memory location, whose value can change during the execution of a program.
- While developing any software application using Java; we come across different types of data and data values.
- In order to store and process different types of data & data values computer uses its memory (RAM).
- To allocate a chunk of memory and access it within a Java program, we need to declare a variable or a constant.
Declaring a variable or a constant:
- means allocating a memory location for some data.
Initializing a variable or a constant:
- means assigning the initial value to that allocated memory location.
Syntax for Declaring a variable in Java:
datatype nameOfVariable;
Example:
int playerScore;
int playerHealth;
Note:
- In Java, default value of a variable depends upon the type of a variable .
- byte (0) , short (0), int (0), long (0L),
- float (0.0f), double (0.0d)
- char (‘\0’)
- boolean (false)
- Any reference (null)
Note:
- Before using a local variable it has to be initialized or assigned with some meaningful value.
Syntax for Declaring and Initializing a variable:
datatype nameOfVariable = ivalue;
Example:
int playerScore = 0;
int playerHealth = 100;
Syntax for Assigning new value to a variable:
nameOfVariable = newvalue;
Example:
playerScore = 10;
playerHealth = 80;
Syntax for declaring multiple variables:
datatype nameOfVariable1, nameOfVariable2,...;
Example:
int playerScore, playerHealth;
Syntax for declaring & initializing multiple variables:
datatype nameOfVariable1 = ivalue, nameOfVariable2 = ivalue,…;
Example:
int playerScore=0, playerHealth=100;
Example Code:
package variablesdemo;
public class VariablesDemo {
public static void main(String[] args) {
/*
int playerScore;
int playerHealth;
System.out.println("player score = " + playerScore); // error
System.out.println("player health = " + playerHealth);// error
int playerScore=0;
int playerHealth=100;
System.out.println("player score = " + playerScore); // 0
System.out.println("player health = " + playerHealth);// 100
playerScore = 10;
playerHealth = 80;
System.out.println("player score = " + playerScore); // 10
System.out.println("player health = " + playerHealth);// 80
*/
int playerScore=0, playerHealth=100;
System.out.println("player score = " + playerScore); // 0
System.out.println("player health = " + playerHealth);// 100
playerScore = 30;
playerHealth = 70;
System.out.println("player score = " + playerScore); // 30
System.out.println("player health = " + playerHealth);// 70
}
}
=========================================
Follow the link for next video:
Java Tutorial 13 - Constants in Java Programming Language | Java Constants
https://youtu.be/qzmBbClw7KE
Follow the link for previous video:
Java Tutorial 11 - Identifiers in Java Programming Language | Java Naming Conventions
https://youtu.be/OQIfLSEy32Q
=========================================
Java Tutorials Playlist:-
https://www.youtube.com/playlist?list=PLdE8ESr9Th_u63vtOQVdMoPVNalhE_xf3
=========================================
Watch My Other Useful Tutorials:-
C++ Tutorials Playlist:
https://www.youtube.com/playlist?list=PLdE8ESr9Th_tVr76LjgBWBgSpQbCYn0tq
C# Tutorials Playlist:-
https://www.youtube.com/playlist?list=PLdE8ESr9Th_ucn3ZWwMwVuQwBJlZKaWQy
C Programming Tutorials Playlist:
- https://www.youtube.com/playlist?list=PLdE8ESr9Th_uJsptn5vJ9uRz63B7TagUM
C Practical LAB Exercises Playlist:-
https://www.youtube.com/playlist?list=PLdE8ESr9Th_t8RpyS4rlhNSjNNeVUAdwB
=========================================
Subscribe to our YouTube channel:-
https://www.youtube.com/chidrestechtutorials
Join as Member of our YouTube channel:-
https://www.youtube.com/chidrestechtutorials/join
Become our Patron:-
https://www.patreon.com/chidrestechtutorials
Visit our Website:-
https://www.chidrestechtutorials.com
Download our Notes from Instamojo:-
https://chidrestechtutorials.myinstamojo.com
Buy our Products on Spring:-
https://chidres-tech-tutorials.creator-spring.com
=========================================
Follow Us:-
Google My Business:-
https://chidrestechtutorials.business.site
Google Blog:-
http://manjunathchidre.blogspot.com
LinkedIn:-
https://www.linkedin.com/company/chidrestechtutorials
Facebook:-
https://www.facebook.com/groups/chidrestechtutorials
Twitter:-
https://twitter.com/ManjunathChidre
Tumblr:-
https://chidrestechtutorials.tumblr.com
Pinterest:-
https://in.pinterest.com/chidrestechtutorials
=========================================
Despite my inconsistent uploads; Thanks for being amazing learners and still sticking with me on YouTube.
=========================================
Hash Tags:-
#ChidresTechTutorials #JAVA #JAVATutorial
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Variables in Java | Java Variables - Java Tutorial 12», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.