0% found this document useful (0 votes)
6 views4 pages

Java Programming

The document provides an overview of Java programming concepts, including key definitions, true/false statements, and short questions related to Java syntax and logic. It includes examples of Java code for various programming tasks such as checking number properties, finding the greatest number, calculating simple interest, and determining net salary. Additionally, it highlights features of Java like case sensitivity and platform independence.

Uploaded by

shubhampanua24
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

Java Programming

The document provides an overview of Java programming concepts, including key definitions, true/false statements, and short questions related to Java syntax and logic. It includes examples of Java code for various programming tasks such as checking number properties, finding the greatest number, calculating simple interest, and determining net salary. Additionally, it highlights features of Java like case sensitivity and platform independence.

Uploaded by

shubhampanua24
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Java Programming

Fill in the blanks.


1. Java is a high-level and object-oriented programming language.
2. The println() method displays the output on the terminal.
3. Operators are special symbols used to perform arithmetic and logical
computation.
4. An identifier is the name given to an object in a Java program.
5. The int is a primitive data type.
6. The case keyword is used to define the case in the switch statement.
7. The break keyword is used to stop the execution of the switch
statement when a matched case is found.
8. A break statement allows us to change the default flow of a program.
9. Keyword are reserved words that cannot be used as a identifier
names as they carry a special meaning for the Java compiler.
10. A data type is used to define the size and type of value that a
variable can store.

True and False.


1. In Java keywords are reserved words. True
2. Java Programming is a platform-dependent language. False
3. Java code is converted into bytecode by its compiler. True
4. The values on which an operator works are called operands. False
5. IDE stands for Integrated Document Environment. False
6. The = operator is used to check the equality between two values.
False
7. The break statement forcefully terminates the loop within which it lies.
True
8. The default must be the first case in the switch statement. False
9. A comment is a statement in a Java Program that is executed by the
Java compiler. False
10. Int is a data type in Java, used to store character values. False

Short Questions.
1. What is the use of the if statement in Java?
 The if statement is used to execute a block of statement if it comes
true after checking the condition.
2. What is the difference between break and continue
statements?

Break Continue
Break statement is used to Continue statement is used to
terminate the current iteration continue and jump to the next
even if all the iterations in the iteration in the loop body.
loop isn’t completed
Break keyword is used for Continue keyword is used for
breaking a statement. continuing a statement.

3. What is the difference between a syntax error and a logical


error?
Syntax Error Logical Error
Syntax error is caused due to Logical error is caused due to the
violating the rules of Java. lack of the concept of Java
Programming.
It can’t be compiled by the It can be compiled but the answer
compiler. will not be the same as the user’s
expectation.

4. What is the use of the default keyword in the switch


statement?
 Default is the last data value in switch statement it will work if any
of the matched statements didn’t match.
5. What are jumping statements? Write the names of any to
jumping statements.
 The jumping statements are a type of statement Java that
terminates the programming if the all the iterations are not
completed in the loop body.
Ex  break and continue.
6. List any two features of Java.
 Two features of Java are:
a. Case Sensitive  Java is a case sensitive language. In Java
‘PAY’ and ‘pay’ are not the same.
b. Platform-Independent  Java is a platform independent
programming language. It can work on any other device without
making any change. It doesn’t depend on the hardware of the
computer.
7. What are logical operators?
 Logical error use to combine multiple conditions and evaluate them.
8. Write the names of any two logical operators.
 The name of any two logical operators is:
a. &&(And)
b. ||(Or)
9. What is the use of unary operators?
 The unary operator that uses only one operand to perform
operations.
10. How many unary operators are there in Java?
 There is total two unary operators in Java.

Java Programming.
1. Write a program to input a number and check if number is
zero, positive and negative using the if…else…if statement.
 public class Number{
public static void main ( int a){
[Link](“ The entered number is:” + a);
if(a<0){
[Link](“The number is Negative”);
}
else if(a>0){
[Link](“The number is Positive”);
}
else{
[Link](“The number is Zero”);
}
}
}

Output:
The entered number is: 10
The number is Positive
2. Write a Java Program to find the greatest among the three
numbers.
 public class Greatest{
public static void main(int a, int b, int c){
[Link](“The 1st entered number is:” + a);
[Link](“The 2nd entered number is:” + b);
[Link](“The 3rd entered number is:” + c);
if(a>b && a>c){
[Link](“A is the greatest”);
}
else if(b>a && b>c){
[Link](“B is the greatest”);
}
else if(c>a && c>b){
[Link](“C is the greatest”);
}
else{
[Link](“ All are equal”);
}
}
}

Output:
The 1st entered number is:50
The 2nd entered number is:25
The 3rd entered number is:45
A is the greatest
3. Write a Java Program to calculate simple interest. SI =
(P*r*t)/100 where P is for the principal amount, r is for the rate
of interest, and t is for the time duration. Take all the values
from the user.
 public class SI{
public static void main(double P, double r, double t){
[Link](“ Principal:” + P);
[Link](“ Rate of interest:” + r);
[Link](“ Time:” + t);
double SI = (P*r*t)/100;
[Link](“ SI:” + SI);
}
}

Output:
Principal:50000
Rate of interest:10
Time:10
SI:50000
4. Write a Java Program to take the basic salary of an employee as input
from the user and calculate the net salary based on the criteria given
below:
Net salary = basic salary + incentive
Incentive = 7% of the salary
 public class Salary{
public static void main(int basic_salary){
[Link](“ Basic Salary:” + basic_salary);
int incentive = basic_salary*(7/100);
int net_salary = basic_salary + incentive;
[Link](“ Incentive:” + incentive);
[Link](“ Net Salary:” + net_salary);
}
}

Output:
Basic Salary:25000
Incentive:1750
Net Salary:27200

You might also like