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
Auf dieser Seite können Sie das Online-Video Constants in Java - Java Tutorial 13 mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer ChidresTechTutorials 10 Juli 2020 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 2,813 Mal angesehen und es wurde von 49 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!