Java Variables and Operators

Java Variables and Operators

1.What is operator?

A:Any symbol that is used for performing and operation can we called as an "operators".

2. Define class?

A: A class is a blue print from which individual objects are created. A class can contain fields and methods to describe the behavior of an object.

3. What do you mean by Object?

A: Object is a runtime entity and it’s state is stored in fields and behavior is shown via methods. Methods operate on an object's internal state and serve as the primary mechanism for object-to-object communication.

4. What kind of variables a class can consist of?

A: A class consist of Local variable, instance variables and class variables.

5. What is a Class Variable

A: These are variables declared with in a class, outside any method, with the static keyword.

6. What do you mean by Constructor?

A: Constructor gets invoked when a new object is created. Every class has a constructor. If we do not explicitly write a constructor for a class the java compiler builds a default constructor for that class.

7. List the three steps for creating an Object for a class?

A: An Object is first declared, then instantiated and then it is initialized.

8.What is the default value of byte datatype in Java?

A: Default value of byte datatype is 0.

9. What is the default value of float and double datatype in Java?

A: Default value of float and double datatype in different as compared to C/C++. For float its 0.0f and for double it’s 0.0d

10. When a byte datatype is used?

A: This data type is used to save space in large arrays, mainly in place of integers, since a byte is four times smaller than an int.

11. What is a static variable?

A: Class variables also known as static variables are declared with the static keyword in a class, but outside a method, constructor or a block.

12. What do you mean by Access Modifier?

A: Java provides access modifiers to set access levels for classes, variables, methods and constructors. A member has package or default accessibility when no accessibility modifier is specified.

13. What is protected access modifier?

A: Variables, methods and constructors which are declared protected in a superclass can be accessed only by the subclasses in other package or any class within the package of the protected members' class.

14.What is Arithmetic operators ? why we are using this one?

A:These operators are used to perform simple mathematical calculations.the various arthemetic operations are +,_,*,/,%.

15. What is a Local Variable

A: Variables defined inside methods, constructors or blocks are called local variables. The variable will be declared and initialized within the method and it will be destroyed when the method has completed.

16. What is a Instance Variable

A: Instance variables are variables within a class but outside any method. These variables are instantiated when the class is loaded.

17.what is dot operator?
A:The dot operator(.) is used to access the instance variables and methods of class objects.It is also used to access classes and sub-packages from a package.

18.What is the difference between the >> and >>> operators?

">>" is a signed right shift
">>>" is an unsigned right shift.

If >> is applied on a negative number, the result will still be negative.
>>> ignores the sign of the number.
If >>> is applied on a negative number,the result will be a positive number

The >> fills from the left with the sign bit (0 or 1).
The >>> zero-fills from the left.

19.What is the difference between the Boolean & operator and the && operator?

For Integers:
"&" is the "bit-wise AND" operator.
For boolean arguments:
"&" constitutes the (unconditional) "logical AND" operator
"&" always evaluates both arguments.

"&&" is defined for two boolean arguments.
It is the "conditional logical AND" operator.
"&&" ealuates the first argument. if it is true, it then evaluates the second.

20.How are positive and negative numbers represented internally?

A:positive numbers are reoresented in binary using 1's complement notation and negative numbers are represented by using 2's compliment notation.

21. What is Singleton class?

A: Singleton class control object creation, limiting the number to one but allowing the flexibility to create more objects if the situation changes.

22.What is new operator?

A:new operator is often used to ceate objects to classes.We know that objects are created on heap memory by JVM.

23.What is cast operator?

A:cast operator is used to convet one data type to another datatype.This operator can be used by using datatype inside simple braces.

 Ex:double x=10.54;
       int y=x;

24.What do you mean by Unary operators?

A:These operators are used to perform the operations on a single operand.The various unary operators are _,++,__..

25.What is Bitwise operators in java?

A:These operators will perform the operations on bits of a number.The various bitwise operators are ~,&,|,^,<<,>>,>>>.


Post a Comment