Program Coding
Short answer type questions.
1. What is Java?
Ans. Java is an object oriented high level programming language.
2. Explain the use of assignment operator.
Ans. Assignment operators are symbols which are used to assign values to operands.
3. Define arithmetic operators.
Ans. Arithmetic operators are symbols which are used to do basic mathematical
calculations.
4. What is the use of a data type? State the types of data types.
Ans. A data type is used to define the size and type of value that a variable can store. The
two types of data types are Primitive data types and Non-Primitive data types.
5. State the names of primitive data types.
Ans. Java provides eight basic or primitive data types which are – byte, short, int, long,
char, float, double, and boolean.
6. What is the Write Once Run Anywhere (WORA) principle?
Ans. Write Once Run Anywhere (WORA) principle means a program once written in Java
can run on any java enabled machine without any change.
7. Write a short note on BlueJ.
Ans. BlueJ is an IDE designed for beginners which has a built-in editor, debugger and
viewer. An editor gives an area where we can write programs. A debugger allows us to find
errors in the programs. The viewer shows the output of the program.
Long answer type questions.
1. List any four features of Java.
Ans. Four Features of Java are as follows:
(i) Simple: Java has relatively simple structure and clearly defined syntax.
(ii) Case Sensitive: Java is a case sensitive language.
(iii) Object-Oriented: Java supports object-oriented programming concepts of classes and
objects.
(iv) Platform Independent: A Java can run on any platform without making changes to it,
which means that the same program will run on windows, Linux, Macintosh, etc.
2. What are logical operators? Write the names of any two logical operators.
Ans. Logical operators are symbols which are used to combine multiple conditions and
evaluate them, which return a Boolean value ‘true’ or ‘false’ as a result.
&& (AND) and || (OR) are the two types of logical operators.
3. What is the use of Unary operators? How many unary operators are there in Java?
Ans. Unary operators are special operators which require only one operand or value to
perform operations.
Java provides only 2 unary operators which are increment (++) or decrement (--).
4. State the rules for naming identifiers.
Ans. The rules for naming an identifier are:
(i) The identifier name can consist of letters, digits (0 – 9), the underscore.
(ii) The name cannot start with a digit.
(iii) Keywords cannot be used as an identifier.
(iv) No special symbols like !, @, #, $, %, ^, &, *, etc. can be used in identifier.
(v) Identifiers are case sensitive.
Q) Define the following.
Ans.
(i) Computer Program: It is a collection of instruction for a computer, written in a
programming language to perform a specific task.
(ii) Programming: The process of writing a program is called program coding or
programming.
(iii) Class: It is a user defined blueprint or prototype that is used to create objects.
(iv) Comment: It is a statement in Java program that is not executed by the Java compiler.
(v) Identifier: It is the name given to an object to uniquely identify it in a Java program.
(vi) Keywords: Keywords are the reserved words which cannot be used as identifier
names as they carry a special meaning for the Java compiler.
(vii) Variables: Variables are the memory locations used to store values.
(viii) Operator: An operator is a symbol that tells the compiler to perform specific
mathematical or logical calculations.
(ix) Relational Operators: These are symbols which are used to compare quantities and
return Boolean value ‘True’ or ‘False’ as a result.
Q) What will be the output of the following:
1)
public class rad
{
public static void main(String[] args)
{
double r, c;
r=2.3;
c=2*3.14 * r;
[Link](c);
}
}
Output:
2)
public class A
{
public static void main(String[] args)
{
double s, GST, inv;
S = 200;
GST = 5s/100;
inv = s + GST;
[Link]("GST to be paid:" + GST);
[Link]("Total invoice value:" + inv);
}
}
Output:
3)
public class program
{
public static void main(String[] args)
{
int a,b,c;
a = 10;
b = 20;
c = a;
a = b;
b = c;
[Link]("Value of a is:" + a);
[Link]("Value of b is:" + b);
}
Output:
4)
public class A1
{
public static void main(String[] args)
{
String first_name = "Kittu";
String last_name = "Sharma";
String name = = first_name + " " + last_name;
[Link](name);
}
Output:
5)
public class B{
public static void main(String[] args){
int age = 17;
age += 1;
age++;
++age;
[Link](age);
}
}
Output:
6)
public class C6{
public static void main(String[] args){
int a = 5;
int b = 5;
[Link](a > b);
[Link](a == b);
}
}
Output:
7)
public class C7{
public static void main(String args[]) {
int a=5;
int b=6;
[Link](a++ + ++a);
[Link](b++ + b++);
}
}
Output: