0% found this document useful (0 votes)
117 views

Java Assignment XI & XII (IT 802 Code)

The document discusses Java concepts like keywords vs identifiers, character vs string constants, types of operators in Java, difference between assignment and equality operators, types of comments in Java, and methods for parsing values. Examples of Java code are provided to demonstrate various concepts.

Uploaded by

studyinsect33
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
117 views

Java Assignment XI & XII (IT 802 Code)

The document discusses Java concepts like keywords vs identifiers, character vs string constants, types of operators in Java, difference between assignment and equality operators, types of comments in Java, and methods for parsing values. Examples of Java code are provided to demonstrate various concepts.

Uploaded by

studyinsect33
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

Java Assignment Ch-5 XI

1. What is the difference b/w


Keyword and an identifier?
● Keyword/Reserved :- It contains only
alphabetical characters, keyword can't use as
identifiers. e.g. int, double, do while
Identifier:- An Identifier can consist of
alphabetical characters, digits and underscores.
e.g. Total_1, marks2
2. What is the difference between
character constant and
String constant.
Ans. Character Constant:- It enclosed within
single quote ' '. It occupies two bytes. e.g.
char ch='a';
String Constant:- It enclosed within double
quotes " ". It occupies More than two bytes.
e.g.
String name="aman";
2. How many types of operators in
Java? Write the names?
● Unary
● Binary
● Arithmetic
● Relational
● Logical
● Assignment
● Bitwise
● Shift
● Ternary
3. What is the difference between
'=' and '==' operators?
Ans. = is an Assignment Operator it is used to
assign the value of variable or expression, while
== is an Equal to Operator and it is a relation
operator used for comparison (to compare
value of both left and right side operands).
int a=10;
if(a==10)
a=90;
else a=100;
4. What do you mean by comment?
How many types of Comments in
Java?
Ans.
1. Single Line comment:- //
2. Multiple Lines Comments:- /*

*/
5. Write Java code to assign the value 70
variable y. Then decrease the value of y by 5
and store it in variable z.
Ans. int y=70;
int z=y-5;
6. Write the value of t after the execution of the
following code:

int t;
int s;
s=6;
t=(8* ++s) / 7;
or
t=(8* ++s) % 7;
Ans 8
or
0
7. The expression 10%3 evaluates
to _____ Ans 1
8. What will be the result of A=7/3 ,
If a is- (a) float (b) int
Ans (a) 2.33
(b) 2
9. What Kind of constants are the following-
14, 011, 0x2A, 17, 079, 0xBC, 899.90
int , Octal, Hexa Dec, Int Octal Hexa Dec,
Double
10. What is the difference between
'a' and "a" in Java?
11. _______ method shows a one-
button, modal dialog box that gives
the user some information

Ans. JOptionPane.showMessageDialog();
12. Method which set the jButton
enable or disable is:
Ans.setEnabled
13. Write down any one function of
JoptionPane.
Ans.JOptionPane.showMessageDialog(null," "+
);
14. Double quotest " " is used to
enclose ____ data type.
Ans.String
15. Single quotes ' ' is used to
enclose ____ data type.
Ans.char
16. The Arithmetic Operator which
returns remainder as result is:
(a) / (b) *
(c) % (d) None of these
17. If((a<10) && (a>20))
(a) Test condition will always be false
(b) Test condition will always be true
(c) The Test Condition will depend on the value
of a
(d) None of these
18. Integer.parseInt() method is
used to:
(a) Convert Integer value to String value
(b) Convert an Integer to float
(c) Convert a value to Integer type
(d) Convert Integer value to Character type
19. How can you write multiline
comments in java program?
/* Java
Programming
*/

/
20. double.parseDouble() method is
used to:
(a) Convert Double value to String value
(b) Convert an Integer to float
(c) Convert a value to double type
(d) Convert Double value to Character type
Q. 21 Why main is special method
in java program?
Ans Main is a special method that every Java
application must have. When you run a
program, the statements in the main method
are the first to be executed.
23. What will be the value of n after the execution of the
following selection statement :
int n=0;
if (6>7 II 5>4)
{n=5;}
else n=7;

Ans. n=5
Q.24
What will be the value of rem after the execution of the following code
snippet? Give reason.
int code =2;
switch(code)
{ case 1: rem= 8;
case 2: rem= 9;
case 3: rem= 10; break;
case 4: rem= 11; break;}
Ans.
25. Write a program to check odd
no

int n=5;
if(n%2!=0)
System.out.println("No is Odd");
else
System.out.println("No is Even");
Q.26 Rewrite the following code using the if
statement without affecting the output of the
code:
char c;
String p;
switch(c){
case 'h' :p=”Shiv Nadar”; break;
case 'i' :p=”Steve Jobs”; break;
case 'm' :p=”Bill Gates”; break;
default: =”wrong choice”;}
Ans.
char c;
String p;
if(c=='h') p="Shiv Nadar"; else
if(c=='i') p="Steve Jobs"; else
if(c=='m') p="Bill Gates"; else
p="Wrong Choice";

You might also like