Wednesday, January 24, 2018

RMI Lab Network




 Using Intelij RMI &  Netbean:

 

Interface:   RmiServerIntf.java

 

import java.rmi.Remote;
import java.rmi.RemoteException;

public interface RmiServerIntf extends Remote{
   
public String getMessage() throws RemoteException;

}

 

//Implementation: RmiImp.java

 

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
public class RmiImp extends UnicastRemoteObject implements RmiServerIntf {

   
public static final String MESSAGE = "Hello World";

   
public RmiImp() throws RemoteException {
       
super(0);
    }

   
public String getMessage() {
       
return MESSAGE;
    }
}

 

 

 //Server: 


import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;



public class RmiServer  {

   
public static void main(String[] args) throws RemoteException, MalformedURLException {
        System.
out.println("RmiServer Strarted");


       
try{

            LocateRegistry.createRegistry(
1099);
            System.
out.println("java RMI registry created");
            RmiImp obj =
new RmiImp();
            Naming.rebind(
"rmi://localhost/RmiServer",obj);
            System.
out.println("PeerServer bound in registy");
        }
       
catch(RemoteException re){

            System.
out.println("java RMI registry already exist");
        }
    }

}

 

//Client:

public class RmiClient {
   
public static void main(String[] args) throws Exception {
        RmiServerIntf obj = (RmiServerIntf) Naming.lookup(
"rmi://localhost/RmiServer");
        System.
out.println(obj.getMessage());
    }
}

Thursday, January 11, 2018

Telnet

 Install Telnet

  1. Click Start.
  2. Select Control Panel.
  3. Choose Programs and Features.
  4. Click Turn Windows features on or off.
  5. Select the Telnet Client option.
  6. Click OK. A dialog box appears to confirm installation. The telnet command should now be available.

Wednesday, March 9, 2016

MCQ Questions & Answers – Networking – Datagrams

This set of Java Multiple Choice Questions & Answers (MCQs) focuses on “Networking – Datagrams”.

1. Which of these is a bundle of information passed between machines?
a) Mime
b) Cache
c) Datagrams
d) DatagramSocket
View Answer

Answer: c
Explanation: The Datagrams are the bundle of information passed between machines.

2. Which of these class is necessary to implement datagrams?
a) DatagramPacket
b) DatagramSocket
c) All of the mentioned
d) None of the mentioned
View Answer

Answer: c
Explanation: None.

3. Which of these method of DatagramPacket is used to find the port number?
a) port()
b) getPort()
c) findPort()
d) recievePort()
View Answer

Answer: b
Explanation: None.

4. Which of these method of DatagramPacket is used to obtain the byte array of data contained in a datagram?
a) getData()
b) getBytes()
c) getArray()
d) recieveBytes()
View Answer

Answer: a
Explanation: None.

5. Which of these methods of DatagramPacket is used to find the length of byte array?
a) getnumber()
b) length()
c) Length()
d) getLength()
View Answer

Answer: d
Explanation: getLength returns the length of the valid data contained in the byte array that would be returned from the getData () method. This typically is not equal to length of whole byte array.

6. Which of these class must be used to send a datagram packets over a connection?
a) InetAdress
b) DatagramPacket
c) DatagramSocket
d) All of the mentioned
View Answer

Answer: d
Explanation: By using 5 classes we can send and receive data between client and server, these are InetAddress, Socket, ServerSocket, DatagramSocket, and DatagramPacket.

7. Which of these method of DatagramPacket class is used to find the destination address?
a) findAddress()
b) getAddress()
c) Address()
d) whois()
View Answer

Answer: b
Explanation: None.

8. Which of these is a return type of getAddress() method of DatagramPacket class?
a) DatagramPacket
b) DatagramSocket
c) InetAddress
d) ServerSocket
View Answer

Answer: c
Explanation: None.

9. Which API gets the SocketAddress (usually IP address + port number) of the remote host that this packet is being sent to or is coming from.
a) getSocketAddress()
b) getAddress()
c) address()
d) none of the mentioned
View Answer

Answer: a
Explanation: getSocketAddress() is used to get the socket address.


Tuesday, March 8, 2016

MCQ “URL Class"

This set of Java Multiple Choice Questions & Answers (MCQs) focuses on “URL Class”.

1. What does URL stands for?
a) Uniform Resource Locator
b) Uniform Resource Latch
c) Universal Resource Locator
d) Universal Resource Latch
View Answer

Answer: a
Explanation: URL is Uniform Resource Locator.

2. Which of these exceptions is thrown by URL class’s constructors?
a) URLNotFound
b) URLSourceNotFound
c) MalformedURLException
d) URLNotFoundException
View Answer

Answer: c
Explanation: None.

3. Which of these methods is used to know host of an URL?
a) host()
b) getHost()
c) GetHost()
d) gethost()
View Answer

Answer: b
Explanation: None.

4. Which of these methods is used to know the full URL of an URL object?
a) fullHost()
b) getHost()
c) ExternalForm()
d) toExternalForm()
View Answer

Answer: d
Explanation: None.

5. Which of these class is used to access actual bits or content information of a URL?
a) URL
b) URLDecoder
c) URLConnection
d) All of the mentioned
View Answer

Answer: d
Explanation: URL, URLDecoder and URLConnection all there are used to access information stored in a URL.

6. What will be the output of the following Java code?

  1.     import java.net.*;
  2.     class networking 
  3.     {
  4.         public static void main(String[] args) throws MalformedURLException 
  5.         {
  6.             URL obj = new URL("https://www.sanfoundry.com/javamcq");
  7.             System.out.print(obj.getProtocol());
  8.         }
  9.     }

a) http
b) https
c) www
d) com
View Answer

Answer: a
Explanation: obj.getProtocol() is used to know the protocol used by the host. http stands for hypertext transfer protocol, usually 2 types of protocols are used http and https, where s in https stands for secured.
Output:

$ javac networking.java
$ java networking 
http

7. What will be the output of the following Java program?

advertisement
  1.     import java.net.*;
  2.     class networking 
  3.     {
  4.         public static void main(String[] args) throws MalformedURLException 
  5.         {
  6.             URL obj = new URL("https://www.sanfoundry.com/javamcq");
  7.             System.out.print(obj.getPort());
  8.         }
  9.     }

a) 1
b) 0
c) -1
d) garbage value
View Answer

Answer: c
Explanation: Since we have not explicitly set the port default value that is -1 is printed.
Output:

$ javac networking.java
$ java networking 
-1

8. What will be the output of the following Java program?

  1.     import java.net.*;
  2.     class networking
  3.     {
  4.         public static void main(String[] args) throws MalformedURLException 
  5.         {
  6.             URL obj = new URL("https://www.sanfoundry.com/javamcq");
  7.             System.out.print(obj.getHost());
  8.         }
  9.     }

a) sanfoundry
b) sanfoundry.com
c) www.sanfoundry.com
d) https://www.sanfoundry.com/javamcq
View Answer

Answer: c
Explanation: None.
Output:

advertisement
$ javac networking.java
$ java networking 
www.sanfoundry.com

9. What will be the output of the following Java program?

  1.     import java.net.*;
  2.     class networking
  3.     {
  4.         public static void main(String[] args) throws MalformedURLException
  5.         {
  6.             URL obj = new URL("https://www.sanfoundry.com/javamcq");
  7.             System.out.print(obj.toExternalForm());
  8.         }
  9.     }

a) sanfoundry
b) sanfoundry.com
c) www.sanfoundry.com
d) https://www.sanfoundry.com/javamcq
View Answer

Answer: d
Explanation: toExternalForm() is used to know the full URL of an URL object.
Output:

$ javac networking.java
$ java networking 
https://www.sanfoundry.com/javamcq

Configure LOG4J in INTELLIJ in Windows.

IntelliJ debugger for temporary logging In this video, it is shown how to use Log4j in Intellij. Sorry for the audio quality :) Log4j zip fi...