UNIT 1 PRINCIPLES OF OOP
Fill in the blanks:
- An act of using essential features without including the background details is called data abstraction.
- In object-oriented programming, the importance is given to data.
- Wrapping of data and functions together as a single unit is called encapsulation.
- An object has a unique identity which contains some characteristics and behavior.
- The objects may communicate with each other through functions.
- In POP, the global data is loosely attached to the functions.
- The process by which a class acquires the properties from another class is known as inheritance.
- In object-oriented programming, using a function for many purposes is termed as polymorphism.
State whether True or False:
- In assembly language, the instructions are given in terms of 0’s and I’s. False
- PASCAL is a structure-oriented programming language. True
- Machine language requires a translator to convert input instructions to be understood by the machine. False
- Compilers and Interpreters are referred to as Language processors. True
- A process according to which a class acquires the characteristics from another class is called Encapsulation. False
- Procedure oriented program stresses on data. False
- C++ is also an object-oriented programming language. True
- An object is identified by its characteristics. True
- Function is a set of objects that share the common state and behavior. False
- Encapsulation keeps data safe from outside interference. True
Name the following:
- Two categories of low-level languages:
a) Machine language
b) Assembly language - Two procedure-oriented languages:
a) C
b) BASIC - Two structure-oriented programming languages:
a) ALGOL
b) PASCAL - Two examples of data abstraction in your daily life:
a) A car
b) A computer - Two examples of real-world objects:
a) A car
b) A pen - Two basic principles of object-oriented programming:
a) Polymorphism
b) Encapsulation
Write short notes with examples (if applicable):
- Object-Oriented Programming: OOP is based on objects. An object is an instance of a class. It gives emphasis on data and follows a bottom-up approach. Examples: C++, Java, Python.
- Data Abstraction: It is an act of representing the essential features without knowing the background details. Example: Polymorphism.
- Encapsulation: It is the system of wrapping data and functions into a single unit. It leads to data hiding.
- Machine Language: It is a low-level language that contains 0s and 1s. It is directly understood by the computer. It is machine dependent.
- Polymorphism: It is the process of showing different behaviors according to different situations. Example: Function overloading.
- Procedure-Oriented Programming: POP uses functions to divide a problem into modules. It emphasizes on functions and follows a top-down approach. Examples: C, FORTRAN.
- Inheritance: It is the process in which one class inherits properties and behavior from another class. It leads to code reusability.
- Assembly Language: It is a low-level language that uses mnemonic codes. It requires a translator called assembler to convert assembly language program into machine language.
Distinguish between:
1. Object-Oriented Programming and Procedure-Oriented Programming
OOP | POP |
1. Gives emphasis to data. | a. Gives emphasis to functions. |
2. It is a bottom-up approach. | b. It is a top-down approach. |
2. High-Level Language and Low-Level Language
HLL | LLL |
1. It is easier to read and write. | a. It is difficult to read and write. |
2. It is machine independent. | b. It is machine dependent. |
3. Compiler and Interpreter
COMPILER | INTERPRETER |
1. Translates the entire program at once. | a. Translates and executes the program line by line. |
2. It is faster. | b. It is slower. |
Answer the following questions:
- Enlist the features of Object-Oriented Programming.
a) It gives importance to data.
b) It divides a problem into objects.
c) The objects can interact with each other.
d) It allows data hiding.
e) It is capable of simplifying complex problems. - Which OOP principle implements function overloading? Explain.
Polymorphism implements function overloading. It allows to create multiple functions with the same name that show different behaviors. - Write three benefits of Object-Oriented Programming.
a) Allows code reusability.
b) Helps in reducing code complexity.
c) Helps in making the code modular. - Mention two limitations of:
(a) Procedure Oriented Programming
Can lead to unintentional changes in data.
Not suitable for solving complex problems.
(b) Object Oriented Programming
It requires intensive software testing.
More time-consuming. - How is Encapsulation useful in Object Oriented Programming? Explain.
Encapsulation allows us to wrap data and related methods into a single unit. This helps in data hiding by keeping data private. This avoids any unintentional changes in data. - What are the advantages of High-Level languages?
HLL are more programmer friendly as they are much easier to read and write.
HLL are also machine independent.
UNIT 2 INTRODUCTION TO JAVA
Write True or False:
- Java application is a Java program which is developed by users. True
- James Gosling developed Java programming language. True
- Machine codes are expressed using alphanumeric characters. False
- Bytecode is the program in binary form. False
- JVM stands for Java Visual Management. False
Fill in the blanks with appropriate words:
- Java is a case-sensitive language.
- In Java, the package used to find power raised to any base is java.lang.
- The words which are preserved with the system are called reserved words and they cannot be used as variable names in Java programming.
- A single line comment is represented by the symbol // in Java programming.
- BlueJ is a window-based platform to operate Java program.
Answer the following questions:
- Who developed Java? What was it initially called?
Java was developed by James Gosling. It was initially called Oak. - Give a brief on the historical development of Java.
Java was initially meant to be used in consumer electronics. It was developed at Sun Microsystems in the year 1995. It has adopted many features from C and C++. - Mention at least four features of Java.
a. It is an object-oriented programming language.
b. It is both compiled and interpreted.
c. It is case-sensitive.
d. It is platform independent. - Define Bytecode.
Bytecode is an intermediate code generated after compiling the Java source code. It is platform independent. - What is Java Virtual Machine (JVM)?
JVM is the Java interpreter that executes the bytecode. - Name three packages of Java Class Library.
a. java.lang
b. java.util
c. java.io - What are Java reserved words? Name any five.
Java reserved words are the keywords that have a special meaning to the Java compiler. Examples: public, static, void, class. - Distinguish between JDK 1.3 and BlueJ.
JDK 1.3 is a software kit that includes Java libraries, compiler and interpreter. BlueJ is an IDE for beginners that makes it convenient to write and execute Java programs. - A compiler is specific to a language. Give your comments.
A compiler is specific to a language because each language has its own syntax and rules. - What is the basic format of a Java Program? Explain with an example.
A basic Java program consists of a class and a main() function. The statements are included inside the main() function. The program starts with the main() function, and when main() terminates, the program also terminates. - What is BlueJ?
BlueJ is an IDE (Integrated Development Environment) for beginners to write, compile and execute Java programs in one place. - Mention five features of BlueJ.
a. Compilation and execution is easy.
b. It is window-based (graphical).
c. Debugging is also easy.
d. It auto-indents the program.
e. It highlights the syntax with colors. - Name a package that is invoked by default.
The default package is java.lang. - What are the points to be taken care of while naming a class, in a Java program?
a. It must not be a reserved word.
b. It must be meaningful. - Java is a case-sensitive language. Explain.
Case-sensitive means that uppercase and lowercase characters are treated differently. - The main function in a Java program is declared as:
public static void main(String args[])
What is the significance of the words public, static and void?
The public keyword means that the main() function can be accessed from anywhere. The static keyword enables main() to be executed without the need of any object of the class it belongs to. The void keyword means that it doesn’t return any value. - What does the term ‘Compilation’ mean?
Compilation means translating a high-level language program into low-level language program. - A Java program uses a compiler as well as an interpreter. Explain.
Java uses a compiler to translate the source code into bytecode. The interpreter is then used to execute the bytecode. - Design a program in Java to display the following information on the output screen:
Name:
Class:
Roll No.
Subject:
School - You want to display your bio-data on the output screen. Write a program in Java to perform the task in the given format:
Name:
Father’s Name:
Date of Birth:
Blood Group:
Aadhar Card No.
State: