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
Nesta página do site você pode assistir ao vídeo on-line Constants in Java - Java Tutorial 13 duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário ChidresTechTutorials 10 Julho 2020, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 2,813 vezes e gostou 49 espectadores. Boa visualização!