Sadasiba Nayak
private static final
1 Answer(s)      2 years and 2 months ago
Posted in : Java Interview Questions

Why there is necessary to make a variable private static final?

View Answers

March 16, 2011 at 1:01 PM


Making a member private, means it's only visible to objects of the same class (unless, of course, expose via a public getter method.

Making it static means that there's only one instance of that particular member variable. This is good since there is no point having more than one instance of a constant.

Making it final, means that it can only be assigned once, alowing the compiler to optimize the bytecode since it is known that the value of that variable is never going to change once assigned.









Related Pages:
private static final
private static final  Why there is necessary to make a variable private static final
Static final variables - Java Beginners
Xyz{ private static final String name="xyz"; public void displayData...Static final variables  can a static final variable be accessed by a instance (non-static)method?  Hi, static final variable u can
final
final  what does final means in "public static final void main (string args[])" ?   keyword final can be assigned only once. They cannot be modified
private and final - Java Interview Questions
private and final  what is the difference between private modifier and final modifier in java   Hi Friend, Private modifier indicates... be accessed or instantiated outside. Final modifier indicates
Static
Static  Can i know the real time example for Static method and final variables with defenition? Thank you
The final Keyword
. private and static methods are always implicitly final... The final Keyword       The final is a keyword. This is similar to const keyword in other
Java 5 - "final" is not final anymore - Java Tutorials
or primitive would get inlined */ private static final String stringValue = "original value"; private static final Object objValue = stringValue... { private final String name; private final int age; private final int
private method
private method  how can define private method in a class and using...); } } public class useOfthisoperator { public static void main(String args...; this.breadth=b; } private int calculate(){ int size
private method
private method  how can define private method in a class and using...); } } public class useOfthisoperator { public static void main(String args... useOfthisoperator { public static void main(String args[]){ rectangle r=new
Final Methods - Java Tutorials
; The fields which are declared as static, final and public are known as named...{ public static final double x = 2.998E8; } final method arguments You can also...The final Keyword in Java In Java, final keyword is applied in various context
Static
an instance of a class. Static methods are implicitly final method, since overriding... final. However, a static method can't be overridden by a nonstatic method. Or we... Static       Static
Java final keyword
Java final keyword The final is a very important keyword in java, which... with the name "Final" in a Java program. We can have final methods, final classes, final data members, final local variables and final parameters. When
loop to input multiple points to calculate final distance and speed
loop to input multiple points to calculate final distance and speed  import java.util.Scanner; public class Travel { private double time; private double distance; public Travel() { time=0; distance=0
changing final Boolean value in SwingUtilities.invokeLater()
static boolean doCommit() { final boolean success = true...changing final Boolean value in SwingUtilities.invokeLater()  Hi, I have a problem with setting final Boolean value in second time
Access Modifier
to change the visibility (public, protected, default, private) and other modifiers (final, static, synchronized) of Java classes, interfaces, methods
Java Final Project - Java Beginners
Java Final Project  I am having a real hard time with this java assignment. Any help or tips will be great!!! This is the requirements: Final... final project. This is your opportunity to show off your skills! Overall
static & instance - Java Beginners
{ private static int noOfObjects; private int count; public Main...static & instance  what is different between static variable and instance variable .? plz explain with example. and when we can use static variable
Final Key Word in Java
the compiler will give an error message. Example- private final int j; // Declaring... .style1 { text-align: center; } Final key word in java In java final is a key word used in several different contexts. It is used before
STATIC
STATIC  WHAT IS STATIC BLOCK?EXPLAIN , AND WHAT IS THE DIFFERENCE BETWEEN STATIC BLOCK AND STATIC METHOD?   A STATIC block is automatically... between static block and static method: static block will execute when ever
static
Static Concept  in what are all the situation we may use static...,then use static blocks and without creation of object we need to perform some task,then go for static methods. If we want variables those values will not be changed
static
static  what r the main uses of static in java   Hi Friend, The Static means that a certain object/variable is resident in memory and accessed each time an instance of a class, an object, is created. When static
static
static  What is the exact need of declaring a variable as static?   A static variable is a variable who's single copy in memory is shared by all objects,so any modifications to the static variable will modify it's value
static
redeclare static variable in the inherited class  can we redeclare static variable in the inherited class like this: public class StaticClass1 { class StaticClass1{ static int noOfInstances; StaticClass1
private and protected
private and protected  what is diffrence between private and protected
private constructor
private constructor  can we extend from a class which is having private constuctor
static Java Keyword
. public final static <type> varName = <value>... final static int MAX_OBJECTS = 100; static int x = 0... static Java Keyword      
PHP Static Variable and Methods
Variables & Methods : <?php class One{ private static $var=0...PHP Static Methods and Variables: In this tutorial we will study when we should use static methods and variables. Static keyword is used to make only one
final keyword
final keyword  why is final keyword used in java
Final Keyword
Final Keyword  hello, What is final?   hii In case of class if we use final then this class can not be extended or final class may not be subclassed. A final method can't be overridden when its class is inherited
final variable
final variable  Please give some easiest and understanding example program for final variable
Java private constructor
Java private constructor  what is private constructor?what are the uses of writing private constructor in our program
Private Cloud Hosting
Private Cloud Hosting  Hi, What is Private Cloud Hosting? What are the benefits of Private Cloud Hosting? Thanks
final grade
final grade  C. Write a JavaScript program that would input a student?s final grade from 50-100. Evaluate the Final grade and display the Point...?s final grade from 50-100. Evaluate the Final grade and display the Point
Private variable of class
Private variable of class  Hi..... What keyword allows you to refer to private variables of a class in flex? Please give me an example for that Thanks  Ans: private keyword and this keyword
Calling Static Methods Using SpEL
Calling Static Method Using SpEL Spring 3 provides powerful Expression Language which can be used to wire values into beans properties by calling static... MyClass { private String random; public void setRandom(String random
Private Java Keyword
Private Java Keyword       private is a keyword defined in the java programming language. Keywords... in java programming language likewise the private keyword indicates the following
What if the main() method is declared as private?
What if the main() method is declared as private?  Hi, What if the main() method is declared as private? Thanks   Hi, I have found... as private. Visit this link may help you for getting examples with syntax related
What is final class?
What is final class?  Hi, What is final class? thanks   Hi, A final class is not be saubclassed. A final method can't be overridden when its class is inherited. You can't change value of a final variable
Java Final Variable
Java Final Variable  I have some confusion --Final variable has single copy for each object so can we access final variable through class name,or it is necessary to create object for accessing final variable
static in java
static in java  what is the need to go static? what use
Static method
Static method  what is a static method?   Have a look at the following link: Java Static Method
compute the final grades
compute the final grades  C. Write a JavaScript program that would input a student?s final grade from 50-100. Evaluate the Final grade and display... input a student?s final grade from 50-100. Evaluate the Final grade and display
compute the final grades
compute the final grades  C. Write a JavaScript program that would input a student?s final grade from 50-100. Evaluate the Final grade and display the Point Equivalent based on the table below. Indicate also the remarks
compute the final grades
compute the final grades  C. Write a JavaScript program that would input a student?s final grade from 50-100. Evaluate the Final grade and display the Point Equivalent based on the table below. Indicate also the remarks
compute the final grades
compute the final grades  C. Write a JavaScript program that would input a student?s final grade from 50-100. Evaluate the Final grade and display the Point Equivalent based on the table below. Indicate also the remarks
compute the final grades
compute the final grades  C. Write a JavaScript program that would input a student?s final grade from 50-100. Evaluate the Final grade and display the Point Equivalent based on the table below. Indicate also the remarks
compute the final grades
compute the final grades  C. Write a JavaScript program that would input a student?s final grade from 50-100. Evaluate the Final grade and display the Point Equivalent based on the table below. Indicate also the remarks
How to copy many files into one file and how to manage the content of the final file?
static void main(String[] args) { File save = new File("Final_save.txt...How to copy many files into one file and how to manage the content of the final... FileStream2 { public static void main(String[] args) throws Exception
static method
static method  Give some absolute examples and definition for static method also

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.