Important Java Questions
Q1: What is J2SE, J2EE, and J2ME?
Java Standard Edition.
This is the core Java programming platform. It contains all of the libraries and APIs that any Java programmer should learn (java.lang, java.io, java.math)
Apps we can build using J2SE are Standalone applications e.g. Calculator Client-Server applications using Sockets (Client Socket and Server Sockets)
Java Enterprise Edition.
J2EE is a platform-independent, Java-centric environment from Sun for developing, building and deploying Web-based enterprise applications online. The J2EE platform consists of a set of services, APIs, and protocols that provide the functionality for developing multitier, Web-based applications.
Web Apps. E.g. Online Student Management System, Enterprise and Distributed Apps.
Java Micro Edition.
This is the platform for developing applications for mobile devices and embedded systems such as set-top boxes. Java ME provides a subset of the functionality of Java SE, but also introduces libraries specific to mobile devices. Because Java ME is based on an earlier version of Java SE, some of the new language features introduced in Java 1.5 (e.g. generics) are not available.
Q2: Why say that HTTP is a stateless protocol?
HTTP is a stateless protocol. A stateless protocol does not require the server to retain information or status about each user for the duration of multiple requests.
But some web applications may have to track the user's progress from page to page, for example when a web server is required to customize the content of a web page for a user.
HTTP is a stateless protocol, which means that the connection between the browser and the server is lost once the transaction ends.
¨ HTTP are stateless protocol because it treats each request independently and have no knowledge of where the request have came from.
¨ A stateless protocol treats each request and response pair as an independent transaction.
¨ Default port no of HTTP is 80.
Q3: What is HTTP Communication model?
A communications model Client, often but not always a web browser, sends a request for a resource to a server.
- The server returns a response or an error message.
- · Stateless
- · No immediate feedback
- · No details on how request is made
- Different clients like
- · Web browsers
- · FTP clients (e.g., interarchy on MacOS X)
- · Software registration programs
- · telnet
Q4: What are the parts of http request response?
Parts of an HTTP request
Request Method
URI
Header Fields
Header Fields
Body
q Result Code
q Header Fields
q Body
HTTP Request Example
HTTP Response Codes
Codes fall into five general categories
100-199
Codes in the 100s are informational, indicating that the client should respond with some other action.
200-299
Values in the 200s signify that the request was successful.
300-399
Values in the 300s are used for files that have moved and usually include a Location header indicating the new address.
400-499
Values in the 400s indicate an error by the client.
500-599
Codes in the 500s signify an error by the server.
200: means every thing is fine.
404: Indicates that the requested resource is not available
401: Indicates that the request requires HTTP authentication (User name and password)
503: Indicates that the HTTP server is temporarily overloaded and unable to handle the request
Q: What are the HTTP METHODS?
Trace
Put
Options
Head
Delete
Q: What the java.net package Do?
Answer:
The
java.net
package in the Java platform provides a class, Socket
, that implements one side of a two-way connection between your Java program and another program on the network.
Q: What is Socket?
Answer:
A socket is one endpoint of a two-way communication link between two programs running on the network. A socket is bound to a port number so that the TCP layer can identify the application that data is destined to be sent to.
Q: What is ServerSocket?
Answer:
Java.net
includes the ServerSocket
class, which implements a socket that servers can use to listen for and accept connections to clients. This lesson shows you how to use the Socket
and ServerSocket
classes.
Q:What is a Port
Answer:
Q:How to make a simple client and serverAnswer:
- To uniquely identify each and different application Port numbers are used.These are the endpoint and way of the communications between two computers.
- For communication between two devices or application Port number are associated with the ip address of these devices.
- Port numbers are from 0 to 65535. Ports 0 to 1024 are reserved for use by certain privileged services.
Simple Client
package client_server;import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
public class Client_Server {
public static void main(String[] args) {
try {
Socket s =new Socket("localhost",10);
OutputStream os=s.getOutputStream();
PrintWriter pw= new PrintWriter(os, true);
pw.println("mazhar");
} catch (Exception e) {
System.out.println("Some exception has accoured");
}
}
}
Simple Server
package server;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
public class Server {
public static void main(String[] args) {
try {
ServerSocket server=new ServerSocket(10);
Socket s=server.accept();
InputStream is =s.getInputStream();
InputStreamReader isr=new InputStreamReader(is);
BufferedReader br=new BufferedReader(isr);
String data=br.readLine();
System.out.println("welocome"+" "+data);
}
catch (Exception e) {
}
}
}
Comments
Post a Comment