0% found this document useful (0 votes)
26 views25 pages

Module 5 Sa &DP

The document provides an overview of client-server systems, detailing the roles of clients and servers, their communication protocols, and the advantages and disadvantages of such networks. It also covers Remote Method Invocation (RMI) in Java, explaining the concepts of stubs and skeletons, and outlines the phases of object-oriented software development, including analysis, design, implementation, and testing. Additionally, it discusses control structures in programming, such as loops and conditional statements, with examples in C and Java.

Uploaded by

bhargavahero625
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)
26 views25 pages

Module 5 Sa &DP

The document provides an overview of client-server systems, detailing the roles of clients and servers, their communication protocols, and the advantages and disadvantages of such networks. It also covers Remote Method Invocation (RMI) in Java, explaining the concepts of stubs and skeletons, and outlines the phases of object-oriented software development, including analysis, design, implementation, and testing. Additionally, it discusses control structures in programming, such as loops and conditional statements, with examples in C and Java.

Uploaded by

bhargavahero625
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/ 25

MODULE – 5

Client-server system

A client-server system is a computing model that allows multiple devices to access resources from a central
server:

 Clients: Devices that request information from the server

 Servers: Devices that provide information to the clients

 Network: The connection between the clients and the server

In a client-server system, clients send requests to the server over a network, and the server responds with
the requested data or action. This model allows for centralized data management and application services.

Here are some key features of client-server systems:

 Request-response protocol: The client requests data, and the server responds with the requested
data.

 Standardized rules: The request-response protocol uses specific rules, guidelines, and languages to
ensure it's standardized across different types of servers.

 Security: The server can reject requests that go against its policies.

 TCP/IP protocol suite: Clients typically communicate with servers using the TCP/IP protocol suite.

The client-server model describes how a server gives one or more clients access to
resources and services. Mail servers, web servers, and file servers are examples of servers. Client
devices, including desktops, laptops, tablets, and mobile devices, have access to the resources on
each of these servers.

There are several types of client-server networks, including 1-tier architecture, 2-tier
architecture, 3-tier architecture, and n-tier architecture. One way to describe the difference between
them is by how they organize the presentation, business logic, and data layers.

Client

A client is a program that runs on the local machine requesting service from the server. A
client program is a finite program means that the service started by the user and terminates when the
service is completed.

Server

A server is a program that runs on the remote machine providing services to the clients.
When the client requests for a service, then the server opens the door for the incoming requests, but
it never initiates the service.

A server program is an infinite program means that when it starts, it runs infinitely unless the
problem arises. The server waits for the incoming requests from the clients. When the request arrives
at the server, then it responds to the request.

Advantages of Client-server networks:

o Centralized: Centralized back-up is possible in client-server networks, i.e., all the data is
stored in a server.

o Security: These networks are more secure as all the shared resources are centrally
administered.

o Performance: The use of the dedicated server increases the speed of sharing resources. This
increases the performance of the overall system.

o Scalability: We can increase the number of clients and servers separately, i.e., the new
element can be added, or we can add a new node in a network at any time.

Disadvantages of Client-Server network:

o Traffic Congestion is a big problem in Client/Server networks. When a large number of


clients send requests to the same server may cause the problem of Traffic congestion.
o It does not have a robustness of a network, i.e., when the server is down, then the client
requests cannot be met.

o A client/server network is very decisive. Sometimes, regular computer hardware does not
serve a certain number of clients. In such situations, specific hardware is required at the
server side to complete the work.

o Sometimes the resources exist in the server but may not exist in the client. For example, If
the application is web, then we cannot take the print out directly on printers without taking
out the print view window on the web.

RMI (Remote Method Invocation)

1. Remote Method Invocation (RMI)

2. Understanding stub and skeleton

1. stub

2. skeleton

3. Requirements for the distributed applications

4. Steps to write the RMI program

5. RMI Example

The RMI (Remote Method Invocation) is an API that provides a mechanism to create
distributed application in java. The RMI allows an object to invoke methods on an object running in
another JVM.

The RMI provides remote communication between the applications using two
objects stub and skeleton.

Understanding stub and skeleton

RMI uses stub and skeleton object for communication with the remote object.
A remote object is an object whose method can be invoked from another JVM. Let's
understand the stub and skeleton objects:

stub

The stub is an object, acts as a gateway for the client side. All the outgoing requests are
routed through it. It resides at the client side and represents the remote object. When the caller
invokes method on the stub object, it does the following tasks:

1. It initiates a connection with remote Virtual Machine (JVM),

2. It writes and transmits (marshals) the parameters to the remote Virtual Machine (JVM),

3. It waits for the result

4. It reads the return value or exception, and

5. It finally, returns the value to the caller.

skeleton

The skeleton is an object, acts as a gateway for the server side object. All the incoming
requests are routed through it. When the skeleton receives the incoming request, it does the
following tasks:

1. It reads the parameter for the remote method

2. It invokes the method on the actual remote object, and

3. It writes and transmits (marshals) the result to the caller.


Understanding requirements for the distributed applications

If any application performs these tasks, it can be distributed application..

1. The application need to locate the remote method

2. It need to provide the communication with the remote objects, and

3. The application need to load the class definitions for the objects.

The RMI application have all these features, so it is called the distributed application.

Java RMI Example

The is given the 6 steps to write the RMI program.

1. Create the remote interface

2. Provide the implementation of the remote interface

3. Compile the implementation class and create the stub and skeleton objects using the rmic tool

4. Start the registry service by rmiregistry tool

5. Create and start the remote application

6. Create and start the client application


RMI Example

In this example, we have followed all the 6 steps to create and run the rmi application. The
client application need only two files, remote interface and client application. In the rmi application,
both client and server interacts with the remote interface. The client application invokes methods on
the proxy object, RMI sends the request to the remote JVM. The return value is sent back to the
proxy object and then to the client application.

1) create the remote interface

For creating the remote interface, extend the Remote interface and declare the Remote
Exception with all the methods of the remote interface. Here, we are creating a remote interface that
extends the Remote interface. There is only one method named add() and it declares Remote
Exception.

1. import java.rmi.*;
2. public interface Adder extends Remote{

3. public int add(int x,int y)throws Remote Exception;

4. }

2) Provide the implementation of the remote interface

Now provide the implementation of the remote interface. For providing the implementation
of the Remote interface, we need to

 Either extend the Unicast Remote Object class,

 or use the export Object() method of the Unicast Remote Object class

In case, you extend the Unicast Remote Object class, you must define a constructor that
declares Remote Exception.

1. import java.rmi.*;

2. import java.rmi.server.*;

3. public class AdderRemote extends UnicastRemoteObject implements Adder{

4. AdderRemote()throws RemoteException{

5. super();

6. }

7. public int add(int x,int y){return x+y;}

8. }

3) create the stub and skeleton objects using the RMIc tool.

Next step is to create stub and skeleton objects using the RMI compiler. The RMIc tool
invokes the RMI compiler and creates stub and skeleton objects.

1. RMI Adder Remote


4) Start the registry service by the RMI registry tool

Now start the registry service by using the RMI registry tool. If you don't specify the port
number, it uses a default port number.

Implementing an object-oriented system on the web:

Object Oriented Implementation is a Phase in Software Development where the design model
and the Structure that is developed in Object Oriented Analysis and Object oriented Design is
translated into actual Code using Appropriate Programming Language.

Object Oriented Implementation is a Phase in Software Development where the design


model and the Structure that is developed in Object Oriented Analysis and Object oriented Design
is translated into actual Code using Appropriate Programming Language. In this phase we convert
the design and structure of software into actual code using an Object Oriented Programming.

Object Oriented Testing

Object Oriented Testing is the last Phase in Software Development that focus on Verify and
Valid

ating the functionality of Software System. This phase verify the Actual Code and
Performance of Object Oriented System, it uses specialized techniques to identify and remove the
errors in the Code. Object Oriented Testing encompasses various levels of testing which Includes
unit testing, integration testing, system testing and so on. Object Oriented Testing ensures reliability
and quality of Object Oriented Software System.
Object-oriented systems are database systems that can directly implement conceptual models
and represent complexities beyond the capabilities of relational systems. They are particularly useful
for handling highly interrelated data, such as product definitions, multimedia, or bills of materials.

Object-oriented systems are database systems that can directly implement conceptual models
and represent complexities beyond the capabilities of relational systems. They are particularly useful
for handling highly interrelated data, such as product definitions, multimedia, or bills of materials.
Additionally, object-oriented databases can store both data and instructions on how to manipulate the
data, making them well-suited for handling unstructured data like photographs, graphics, audio, and
video.

Object-Oriented Modelling (OOM) technique visualizes things in an application by using


models organized around objects. Any software development approach goes through the following
stages −

 Analysis,

 Design, and

 Implementation.

In object-oriented software engineering, the software developer identifies and organizes the
application in terms of object-oriented concepts, prior to their final representation in any specific
programming language or software tools.

Phases in Object-Oriented Software Development

The major phases of software development using object–oriented methodology are object-
oriented analysis, object-oriented design, and object-oriented implementation.

Object–Oriented Analysis

In this stage, the problem is formulated, user requirements are identified, and then a model is
built based upon real–world objects. The analysis produces models on how the desired system
should function and how it must be developed. The models do not include any implementation
details so that it can be understood and examined by any non–technical application expert.

Object–Oriented Design

Object-oriented design includes two main stages, namely, system design and object design.
System Design

In this stage, the complete architecture of the desired system is designed. The system is
conceived as a set of interacting subsystems that in turn is composed of a hierarchy of interacting
objects, grouped into classes. System design is done according to both the system analysis model
and the proposed system architecture. Here, the emphasis is on the objects comprising the system
rather than the processes in the system.

Object Design

In this phase, a design model is developed based on both the models developed in the system
analysis phase and the architecture designed in the system design phase. All the classes required are
identified. The designer decides whether −

 new classes are to be created from scratch,

 any existing classes can be used in their original form, or

 new classes should be inherited from the existing classes.

The associations between the identified classes are established and the hierarchies of classes
are identified. Besides, the developer designs the internal details of the classes and their associations,
i.e., the data structure for each attribute and the algorithms for the operations.

Object–Oriented Implementation and Testing

In this stage, the design model developed in the object design is translated into code in an
appropriate programming language or software tool. The databases are created and the specific
hardware requirements are ascertained. Once the code is in shape, it is tested using specialized
techniques to identify and remove the errors in the code.
Selection Staements

Repetitive statements (Iterativestatements)

There may be a situation, when you need to execute a block of code several number of times.
In general, statements are executed sequentially: The first statement in a function is executed first,
followed by the second, and so on.Programming languages provide various control structures that
allow for more complicated execution paths.A loop statement orrepetitive statement allows us to
execute a statement or group of statements multiple times.

C programming language provides the following types of loop to handle looping


requirements. Click the following links to check their detail.

Loop Type Description

while loop Repeats a statement or group of statements while a given


condition is true. It tests the condition before executing theloop
body.

forloop Execute a sequence of statements


multiple times and abbreviates the code that
manages the loop variable.

do...while loop Like a while statement, except that it tests the condition at
the end of the loop body

nestedloops You can use one or more loop inside any another while,
for or do..while loop.

while loop

Thewhileloopcheckswhetherthetestexpressionistrueornot.Ifitistrue, code/s inside the body of


while loop is executed,that is, code/s inside the braces { }
areexecuted.Thenagainthetestexpressionischeckedwhethertestexpressionistrueor
not.Thisprocesscontinuesuntilthetestexpressionbecomesfalse.
Syntaxofwhileloop,

while(testexpression)

statement/stobeexecuted.

}
Flow of while loop,

Continue Statement

It is sometimes desirable to skip some statements inside the loop. In such cases, continue
statements are used.

Syntaxis,

continue;

Just like break, continue is also used with condition al if statement.


Example:

Writea C program to find the produc to 4 integer sentered by a user.

//programtodemonstratetheworkingofcontinuestatementinCprogramming # include
<stdio.h>
int main(){
inti,num,product;
for(i=1,product=1;i<=4;++i){printf
("Enter num%d:",i);
scanf("%d",&num);if(num==0)
continue;/*Inthisprogram,whennumequalstozero,itskipsthestatement
product*=numandcontinuetheloop.*/
product*=num;

printf("product=%d",product);ret
urn0;
}

Output

1. if Statement:

The "if" statement is an essential component of programming that enables conditional


execution of instructions based on a specified condition. The "if" statement assesses a
specified condition, executing a predefined set of commands when the condition is true and
skipping them otherwise. Essentially, it functions as a way to pose a question in code and
generate a corresponding response based on the condition's evaluation.

Syntax:

1. if (condition) {

2. //Code is being executed if the condition is true

3. }

o Condition: An expression that evaluates to a boolean value (true or false).

o If the condition is true, the Code inside the curly braces {} is executed.
o If the condition is false, the Code inside the curly braces is skipped, and the program
continues with the following statement after the if block

Filename: NumberClassifier.java

1. // Defining a class named NumberClassifier to classify user-entered numbers

2. public class NumberClassifier {

3. public static void main(String[] args) {

4. int number = 5; // You can replace this with any integer value

5.

6. // Checking if the number is positive using an 'if' statement

7. if (number > 0) {

8. // Printing a message if the number is positive

9. System.out.println("The entered number is positive.");

10. }

11. // Checking if the number is negative using another 'if' statement

12. if (number < 0) {

13. // Printing a message if the number is negative

14. System.out.println("The entered number is negative.");

15. }

16. // Checking if the number is zero using a third 'if' statement

17. if (number == 0) {

18. // Printing a message if the number is zero

19. System.out.println("The entered number is zero.");

20. }
21. }

22. }

Output:

The entered number is positive.

2. if-else Statement:

The if-else statement serves as a control flow construct that allows for the efficient
implementation of conditional logic. By providing two separate blocks of code to execute
based on whether a specified condition is met or not, this statement expands upon the
functionality of the traditional if statement. Essentially, it offers a means of handling both
true and false outcomes of a condition with ease.

Syntax:

1. if (condition) {

2. //Code to be executed if the condition is true

3. } else {

4. //If the is condition is false the code is being executed


5. }

o Condition: In Java, expressions produce a Boolean outcome, representing either true


or false.

o If the condition derived from the expression is true, the code enclosed within the first
pair of curly brackets is executed.

o Conversely, when the condition evaluates to false, the code within the second pair of
curly brackets (following the else keyword) is executed.

o The conditional structure enables the program to take different actions based on the
true or false result of the expression.

Filename: EligibilityChecker.java

1. public class Eligibility Checker {

2. public static void main(String[] args) {

3. // For illustration purposes, using a predetermined value instead of user input

4. int userAge = 10; // You can replace this with any integer value

5.

6. // Ascertain whether the individual is eligible to vote using an if statement

7. if (userAge >= 18) {

8. System.out.println("Congratulations! You have attained the eligible voting age


.");

9. } else {

10. System.out.println("Apologies, you are currently not eligible to vote.");

11. System.out.println("You will achieve voting eligibility in " + (18 -


userAge) + " year(s).");

12. }

13. }
14. }

Output:

Apologies, you are currently not eligible to vote.

You will achieve voting eligibility in 8 year(s).

3. Nested if Statement

In Java, a nested if Statement is an if Statement that is inside another if Statement. It


means you can have one or more if statements inside another if Statement's block. The inner
if statements are executed only if the outer if Statement's condition is true.

Syntax:

1. if (condition1) {

2. //Code to be executed if condition1 is true

3. if (condition2) {

4. // code to be executed if both condition1 and condition2 are true

5. }
6. // more Code inside the outer if block

7. }

8. //Code outside the outer if block

In this structure, the condition is evaluated first. If it is true, the inner block of the
Code is executed. Inside the inner block, condition2 is considered. If it is also true, the Code
inside the inner if Statement is executed.

Filename: NestedIfStatementExample.java

1. public class NestedIfStatementExample {

2.

3. public static void main(String[] args) {

4. int number = 75; // You can replace this with any integer value

5.

6. // Validate if the number is below 100

7. if (number < 100) {

8. System.out.println("The given number is less than 100.");

9.

10. // Check if the number is evenly divisible by 5

11. if (number % 5 == 0) {

12. System.out.println("It is a multiple of 5.");

13. } else {

14. System.out.println("It is not a multiple of 5.");

15. }

16. } else {
17. System.out.println("The given number is greater than or equal to 100.");

18. }

19.

20. System.out.println("Exiting the nested if-


else block."); // Signify the end of the nested if-else block

21. }

22. }

Output:

The given number is less than 100.

It is a multiple of 5.

Exiting the nested if-else block.

4. if- else if- else Statement

In Java, the if-else if-else Statement acts as a decision-making tool, enabling you to
execute different code blocks based on various conditions. It's a versatile tool for handling
multiple possible outcomes in your program. Think of it as a branching path where you
choose the appropriate direction based on specific criteria.
Syntax:

1. if (condition1) {

2. //Code to be executed if condition1 is true

3. } else if (condition2) {

4. //Code to be executed if condition2 is true

5. } else {

6. //Code to be executed if all conditions are false

7. }

o The if Statement checks condition1. If condition1 is true, the corresponding block of


Code inside the first set of curly braces is executed.
o If condition1 is false, the program evaluates condition2 specified after the else if. If
condition2 is true, the corresponding block of Code inside the second set of curly
braces is executed.

o If both condition1 and condition2 are false, the Code inside the else block is executed.

Arrays

An array is a data structure that stores multiple pieces of data of the same type in a
contiguous memory location. Arrays are often used to organize data in a table-like format,
with each element in the array represented by a cell in the table.

Here are some key points about arrays:

 Data type

All data in an array must be of the same data type. For example, an array might store a list of
scores, or a list of images.

 Indexing

Each element in an array is identified by an index or key. In computers, array indexes start at
0, so the first element in an array is, the second element is, and so on.

 Length

The length of an array is fixed when it is created.

 Efficiency
Arrays are an efficient way to manage related data. For example, instead of creating a
separate variable for each score in a game, you can use an array to store all the scores under
one name.
Array in C++:

int arr[5];

arr[0] = 5;

arr[2] = -10;

// this is same as arr[1] = 2


arr[3 / 2] = 2;

arr[3] = arr[0];

cout << arr[0] << " " << arr[1] << " " << arr[2] << " "

<< arr[3];

Array declaration in Python:

cars = [“Ford”, “Volvo”, “BMW”]

Similarly an array can be of any data type such as double, float, short etc.

Various ways to initialize an array

In the above example, we have just declared the array and later we initialized it with
the values input by user. However you can also initialize the array during declaration like
this:

int arr[5] = {1, 2, 3, 4 ,5};

OR (both are same)

int arr[] = {1, 2, 3, 4, 5};

Un-initialized array always contain garbage values.

You might also like