Prev Next

Java / Variable

1. Is it possible to access a non static variable in static context?

A static variable in Java is at class level and shared among all its instances. A static variable is initialized when the class is loaded by the JVM. When we try to access a non-static (instance-level) variable from the static context, we encounter compilation error as instance variables are not ...

Read full answer

2. Is null, main, exit, delete are keywords in Java?

3. Explain integer number with leading zeros in Java.

The number starting with 0 represents an octal digit.

Read full answer

4. What is transient variable in Java?

Transient variable cannot be serialized. For example if a variable is declared as transient in a class implementing Serializable interface and the class is persisted to an ObjectStream, the value of the variable is ignoerd and not written to the stream. When the class is retrieved from the Object...

Read full answer

5. What is shadowing in Java?

Shadowing refers to the practice of using two variables with the same name within scopes that overlap. When shadowed, the variable with the higher-level scope is hidden because the variable with lower-level scope overrides it. The higher-level variable is then shadowed. You can access a shadowed ...

Read full answer

6. Different types of variables in Java.

Instance or non static variables, Static or class variables, Local or method variables, and parameters.

Read full answer

7. Difference between static type and dynamic type programming languages.

A language is statically typed if the type of a variable is known at compile time. For example in Java, C and C++, programmer must specify what type each variable is. A language is dynamically typed if the type is associated with run-time values. Example programming languages are perl, python and...

Read full answer

8. What are local variables in Java?

A local variable is one that exists inside a method or a block of code and exists as long as that method or block is executing. Once the program reaches the end of the method (or block), the local variable disappears from memory. The next time the method is called, a completely new version of the...

Read full answer

9. Is local variable thread safe in java?

Yes. All local variables defined in your program will be allocated memory in the stack. So, When you create a thread it will have its own stack created. Two threads will have two stacks and one thread never shares its stack (that is, local variables) with other thread.

Read full answer

«
»

Comments & Discussions