Sunday, December 11

Quick way to see facebook 2016 year in review

Hi friends,

See your 2016 review on facebook!!

  1. Log into  Facebook
  2.  go to Facebook.com/yearinreview2016.
Enjoy

Saturday, August 6

KERALA PSC COMPUTER SCIENCE PREVIOUS QUESTIONS AND ANSWERS

Hello all,

In this post we will discuss various technical questions (Computer Science) and answers asked in KERALA PSC examinations like computer programmer, computer science lecturer etc.
Hope this will be helpful. :)


The questions were asked in Programmer (145/2015) post.


1. SCSI stand for :
(A) Small Computer Systems Interface
 (B) Simple Component Systems Interface
(C) Simple Computer Systems Interface
(D) Small Component Systems Interface

Answer A
·         SCSI stands for  Small Computer System Interface (SCSI)
·         It is a set of  interface standards for attaching printers, disk drives, scanners and other peripherals to computers.
·         SCSI is pronounced as "skuzzy"



2. Which of the following is a logical extension of multiprogramming?
(A) Multi processing
(B) Multitasking
(C) Real time processing
(D) Distributed processing


Answer B
Remember these terms:
Multiprogramming
  • One or more programs reside in main memory.
  • Only one job is executed at a time.
  • When current job is blocked or terminated next job is picked.
Multitasking
  • Extension of  multiprogramming.
  • Multiple jobs are executed at same time by switching between them.
Multiprocessing
  • More than one physical processor is present.
  • At a time more than one program get CPU for execution
Multithreading
Allows multiple threads to run at same time.
Multiuser
Many users can access at same time.
Real-time processing
A processing system that needs to be completed within a fixed time frame. Real-time processing does not have to be fast
Eg: traffic lights, car engine control
Distributed computing
components are located on networked computers and they communicate and coordinate their actions by passing messages




3. Which among the following is not an example of a Java wrapper class?
(A) Char 
(B) Integer
(C) Boolean
(D) Byte


Answer A
Wrapper class in java provides the mechanism to convert primitive into object and object into primitive.
Autoboxing: convert primitive to object
Unboxing: Convert object to primitive
Java has eight wrapper classes: Boolean, Character,  Byte, Short, Integer, Long,     Float and Double


4. Which one of the following is not an ACID property?
 (A) Atomicity
(B) Consistency
 (C) Isolation
(D) Dependency Preservation



Answer D

A DBMS should obey ACID properties to make the transactions correct.
ACID properties stand for Atomicity, Consistency, Isolation and Durability
ACID property
Definition
Responsibility of
Atomicity
Either all tasks of the transaction are completed in the database, or none are.
Recovery manager /Transaction manager
Consistency
Execution of a transaction must preserve the consistency of the database.
Eg: if a faulty money transfer program credits an amount less than it debited, the DBMS cannot detect it.
Users/ user programs.

Isolation
Each transaction will be executed as if it is the only transaction in the system.
Concurrency control
Durability
The database should hold all its latest updates even if the system fails.
Recovery manager





5. Which among the following sorting method is also known as Bucket sorting?
(A) Radix sort
(B) Heap sort  
(C) Merge sort
(D) Quick sort

Answer A:
·         The initial pass of both RadixSort and BucketSort is exactly the same.
·         The elements put in buckets of incremental ranges (e.g. 0-9, 10-19, ... 90-99)
·         In the next pass, however, BucketSort sort these 'buckets' and appends sorted buckets into one array. However, RadixSort appends the buckets without further sorting and 're-buckets' it based on the second digit of the numbers.
·         Hence, BucketSort is more efficient for 'Dense' arrays,
·         RadixSort can handle sparse arrays well.


6. Which one of the following key is called the minimal super key?
 (A) Candidate key
 (B) Super key
(C) Primary key
(D) None
Answer A
•           Candidate key: A set of fields that can uniquely identify a tuple in a relation.
•           Super-key: A set of fields in which at least one member is a candidate key.
•           Primary key: One of the candidate keys which administrator has been selected to identify a tuple.

Unique key: The fields should not have duplicate values in same table. It can have null values.

Saturday, February 13

RPC Sample code in Java



Hello friends,
In this post we will see how RPC (Remote Procedure Call) mechanism can be implemented in Java.
RMI (Remote Method Invocation)  is the special mechanism to do  RPC in Java. RMI is the java flavor of RPC in other languages, but core concept is still same!

The main Idea is summarized as below:

 In this example, we make a server (RMIServer.java) to receive input text from client application and replies how many characters it received.


Server Side:
  • Create a remote interface. (myInterface.java)
  • Create a separate java file to implement the remote interface. (RMIServer.java)
  • Register the interface in RMI registry (bind with any name eg: myRMIService)
Client Side:
  • In client code, through interface name (in our case myRMIService) create a "fake remote" object reference of server within client. (RMIClient.java)
  • Through this reference access the server methods / services


Let us have a detailed look on code:

1. MyInterface.java

  1. import java.rmi.*;
  2. public interface MyInterface extends Remote
  3. {
  4.  public String countInput(String input)throws RemoteException;   
  5. }

  • It simply says about a remote service to accept a string input and gives string output.
  • Line no 4  insists that any code implementing this interface should have countInput method.

2. RMIServer.java
  1. import java.rmi.*;
  2. import java.rmi.server.*;
  3. public class RMIServer extends UnicastRemoteObject implements MyInterface
  4.     public RMIServer()throws RemoteException
  5.     { 
  6.         System.out.println("Remote Server is running Now.!!"); 
  7.     }    
  8. public static void main(String arg[])
  9.     try{ 
  10.         RMIServer p=new RMIServer();
  11.         Naming.rebind("rmiInterface",p);
  12.     }  
  13. catch(Exception e)
  14. { System.out.println("Exception occurred : "+e.getMessage()); } 
  15. }

  16.     @Override
  17.     public String countInput(String input) throws RemoteException 
  18.     {
  19.     System.out.println("Received your input "+ input+"  at server!!");
  20.         String reply;
  21.         reply="You have typed "+ input.length() +"  letters!!";
  22.         return reply;
  23.     }
  24. }
  • Line 3 says we are going to implement MyInterface interface
  • Line 13 says we register this service with name rmiInterface. Any client can access the services from this class using this name.
  • Line 19-27 implements the methods offered by interface.
3. RMIClient.java
  1. import java.rmi.*;
  2. import java.io.*; 
  3. public class RMIClient
  4. {   
  5.     public static void  main(String args[])
  6.     { 
  7.         try
  8.       { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); 
  9.       MyInterface p=( MyInterface)Naming.lookup("rmiInterface");
  10.         System.out.println("Type something..."); 
  11.         String input=br.readLine(); 
  12.         System.out.println(p.countInput(input)); 
  13.             }
  14.         catch(Exception e) { 
  15.             System.out.println("Exception occurred : "+e.getMessage());
  16.         }
  17.     } 
  18.  
Line 9:  Looking for the remote service using the name!
Line 12: Accessing the service using the remote object.

RESULT:


Compile the java files.



Run remote object registry  called  rmiregistry. It is used by RMI servers on the same host to bind remote objects to names.


Run the Server class.

Run the client class. You can see it is prompting for input


Type some text
Input is received by remote server
   
                                          


Client receives reply from remote server



Hope this post was useful!!


Feel free to post your suggestions and comments!