t1
Concurrent programming is also known as multithreaded programming . Multithreaded or concurrent program has multiple threads running simultaneously and so may handle multiple tasks at the same time during execution. It’s not necessary to have a multiprocessor systems to run a multithreading program.
Threads can be created and declared in one of two ways:
By directly extending the java.lang.Thread class
2. By implementing the java.lang.Runnable interface.
Life Cycle of Threads:
New
Alive
Dead
Synchronization:
In Java the reading and assignment of variables of primitive types, except long and double, are atomic. All other operations should be synchronized to ensure atomicity.
class MyClass {
synchronizedvoid aMethod() {
<dosomething>
}
}
A synchronized instance method in Java is synchronized on the instance (object) owning the method. Thus, each instance has its synchronized methods synchronized on a different object: the owning instance.
Synchronized static methods are synchronized on the class object of the class the synchronized static method belongs to. Since only one class object exists in the JVM per class, only one thread can execute inside a static synchronized method in the same class.
Multicasting
Multicasting, is the Internet’s version of broadcasting.
Most high-level network protocols only provide a unicast transmission service. That is, nodes of the network only have the ability to send to one other node at a time.
Multicast groups
The notion of “group” is essential to the concept of multicasting. By definition a multicast message is sent from a source to a group of destination hosts. In IP multicasting, multicast groups have an ID called multicast group ID
Different types of IP addresses
There are three types of IP addresses: unicast, broadcast, and multicast.
Unicast addresses are used for transmitting a message to a single destination node.
Broadcast addresses are used when a message is supposed to be transmitted to all nodes in a subnetwork.
Multicastaddresses are used for delivering a message to a group of destination nodes which are not necessarily in the same subnetwork.
Java and Multicasting
java.net.MulticastSocket. and java.net.DatagramPacket together used to implement multicasting in java and makes programming easier.
Advantages of Multicasting
decrease of the network load
resource discovery.
Datacasting
flexibility in joining and leaving a group
Remote Method Invocation (RMI)
1. Remote I/O files
We can read all kinds of files from a remote server. To be able to input a remote file in LINUX/UNIX operating system we should have the file in the folder public html.
2. Remote Method Invocation (RMI)
Remote Method Invocation (RMI) supports Objects call. RMI allows a Java program on one machine to invoke (call) a method on a remote object.
Cookies
A cookie is a piece of information. A server sends a cookie to a browser to be stored in the client computer and some attributes such as a comments, path, a maximum age, and a version number. After this process if the client makes a request from the server the cookie will be sent to the server. One of the benefits of cookies is remembering the user names and passwords.
The javax.servlet.http contains a Cookie class that allows us to quickly set up and process HTTP cookies and a HttpSession class that provides session tracking.
A cookie has a name, a single value, and optional attributes such as a comment, path and domain qualifiers, a maximum age, and a version number. Some Web browsers have bugs in how they handle the optional attributes, so use them sparingly to improve the interoperability of your servlets.
The servlet sends cookies to the browser by using the HttpServletResponse.addCookie(javax.servlet.http.Cookie)
The browser returns cookies to the servlet by adding fields to HTTP request headers. Cookies can be retrieved from a request by using the HttpServletRequest.getCookies() method.
Serialization
Serialization is a technique of converting the state of an object into a byte stream. Deserialization is the reverse process where the byte stream is used to recreate the actual Java object in memory.
To make a Java object serializable we implement the java.io.Serializable interface.
The ObjectOutputStream class contains writeObject() method for serializing an Object.
Java Beans
JavaBeans are classes that encapsulate many objects into a single object (the bean). They are serializable, have a zero-argument constructor, and allow access to properties using getter and setter methods.
JSP
Java Server Pages (JSP) is a server-side programming technology
It enables creation of:
Dynamic web pages
Web applications with dynamic contents
Usage :
Collect input from users through Webpage forms
Present records from a database
Present records from other sources – like a flat file and excel file
Create Webpages dynamically
Registering user preferences
Servlet
Java Servlets are programs that run on a Web or Application server
It acts as a middle layer between:
– a requests coming from a Web browser and database
– a HTTP client and applications on the HTTP server
Usage
Collect input from users through web page forms
Present records from a database
Present records from other sources – like flat file and excel
Create web pages dynamically