Lab Session 1: Introduction To Java Programming Language Objective
Lab Session 1: Introduction To Java Programming Language Objective
Language
Objective
Netbean IDE
o https://netbeans.apache.org/download/index.html
Pre-lab Exercise
1|Page
6. Which component is responsible for converting byte-code into machine specific code?
A. JVM C. JDK
B. JIT D. JRE
7. Which statement is true about java?
A. Platform independent programming language
B. Platform dependent programming language
C. Code dependent programming language
D. Sequence dependent programming language
8. What is the extension of java code files
A. .class B. .java C. .txt D. .js
9. Which of the following is a valid declaration of an object of class Box?
A. Box obj = new Box(); C. Box obj = new Box;
B. obj = new Box(); D.new Box obj;
10. Which of the following is a method having same name as that of it’s class?
A. finalize C. delete
B. class D. constructor
11. What is the output of the following program:
2|Page
In-lab Exercise
12. Write a Java program that accept two integers and return true if either one is 5 or their
sum or difference is 5.
Sample Output:
Enter the first number: 5
Enter the second number: 3
true
=+++++++++++++++++++=
Enter the first number: 3
Enter the second number: 4
false
3|Page
Inside Program12 class
o Create three attributes: num1, num2 and num3 (integer)
o Create a parameterized constructor that initialize the attributes
o Create method: findTheSmallest[return the smallest number]
Inside TestProgram12 class
o Create main method [inside this method do the following]
Accept three numbers with a prompt statement asking the
user to enter a number.
Creating an object of Program12 [with the parameterized
constructor]
Call the method: findTheSmallest
14. Write a Java method to compute the sum of the digits in an integer.
Test Data:
Input an integer: 25
Expected Output:
The sum is: 7
// Program13 //TestProgram13
package Program13; public class TestProgram13
import java.util.*; {
class Program13 public static void main()
{ {
int num; Scanner reader=new Scanner(System.in);
public Program13(int num) System.out.print(“Enter the number:”);
{ int number= reader.nextInt();
this.num= num; Program13 p13=new Program13(number);
} p13.sumOfDigits();
public void sumOfDigits() }
{ }
//write your solution here
}
}
4|Page
15. Write a Java program to convert a decimal number to binary number.
Test Data:
Input a Decimal number: 6
Expected Output:
Binary number is: 110
// Program14 //TestProgram14
package Program14; public class TestProgram14
import java.util.*; {
class Program14 public static void main()
{ {
int num; Scanner reader=new Scanner(System.in);
public Program14(int num) System.out.print(“Enter the number:”);
{ int number= reader.nextInt();
this.num= num; Program14 p14=new Program14(number);
} p14.decimalToBinary();
public void decimalToBinary() }
{ }
//write your solution here
}
}
Post-lab Exercise
5|Page