Constants in Java - Java Tutorial 13

Опубликовано: 10 Июль 2020
на канале: ChidresTechTutorials
2,813
49

Notes for You:: Constants in Java - Java Tutorial 13
is a named memory location, whose value never change during the execution of a program once it is initialized or assigned.

Creating constants in Java:
Constants in Java are created using final keyword.
Constants are also called final variables.

Note:
Final variables must be initialized when they are declared.

Syntax for Declaring and Initializing a constant:
final datatype NAME_OF_CONSTANT = value;
Example:
final float PI = 3.142f;

Syntax for Declaring and Initializing multiple constants:
final datatype NAME_OF_CONSTANT1 =value, NAME_OF_CONSTANT2 =value,...;
Example:
final float PI = 3.142f, E = 2.71828f;

Example Code:
package constantsdemo;

public class ConstantsDemo
{
public static void main(String[] args)
{
/*
int playerScore = 0;
System.out.println("player score = " + playerScore); // 0

playerScore = 10;
System.out.println("player score = " + playerScore); // 10

final float PI = 3.142f;
System.out.println("PI = " + PI);//3.142

// PI = 4.142f; error

*/

final float PI=3.142f, E=2.71828f;
System.out.println("PI = " + PI); // 3.142
System.out.println("E = " + E); // 2.71828
}
}


=========================================

Follow the link for next video:
   • char Data Type in Java - Java Tutoria...  

Follow the link for previous video:
   • Variables in Java - Java Tutorial 12  

=========================================

Java Tutorials Playlist:-
   • Java Tutorials  

=========================================
Watch My Other Useful Tutorials:-

C++ Tutorials Playlist:
   • C++ Tutorials  

C# Tutorials Playlist:-
   • C# Tutorials  

C Programming Tutorials Playlist:
   • C Programming Tutorials  

C Practical LAB Exercises Playlist:-
   • C Practical Programs  

=========================================

► Subscribe to our YouTube channel:
   / chidrestechtutorials  

► Visit our Website:
https://www.chidrestechtutorials.com

=========================================
Hash Tags:-
#ChidresTechTutorials #JAVA #JAVATutorial


На этой странице сайта вы можете посмотреть видео онлайн Constants in Java - Java Tutorial 13 длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь ChidresTechTutorials 10 Июль 2020, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 2,813 раз и оно понравилось 49 зрителям. Приятного просмотра!