Google Search

Saturday, October 24, 2015

Explain the steps involved in creating a distributed application using Remote Method Invocation (RMI).

Remote method invocation (RMI) allow a java object to invoke method on an object running on another machine. RMI provide remote communication between java program. RMI is used for building distributed application.
This is 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

Static variable and static method in java

static is a keyword in java and we can’t create a class or package name as static. Java static keyword can be used in four cases.
Java static variables: We can use static keyword with a class level variable. A static variable is a class variable and doesn’t belong to Object/instance of the class. Since static variables are shared across all the instances of Object, they are not thread safe. Usually static variables are used with final keyword for common resources or constants that can be used by all the objects. If the static variable is not private, we can access it with ClassName.variableName
//static variable example
private static int count;
public static String str;
public static final String DB_USER = "myuser";
Java static methods: Same as static variables, static methods belong to class and not to class instances. A static method can access only static variables of class and invoke only static methods of the class. Usually static methods are utility methods that we want to expose to be used by other classes without the need of creating an instance; for example Collections class. Java Wrapper classes and utility classes contains a lot of static methods. The main() method that is the entry point of a java program itself is a static method.
//static method example
public static void setCount(int count) {
if(count > 0)
StaticExample.count = count;
}
//static util method
public static int addInts(int i, int...js){
int sum=i;
for(int x : js) sum+=x;
return sum;
}

Define a flowchart

A flowchart is a graphical representation of decisions and their results mapped out in individual shapes that were first developed by Herman Goldstine and John von Neumann in the 1940's. Flowcharts can provide a step-by-step diagram for mapping out complex situations, such as programming code or troubleshooting problems with a computer.
A flow chart is a graphical or symbolic representation of a process. Each step in the process is represented by a different symbol and contains a short description of the process step. The flow chart symbols are linked together with arrows showing the process flow direction.

C program example of "Function with no arguments and no return value."

‪#‎include‬<stdio.h>
void area(); // Prototype Declaration
void main()
{
area();
}
void area()
{
float area_circle;
float rad;
printf("\nEnter the radius : ");
scanf("%f",&rad);
area_circle = 3.14 * rad * rad ;
printf("Area of Circle = %f",area_circle);
}
Output:
Enter the radius : 3
Area of Circle = 28.260000

PROLOG Code for Fibonacci Numbers

fibo(1,0).
fibo(2,1).
fibo(N,F):-N>1,N1 is N-1, fibo(N1,F1), N2 is N-2, fibo(N2,F2), F is F1+F2.

PROLOG Code for GCD

gcd(A,B,G):- A=B, G is A.
gcd(A,B,G):- A>B, AB is A-B, gcd(AB,B,G).
gcd(A,B,G):- A<B, BA is B-A, gcd(A,BA,G).

PROLOG Code for Factorial

fact(0,1).
fact(N,F):-N>0,N1 is N-1,fact(N1,F1),F is N*F1.