0% found this document useful (0 votes)
138 views5 pages

Lab Session 1: Introduction To Java Programming Language Objective

The document introduces an introductory Java programming lab session that aims to help students understand basic object-oriented programming concepts like classes, attributes, and methods. It provides objectives, required software, pre-lab and in-lab exercises. The pre-lab quiz covers OOP concepts and Java features. The in-lab exercises guide students in writing sample Java programs that demonstrate working with classes, methods, parameters, inputs/outputs and performing tasks like finding minimum numbers, calculating sums and converting between decimal and binary.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
138 views5 pages

Lab Session 1: Introduction To Java Programming Language Objective

The document introduces an introductory Java programming lab session that aims to help students understand basic object-oriented programming concepts like classes, attributes, and methods. It provides objectives, required software, pre-lab and in-lab exercises. The pre-lab quiz covers OOP concepts and Java features. The in-lab exercises guide students in writing sample Java programs that demonstrate working with classes, methods, parameters, inputs/outputs and performing tasks like finding minimum numbers, calculating sums and converting between decimal and binary.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Lab session 1: Introduction to Java Programming

Language

Objective

The objective of lab session 1 is


 To understand basic concepts of OOP
 To understand basic java code structure
 To create class, attributes , methods and constructor
 To demonstrates java classes
Required Software

 Netbean IDE
o https://netbeans.apache.org/download/index.html

Pre-lab Exercise

1. Which of the following is not OOPs concept in Java?


A. Inheritance C. Encapsulation
B. Polymorphism D. Compilation
2. Which concept of Java is a way of converting real world objects in terms of class?
A. Polymorphism C. Encapsulation
B. Abstraction D. Inheritance
3. Which of the following is not a Java features?
A. Dynamic C. Architecture Neutral
B. Use of pointers D. Object-oriented
4. Which of these keywords is used to make a class?
A. class C. struct
B. int D. None of the mentioned
5. Which statement is not true in java language?
A. A public member of a class can be accessed in all the packages.
B. A private member of a class cannot be accessed by the methods of the same
class.
C. A private member of a class cannot be accessed from its derived class.
D. A protected member of a class can be accessed from its derived class.
E. None of the above.

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:

public class TestMethod public class IncTest


{ {
static int i = 1; public static void main(String args[])
public static void main(String args[]) {
{ int i = 0;
System.out.println(i+” , “); i = i++ + i;
m(i); System.out.println("I = " +i);
System.out.println(i); }
} }
public void m(int i)
{
i += 2;
}
}

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

[Follow the following procedures to write the full program]

 Create two classes called: Program11 and TestProgram11


 Inside Program11 class
o Create two attributes: number1 and number2(integer)
o Create a parameterized constructor that initialize number1 and
number2
o Create method: checkIf5[return true/false]
 Inside TestProgram11 class
o Create main method [inside this method do the following]
 Accept two numbers with a prompt statement asking the user
to enter a number.
 Creating an object of Program11[with the parameterized
constructor]
 Call the method: checkIf5
13. Write a Java method to find the smallest number among three numbers.
Test Data:
Input the first number: 25
Input the Second number: 37
Input the third number: 29
Expected Output:
The smallest value is: 25

[Follow the following procedures to write the full program]

 Create two classes called: Program12 and TestProgram12

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

16. How the java code executed?


17. Describe the difference between public, private, protected and default access
modifier?
18. Why the Java filename should be always the same as a public class?

5|Page

You might also like