0% found this document useful (0 votes)
3 views17 pages

Questions

The document provides a comprehensive overview of Java programming concepts, including the differences between procedural and object-oriented programming, the principles of OOP, and its applications in various systems such as real-time systems, client-server systems, and AI expert systems. It also outlines the features of Java, the structure of a Java program, and explains keywords and identifiers in programming. Overall, it serves as a resource for understanding key Java programming concepts and their practical applications.
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)
3 views17 pages

Questions

The document provides a comprehensive overview of Java programming concepts, including the differences between procedural and object-oriented programming, the principles of OOP, and its applications in various systems such as real-time systems, client-server systems, and AI expert systems. It also outlines the features of Java, the structure of a Java program, and explains keywords and identifiers in programming. Overall, it serves as a resource for understanding key Java programming concepts and their practical applications.
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/ 17

Questions https://awaisahmed.notion.site/Questions-650d1a8c7efb4edc997c111aa...

Questions
Unit -1: Important Java Questions:
1. Difference between procedure-oriented and object-oriented
programming.
answer

Procedural Programming
Procedural Programming can be defined as a programming model
which is derived from structured programming, based upon the
concept of calling procedure. Procedures, also known as routines,
subroutines or functions, simply consist of a series of computational
steps to be carried out. During a program’s execution, any given
procedure might be called at any point, including by other procedures
or itself.

Languages used in Procedural Programming:

FORTRAN, ALGOL, COBOL, BASIC, Pascal and C.

Object-Oriented Programming
Object-oriented programming can be defined as a programming
model which is based upon the concept of objects. Objects contain
data in the form of attributes and code in the form of methods. In
object-oriented programming, computer programs are designed
using the concept of objects that interact with the real world. Object-
oriented programming languages are various but the most popular
ones are class-based, meaning that objects are instances of classes,
which also determine their types.
Languages used in Object-Oriented Programming:

Java, C++, C#, Python, PHP, JavaScript, Ruby, Perl, Objective-C,


Dart, Swift, Scala.
1. Explain different concepts of OOPs.
answer

1 of 33 12-12-2023, 18:52
Questions https://awaisahmed.notion.site/Questions-650d1a8c7efb4edc997c111aa...

Object Oriented Programming


(OOPs) Concept in Java
As the name suggests, Object-Oriented Programming or OOPs refers
to languages that use objects in programming, they use objects as a
primary source to implement what is to happen in the code. Objects
are seen by the viewer or user, performing tasks assigned by you.
Object-oriented programming aims to implement real-world entities
like inheritance, hiding, polymorphism etc. in programming. The main
aim of OOP is to bind together the data and the functions that
operate on them so that no other part of the code can access this
data except that function.

• Access Modifier: Defines the access type of the method i.e. from
where it can be accessed in your application. In Java, there are 4
types of access specifiers:

◦ public: Accessible in all classes in your application.

◦ protected: Accessible within the package in which it is defined


and in its subclass(es) (including subclasses declared outside
the package).

◦ private: Accessible only within the class in which it is defined.

◦ default (declared/defined without using any


modifier): Accessible within the same class and package
within which its class is defined.

• The return type: The data type of the value returned by the
method or void if it does not return a value.

• Method Name: The rules for field names apply to method names
as well, but the convention is a little different.

• Parameter list: Comma-separated list of the input parameters that


are defined, preceded by their data type, within the enclosed
parentheses. If there are no parameters, you must use empty
parentheses ().

• Exception list: The exceptions you expect the method to throw.


You can specify these exception(s).

• Method body: It is the block of code, enclosed between braces,

2 of 33 12-12-2023, 18:52
Questions https://awaisahmed.notion.site/Questions-650d1a8c7efb4edc997c111aa...

• Method body: It is the block of code, enclosed between braces,


that you need to execute to perform your intended operations.
1. What are the benefits/advantages of OOPs?
answer

• We can build the programs from standard working modules that


communicate with one another, rather than having to start writing
the code from scratch which leads to saving of development time
and higher productivity,

• OOP language allows to break the program into the bit-sized


problems that can be solved easily (one object at a time).

• The new technology promises greater programmer productivity,


better quality of software and lesser maintenance cost.

• OOP systems can be easily upgraded from small to large systems.

• It is possible that multiple instances of objects co-exist without


any interference,

• It is very easy to partition the work in a project based on objects.

• It is possible to map the objects in problem domain to those in


the program.

• The principle of data hiding helps the programmer to build secure


programs which cannot be invaded by the code in other parts of
the program.

• By using inheritance, we can eliminate redundant code and


extend the use of existing classes.

• Message passing techniques is used for communication between


objects which makes the interface descriptions with external
systems much simpler.

• The data-centered design approach enables us to capture more


details of model in an implementable form.
1. List different applications of OOPs.
answer

Application of OOPs
Now we have a basic idea of what object-oriented programming

3 of 33 12-12-2023, 18:52
Questions https://awaisahmed.notion.site/Questions-650d1a8c7efb4edc997c111aa...

Now we have a basic idea of what object-oriented programming


means, now let’s look at some of the applications of OOPs.

Real Time Systems


The term “real-time system” refers to any information processing
system with hardware and software components that perform real-
time application functions and can respond to events within
predictable and specific time constraints. For real-time computing,
timeliness and time synchronization are the two requirements.
Timeliness means the ability to produce the expected result by a
specific deadline and time synchronization means the capability of
agents to coordinate independent clocks and operate together in
unison. Using Object-oriented technology, we can develop real-time
systems, this will offer adaptability, ease of modifications, reusability
for the code. There is a lot of complexity involved in designing real-
time systems, OOP techniques make it easier to handle those
complexities.

Client Server System

The client-server systems are those that involve a relationship


between cooperating programs in an application. In general, the
clients will initiate requests for services and the servers will provide

4 of 33 12-12-2023, 18:52
Questions https://awaisahmed.notion.site/Questions-650d1a8c7efb4edc997c111aa...

clients will initiate requests for services and the servers will provide
that functionality. The client and server either reside in the same
system or communicate with each other through a computer network
or the internet.

The concepts of OOPs are quite useful when designing client-server


systems. Object-oriented client-server systems are used to provide the
IT Infrastructure that creates Object-oriented server internet or the
OCSI applications. The infrastructure refers to the operating systems,
networks, and hardware. OCSI contains the following main
technologies

• The Client Server

• Object Oriented Programming

• The Internet

Hypertext and Hypermedia


Hypertext is non-linear, multi-sequential, a cross-referencing tool that
connects the links to other texts, Example of Hypertext is that
InterviewBit, when we read one article it uses hypertext to link other
pages and when we click on that hypertext it takes to us to that page
so that we can gather more information related to the topic.
Hypermedia is the extension to hypertext including multiple forms of
media like graphics, text, audio, and video, etc. An example of
hypermedia is that when we use an e-commerce site say Amazon and
when we click on any product it takes us to the specific product page
which belongs to that. So here the link is embedded in the
image.OOP also helps in laying the framework for hypertext and
hypermedia

Object Oriented Database

5 of 33 12-12-2023, 18:52
Questions https://awaisahmed.notion.site/Questions-650d1a8c7efb4edc997c111aa...

Nowadays each and every data is being stored and processed, the
traditional model of storing data i.e the relational model stores each
and every piece of data in tables that consist of rows and columns.
However as complexity grows, storing in the form of tables becomes
quite cumbersome, here the need for storing in the form of real-world
objects comes into the picture. These databases try to maintain a
direct correspondence between the real-world and database objects
in order to let the object retain its identity and integrity. They can then
be identified and operated upon.

A popular example of object-oriented databases is MongoDB.

Neural Networks and Parallel Programming


A neural network is a series of algorithms that endeavors to recognize
underlying relationships in a set of data through a process that
mimics the way the human brain operates. In this sense, neural
networks refer to systems of neurons, either organic or artificial in
nature.

Parallel programming involves the division of a problem into smaller

6 of 33 12-12-2023, 18:52
Questions https://awaisahmed.notion.site/Questions-650d1a8c7efb4edc997c111aa...

Parallel programming involves the division of a problem into smaller


subproblems, the subproblems can be executed at the same time
using multiple computing resources. OOPs, are used to simplify the
process by simplifying the approximation and prediction ability of the
network.

AI Expert Systems

An AI Expert system is the one that simulates the decision-making


ability of a human expert, the expert knowledge can be increased
using different add-ons to the knowledge base or in simple words the
addition of rules. For example, PXDES is an expert system that predicts
the degree and type of lung cancer. There are many expert systems
out there.

OOPs, power the development of such AI Expert systems, To AI


systems use forward and backward chaining to reach a conclusion.
Basically, the chaining involves a chain of conditions and derivations
to deduce the outcome. An AI system has to be reliable, highly
responsive, and offers a high performance, to power such capabilities
OOPs are used.

Simulation and Modeling System


Modeling a complex system is quite difficult owing to the varying
specifications of the variables, such types of systems are prevalent in

7 of 33 12-12-2023, 18:52
Questions https://awaisahmed.notion.site/Questions-650d1a8c7efb4edc997c111aa...

medicine and in other areas of natural science, like zoology, ecology,


and agronomic systems. Simulation and modeling systems are the
imitations of the real world product. The system’s workings can be
checked and analyzed using object-oriented programming.

A good example of a simulation and modeling system is of


automobiles such as cars, Once the model of the car structure is
developed by the engineer’s team, as and when they feel that the
product is good to go they can release the product. OOP provides an
appropriate approach for simplifying these complex models.

Office Automation Systems


Nowadays companies use automated systems to share information
and communication to and from the people inside and outside the
organization. There are various works in the office for which the
employees can be replaced by automated robots and these works are
generally time-consuming and hard work. The company can reduce its
cost expenses by developing such a system.

To develop office automation systems, robot programming


automation or RPA is used. RPA uses Object-oriented programming.
1. Briefly explain the features of Java.
answer

A list of the most important features of the Java language is given


below.

8 of 33 12-12-2023, 18:52
Questions https://awaisahmed.notion.site/Questions-650d1a8c7efb4edc997c111aa...

1. Simple

2. Object-Oriented
3. Portable

4. Platform independent

5. Secured

6. Robust

7. Architecture neutral

8. Interpreted

9. High Performance

10. Multithreaded

11. Distributed

12. Dynamic
1. In detail explain the structure of the Java Program.
answer

Structure of Java Program


Java is an object-oriented programming, platform-
independent, and secure programming language that makes it
popular. Using the Java programming language, we can develop a
wide variety of applications. So, before diving in depth, it is necessary
to understand the basic structure of Java program in detail. In this
section, we have discussed the basic structure of a Java program. At
the end of this section, you will able to develop the Hello world Java
, easily.

9 of 33 12-12-2023, 18:52
Questions https://awaisahmed.notion.site/Questions-650d1a8c7efb4edc997c111aa...

program, easily.

Let's see which elements are included in the structure of a Java


program. A typical structure of a Java program contains the following
elements:

• Documentation Section

• Package Declaration

• Import Statements

• Interface Section

10 of 33 12-12-2023, 18:52
Questions https://awaisahmed.notion.site/Questions-650d1a8c7efb4edc997c111aa...

• Class Definition

• Class Variables and Variables

• Main Method Class

• Methods and Behaviors


1. Write a note on Keywords & Identifiers.
answer

C Keywords
Keywords are predefined, reserved words used in programming that
have special meanings to the compiler. Keywords are part of the
syntax and they cannot be used as an identifier. For example:

int money;

Here, int is a keyword that indicates money is a variable of


type int (integer).

As C is a case sensitive language, all keywords must be written in


lowercase. Here is a list of all keywords allowed in ANSI C.

Show All

Untitled
Title auto double

break else

case enum

char extern

continue for

default goto

const float

11 of 33 12-12-2023, 18:52
Questions https://awaisahmed.notion.site/Questions-650d1a8c7efb4edc997c111aa...

Untitled

All these keywords, their syntax, and application will be discussed in


their respective topics. However, if you want a brief overview of these
keywords without going further, visit List of all keywords in C
programming.

C Identifiers
Identifier refers to name given to entities such as variables, functions,
structures etc.

Identifiers must be unique. They are created to give a unique name to


an entity to identify it during the execution of the program. For
example:

int money; double accountBalance;

Here, money and accountBalance are identifiers.

Also remember, identifier names must be different from keywords.


You cannot use int as an identifier because int is a keyword.

Rules for naming identifiers


1. A valid identifier can have letters (both uppercase and lowercase
letters), digits and underscores.

2. The first letter of an identifier should be either a letter or an


underscore.

3. You cannot use keywords like int , while etc. as identifiers.

4. There is no rule on how long an identifier can be. However, you


may run into problems in some compilers if the identifier is longer
than 31 characters.

You can choose any name as an identifier if you follow the above rule,
however, give meaningful names to identifiers that make sense

12 of 33 12-12-2023, 18:52
Questions https://awaisahmed.notion.site/Questions-650d1a8c7efb4edc997c111aa...

1. Write a note on Variables, Constants & Separators.


Toggle
1. Explain different types of operators used in Java programming with
syntax & examples.
answer

1. Arithmetic Operators: They are used to perform simple arithmetic


operations on primitive data types.

• *: Multiplication

• / : Division

• % : Modulo

• + : Addition

• – : Subtraction

2. Unary Operators: Unary operators need only one operand. They


are used to increment, decrement or negate a value.

• – : Unary minus, used for negating the values.

• + : Unary plus indicates the positive value (numbers are positive


without this, however). It performs an automatic conversion to int
when the type of its operand is the byte, char, or short. This is
called unary numeric promotion.

• ++ : Increment operator, used for incrementing the value by 1.


There are two varieties of increment operators.

◦ Post-Increment: Value is first used for computing the result


and then incremented.

◦ Pre-Increment: Value is incremented first, and then the result


is computed.

• — : Decrement operator, used for decrementing the value by 1.


There are two varieties of decrement operators.

◦ Post-decrement: Value is first used for computing the result


and then decremented.

◦ Pre-Decrement: Value is decremented first, and then the


result is computed.

• ! : Logical not operator, used for inverting a boolean value.

13 of 33 12-12-2023, 18:52
Questions https://awaisahmed.notion.site/Questions-650d1a8c7efb4edc997c111aa...

• ! : Logical not operator, used for inverting a boolean value.

3. Assignment Operator: ‘=’ Assignment operator is used to


assigning a value to any variable. It has a right to left associativity, i.e.
value given on the right-hand side of the operator is assigned to the
variable on the left, and therefore right-hand side value must be
declared before using it or should be a constant.

The general format of the assignment operator is:

variable= value;

In many cases, the assignment operator can be combined with other


operators to build a shorter version of the statement called
a Compound Statement. For example, instead of a = a+5, we can
write a += 5.

• +=, for adding left operand with right operand and then
assigning it to the variable on the left.

• =, for subtracting right operand from left operand and then


assigning it to the variable on the left.

• =, for multiplying left operand with right operand and then


assigning it to the variable on the left.

• %=, for assigning modulo of left operand by right operand and


then assigning it to the variable on the left.

• /=, for dividing left operand by right operand and then assigning
it to the variable on the left.

4. Relational Operators: These operators are used to check for


relations like equality, greater than, and less than. They return boolean
results after the comparison and are extensively used in looping
statements as well as conditional if-else statements. The general
format is,

variablerelation_operator value

• Some of the relational operators are-

14 of 33 12-12-2023, 18:52
Questions https://awaisahmed.notion.site/Questions-650d1a8c7efb4edc997c111aa...

Some of the relational operators are-

◦ ==, Equal to returns true if the left-hand side is equal to the


right-hand side.

◦ !=, Not Equal to returns true if the left-hand side is not equal
to the right-hand side.

◦ <, less than: returns true if the left-hand side is less than the
right-hand side.

◦ <=, less than or equal to returns true if the left-hand side is


less than or equal to the right-hand side.

◦ >, Greater than: returns true if the left-hand side is greater


than the right-hand side.

◦ >=, Greater than or equal to returns true if the left-hand side


is greater than or equal to the right-hand side.

5. Logical Operators: These operators are used to perform “logical


AND” and “logical OR” operations, i.e., a function similar to AND gate
and OR gate in digital electronics. One thing to keep in mind is the
second condition is not evaluated if the first one is false, i.e., it has a
short-circuiting effect. Used extensively to test for several conditions
for making a decision. Java also has “Logical NOT”, which returns true
when the condition is false and vice-versa

Conditional operators are:

• &&, Logical AND: returns true when both conditions are true.

• ||, Logical OR: returns true if at least one condition is true.

• !, Logical NOT: returns true when a condition is false and vice-


versa

6. Ternary operator: Ternary operator is a shorthand version of the if-


else statement. It has three operands and hence the name ternary.

The general format is:

condition? if true: if false

1. Explain the process of creating a java program as an example and also


mention the steps used to execute the program.

15 of 33 12-12-2023, 18:52
Questions https://awaisahmed.notion.site/Questions-650d1a8c7efb4edc997c111aa...

answer

public class operators { public static void main(String[]


args) { int a = 20, b = 10, c = 30, result; `// result holds
max of three` numbers` `result` `= ((a > b) ? (a > c) ? a :
c : (b > c) ? b : c);` `System.out.println("Max of three
numbers = " + result); } }

1. Explain different data types used in Java.


answer

1. Explain different mathematical functions used in Java.


answer

Show All

Untitled

Math.abs() It will return the Absolute value of the


given value.

Math.max() It returns the Largest of two values.

Math.min() It is used to return the Smallest of two


values.

Math.round() It is used to round of the decimal numbers

16 of 33 12-12-2023, 18:52
Questions https://awaisahmed.notion.site/Questions-650d1a8c7efb4edc997c111aa...

to the nearest value.

Math.sqrt() It is used to return the square root of


a number.

Math.floor() It is used to find the largest integer value


which is less than or equal to the
argument and is equal to the
mathematical integer of a double value.
Method Description
Math.ceil() It is used to find the smallest integer value
that is greater than or equal to the
argument or mathematical integer.

Math.pow() It returns the value of first argument


raised to the power to second argument.

Math.exp() It returns E raised to the power of a

Math.sin() It is used to return the trigonometric Sine


value of a Given double value.

Math.cos() It is used to return the trigonometric


Cosine value of a Given double value.

Math.tan() It is used to return the trigonometric


Tangent value of a Given double value.

Math.log() It returns the natural logarithm of


a double value.

17 of 33 12-12-2023, 18:52

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy