Chapter 3
PROGRAMMING FUNDAMENTALS
Questions and Answers
Q1. Name
any two Object Oriented Programming languages? Ans.
C++ and Java
Q2. Why is java called a platform independent
language?
Ans Java program can be easily moved from one
computer system to another, anywhere anytime.
Changes and upgrade in operating system, processors and system resources will not force any
change in the Java program. Hence it is called a platform independent language.
Q3. Elaborate the java Compilation process.
Changes and upgrade in operating system, processors and system resources will not force any
change in the Java program. Hence it is called a platform independent language.
Q3. Elaborate the java Compilation process.
Ans. The
source program is first converted into a byte
code using
a java compiler. This byte code is
machine independent i.e. same for all the machines. Later the byte code is executed on the
machine using an interpreter.
machine independent i.e. same for all the machines. Later the byte code is executed on the
machine using an interpreter.
Q4. Why do we write a comment
in a program? What are the two ways of wr
java
Program?
Ans. Comments are added to a
program for the following purposes:-
1. Make the more readable and
understandable
2. For future references we can add comments in
a Java program in the following ways:
i) Adding // before the line which is to be
commented. This can be used only for single
line
comments.
ii) using a pair of /* and */ for multi-line
comments.
Q5. What is a syntax error in
context of a program? Give an example.
Ans. Error in the way of
writing a statement in a program, results in a syntax error.
For
e.g.
for
( i=0, i<=100. i++), will result in a syntax because the program has written
comma
instead of a semi comma in the for loop.
Q6. What is RAD programming?
Why is program development in java using Netbeans IDE is
RAD?
Ans. RAD stands for Rapid
Application Development. A programming
style which aims at building
programs fastly through
the use of tools and wizards is called RAD.
Program development using
Netbeans IDE is RAD as it
• provides GUI
• Provides online help and suggestions
during typing of the program (using ctrl+ Spacebar key)
• Error alerts while
typing of the program.
Q7. What is IDE? Name two IDE
for Programming in java.
Ans. A programming environment,
where all the tools required for programming are available under
one
roof is called IDE. Two IDE for Java are Netbeans and BlueJ
Q8. Name any two type of
Tokens available in Java.
Ans. Keyword, Identifier,
Literal, Punctuators ad Operators.
Q9. What are primitive data
types? Name the various primitive data type available in Java.
Ans. Data types that are
directly available with java are called primitive data type.
Various
primitive data types available in java are byte, short, int, long, float,
double,
char and boolean.
Q10. What
are Reference data types?
Ans. Data types created by the
programmer using the primitive data type are called
reference
data type e.g. Classes, interfaces etc.
Q11. What
is type casting?
Ans. Converting a value form
one type to another is called type casting.
For e.g. int a = 5 . here ‘a’ is a integer,
which can be cased to float as follows float b = (float) a;
Q12. Name and explain the usage
of any two data types used in Java to store numbers with decimals.
Ans. Two data types available in java for storing numbers with decimals are
Ans. Two data types available in java for storing numbers with decimals are
1. float: for single precision floating point values
for e.g. float num = 10.0F
2. double: for double precision floating point value.
This is the default data type
for decimal numbers. for
e.g. double num = 10.0
Q13. What are Keywords? Give
two examples of keywords available in Java.
Ans. Keywords are words that
have a specific predefined meaning in Java. They cannot be used as
variable
names. Eg. void, private, if, while etc.
Q14. Name and explain the usage
of any one relational and one logical operator in Java.
Ans. One relational operator
in java is ==. This operator results in true if both its operands are equal
otherwise false. One logical operator in java
is &&. This operator is used to combine two logical values. The result
of the && will be true if and only if both its operands are true otherwise false.
Q15. What is the difference
between = and == operator in java?
Ans. Represent an assignment
operator. It sets the value of the variable on its left side with the
result of expression on
its right side. == represent a conditional equal to operator. It checks for
the equality of both its operands. If both the
operands are equal, cond otherwise
to false.
Q16. Name the two type of
selection statement available in Java.
Ans. Two selection statement
available in java are ‘if’ and ‘Switch’
Q17. Write the purpose of
Switch Statement with the help of an example. Which Java Statement can
be used in place of switch statement? In the
switch statement, what happens if every case fails and there is no default
option?
Ans. A Switch statement is
used execute a statement from a group of statement based on the result
of a expression. The
expression must result in either of byte, short, integer or character.
An ‘if
statement’ can
be used in place of switch statement. In a switch
statement if
none of the statement satisfies and
even there is no default case then nothing would happen. This would not result in any sort of error.
Q18. What is the purpose of ‘break’
statement in java?
Ans. Break is used to
terminate the current switch statement or the loop.
Q19. What is the purpose of ‘continue’
statement in java?
Ans. Continue statement skips
the remaining part of the current loop and begins the next iteration of
the
loop.
Q20 Find the output of the
following code snippet written in java public static void main(String [
]args)
{
long a=78345,s1=0,s2=0,r;
while(a>0)
while(a>0)
{
r=a%10;
if (r%4==0)
s1+= r;
s1+= r;
else
s2+=r;
a/=10;
}
System.out.println("S1
="+ s1);
System.out.println("S2 ="+ s2);
}
System.out.println("S2 ="+ s2);
}
Ans. Output:
s1= 12
s2= 15
s2= 15
Q21.
Correct the errors in the following program segment written in JAVA. You are
just required to
write the corrected code, underlying the corrections made.
write the corrected code, underlying the corrections made.
public Static Void Main
(String [] args)
{
Integer Nos = 100;
while (Nos => 45)
{
while (Nos => 45)
{
If (Nos % 5 = 0);
Nos+=10;
Nos+=10;
otherwise
Nos + = 20;
}
Nos + = 20;
}
}
Ans: Corrected Code
public static void main (String [] args)
{
{
int Nos = 100;
while (Nos >= 45)
{
if (Nos % 5 == 0)_
Nos+=10;
Nos+=10;
else
Nos + = 20;
}
}
}
No comments:
Post a Comment