filmov
tv
Java interview questions| Data Types|Variables |Operators| basics off java|Coding for beginners

Показать описание
#javainterview #codingforbeginners #javatutorial
Q.1) What is declaration and definition of a variable? Can both be done together
Yes - int a; // Declaration
a = 3; // Defination
int a =3; // Declaration + Defination
Q.2) Can variable name start with a digit? - No
Rules
-: Variable name should start with letters, ‘_’ or ‘$’
-: After the first letter it can contain digits
-; No spaces and other special characters
-: No keywords as variable names
Conventions
-: Camel case convention should be followed e.g. greaterNumber
-: ‘_’ or ‘$’ are mostly discouraged
-: Length should be limited
Q.3) How many primitive data types are there in java? - 8
-: byte,short,int,long,float,double,boolean,characters
Q.4) Why are primitive data types are not included in objects?
-: Since the primitive data types consume less memory and can be accessed faster, they are not objects.
The equivalent Wrapper classes are also available in java like "Integer" "Short" etc.
-: Since they are widely used creating heap memory for them would be costly
Q.5) What is the purpose of data types?
-: defines the type of a variable and to assign memory to it accordingly.
Q.6) Difference between & and && on boolean condition?
-: && (logical AND) does not check the next condition if the first condition is false because the result is going to be ultimately false if one condition is false.
e.g. (a:1 && a:10)
-: & (bitwise AND ) checks all the conditions irrespective of the first condition
e.g. (a:1 & a:10)
Q.7) Difference between the signed right shift and unsigned right shift: ?
-: a signed right shift operator removes bits at the end and if the number is positive adds an equal number of 0’s before the number and if a number is negative adds an equal number of 1’s before the number.
-: unsigned right shift operator. It removes bits from the end of the number and it always adds an equal number of 0’s at the
beginning irrespective of the sign of the number.
Q.8) Difference between unary post and pre operators?
-: Unary Post increment and decrement operators assign the value to the variable first and then increment the value.
e.g. int b=4++; -: b=4;
-: Unary Pre increment or decrement operators first increment the value
int b=++4; b=5;
Q.9)What is difference between = & ==?
-: = is an assignment operator and assigns value to a variable
e.g. int a=3; -: stores value 3 in a
-: == is a logical operator and checks if two values are equal if values are equal it returns true otherwise false
e.g a==3; - returns true
Q.10) Difference between automatic and manual typecasting?
-: When the target data type is larger than the source data type compiler directly converts source data type to target data type this is called automatic/widening typecasting.
e.g int i=3; double d= i; d=3.0;
-: When the target data type is smaller than the source data type we manually need to tell the compiler about the target data type. This is manual or narrow typecasting.
e.g. double d=3.0 int i =(int)d; -: i=3;
Q.1) What is declaration and definition of a variable? Can both be done together
Yes - int a; // Declaration
a = 3; // Defination
int a =3; // Declaration + Defination
Q.2) Can variable name start with a digit? - No
Rules
-: Variable name should start with letters, ‘_’ or ‘$’
-: After the first letter it can contain digits
-; No spaces and other special characters
-: No keywords as variable names
Conventions
-: Camel case convention should be followed e.g. greaterNumber
-: ‘_’ or ‘$’ are mostly discouraged
-: Length should be limited
Q.3) How many primitive data types are there in java? - 8
-: byte,short,int,long,float,double,boolean,characters
Q.4) Why are primitive data types are not included in objects?
-: Since the primitive data types consume less memory and can be accessed faster, they are not objects.
The equivalent Wrapper classes are also available in java like "Integer" "Short" etc.
-: Since they are widely used creating heap memory for them would be costly
Q.5) What is the purpose of data types?
-: defines the type of a variable and to assign memory to it accordingly.
Q.6) Difference between & and && on boolean condition?
-: && (logical AND) does not check the next condition if the first condition is false because the result is going to be ultimately false if one condition is false.
e.g. (a:1 && a:10)
-: & (bitwise AND ) checks all the conditions irrespective of the first condition
e.g. (a:1 & a:10)
Q.7) Difference between the signed right shift and unsigned right shift: ?
-: a signed right shift operator removes bits at the end and if the number is positive adds an equal number of 0’s before the number and if a number is negative adds an equal number of 1’s before the number.
-: unsigned right shift operator. It removes bits from the end of the number and it always adds an equal number of 0’s at the
beginning irrespective of the sign of the number.
Q.8) Difference between unary post and pre operators?
-: Unary Post increment and decrement operators assign the value to the variable first and then increment the value.
e.g. int b=4++; -: b=4;
-: Unary Pre increment or decrement operators first increment the value
int b=++4; b=5;
Q.9)What is difference between = & ==?
-: = is an assignment operator and assigns value to a variable
e.g. int a=3; -: stores value 3 in a
-: == is a logical operator and checks if two values are equal if values are equal it returns true otherwise false
e.g a==3; - returns true
Q.10) Difference between automatic and manual typecasting?
-: When the target data type is larger than the source data type compiler directly converts source data type to target data type this is called automatic/widening typecasting.
e.g int i=3; double d= i; d=3.0;
-: When the target data type is smaller than the source data type we manually need to tell the compiler about the target data type. This is manual or narrow typecasting.
e.g. double d=3.0 int i =(int)d; -: i=3;
Комментарии