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
On this page of the site you can watch the video online Constants in Java - Java Tutorial 13 with a duration of hours minute second in good quality, which was uploaded by the user ChidresTechTutorials 10 July 2020, share the link with friends and acquaintances, this video has already been watched 2,813 times on youtube and it was liked by 49 viewers. Enjoy your viewing!