Professional Documents
Culture Documents
1
INDEX
2
1. INTRODUCTION
2. ECLIPSE
The Eclipse IDE has a very long development history. In November 2001, IBM created
the Eclipse Project to implement a Java-based IDE that supports development of embedded
Java applications. The initial version of Eclipse derives from Visual Age - a multi-
programming language IDE from IBM.
In January 2004, the Eclipse Foundation was established as an independent not-for-profit
corporation to transparently develop the Eclipse Project as an open and vendor-neutral
product.
Originally created for developing a Java IDE, the Eclipse Foundation is now developing a
wide range of development tools that support many programming languages: C/C++, PHP,
Javascript, Python, Rust…However Eclipse is best known as the most widely used IDE for
Java development.
Because the Eclipse Foundation releases many packages for different programming
languages and different domains, in this course the name Eclipse or Eclipse IDE refers to the
package Eclipse IDE for Java EE Developers. And as Java programmer, you use this
package most of the time.
3
For me, I started using Eclipse in 2004 - Eclipse 3.0 with JDK 1.4.
Eclipse is free and open-source, which means you can use it at no cost and access its source
code if needed. Today, Eclipse is the most widely used IDE for developing Java applications,
with millions of programmers using every day. The homepage of Eclipse is eclipse.org.
Eclipse IDE is written mostly in Java and some native parts are written in C/C++. Eclipse can
run on major operating systems like Windows, Mac and Linux. So if you are using Eclipse
IDE, you are actually running a Java application!
Eclipse has a long history of development so it has been evolving over many versions.
Eclipse uses interesting naming for its versions, mostly based on astronomy scheme: Juno,
Kepler, Luna, Mars, Neon, Oxygen, Photon…and the latest version uses different naming
scheme, i.e. month-year format: Eclipse 2018-09.
Though evolving over many versions, the key concepts, structure and working of the IDE
remain unchanged. Mostly new features and improvements were added.
2.3. ADVANTAGES
1. It is free and open source.
2. Industrial level of development
3. It supports many other languages other than JAVA.
4. Framework integration like Junit and TestNG and other plugins can be done
easily.
5. Since Eclipse tools are open source, they are quickly updated with the latest
technology that can be integrated into existing code.
The capabilities of each packaging of eclipse are different. Java developers typically use
Eclipse Classic or Eclipse IDE for developing Java applications.
The drop down box in the right corner of the download page allows you to set the operating
system on which eclipse is to be installed. You can choose between Windows, Linux and
Mac. Eclipse is packaged as a zip file.
7-zip
PeaZip
IZArc
Using any one of these tools, extract the contents of the eclipse zip file to any folder of your
choice.
5
2.5. LAUNCHING ECLIPSE
On the windows platform, if you extracted the contents of the zip file to c:\, then you can
start eclipse by using c:\eclipse\eclipse.exe
When eclipse starts up for the first time it prompts you for the location of the workspace
folder. All your data will be stored in the workspace folder. You can accept the default or
choose a new location.
If you select "Use this as the default and do not ask again", this dialog box will not come up
again. You can change this preference using the Workspaces Preference Page.
6
2.6. PARTS OF AN ECLIPSE WINDOW
The major visible parts of an eclipse window are −
Views
Editors (all appear in one editor area)
Menu Bar
Toolbar
An eclipse perspective is the name given to an initial collection and arrangement of views
and an editor area. The default perspective is called java. An eclipse window can have
multiple perspectives open in it but only one perspective can be active at any point of time.
A user can switch between open perspectives or open a new perspective. A perspective
controls what appears in some menus and tool bars.
A perspective has only one editor area in which multiple editors can be open. The editor area
is usually surrounded by multiple views. In general, editors are used to edit the project data
and views are used to view the project metadata. For example the package explorer shows
the java files in the project and the java editor is used to edit a java file.
7
The eclipse window can contain multiple editors and views but only one of them is active at
any given point of time. The title bar of the active editor or view looks different from all the
others.
The UI elements on the menu bar and tool bar represent commands that can be triggered by
an end user.
Multiple Eclipse Windows can be open at the same time. To open a new window, click on
the Windows menu and select the New Window menu item.
Each window can have a different perspective open in them. For example you could open
two Eclipse windows one in the Java perspective and the other in the Debug perspective.
The window showing the Java perspective can be used for editing the java code and the
window showing the debug perspective can be used for debugging the application being
developed.
The typical menus available on the menu bar of an Eclipse window are −
File
1 The File menu allows you to open files for editing, close editors, save editor content and rename
files. Among the other things, it also allows you to import and export workspace content and
shutdown Eclipse.
Edit
2
The Edit menu presents items like copy & paste.
Source
3
The Source menu is visible only when a java editor is open. It presents a number of useful menu
items related to editing java source code.
Navigate
4
The Navigate menu allows you to quickly locate resources and navigate to them.
5 Search
8
The Search menu presents items that allow you to search the workspace for files that contain
specific data.
Project
6
The menu items related to building a project can be found on the Project menu.
Run
7
The menu items on the Run menu allow you to start a program in the run mode or debug mode. It
also presents menu items that allow you to debug the code.
Window
8
The Window menu allows you to open and close views and perspectives. It also allows you to
bring up the Preferences dialog.
Help
9
The Help menu can be used to bring up the Help window, Eclipse Marketplace view or Install new
plug-ins. The about Eclipse menu item gives you version information.
3. JAVA
Java was developed by Sun Microsystems (which is now the subsidiary of Oracle) in the year
1995. James Gosling is known as the father of Java. Before Java, its name was Oak. Since
Oak was already a registered company, so James Gosling and his team changed the Oak
name to Java.
9
2. Web Applications such as irctc.co.in, javatpoint.com, etc.
3. Enterprise Applications such as banking applications.
4. Mobile
5. Embedded System
6. Smart Card
7. Robotics
8. Games, etc.
1) Standalone Application
2) Web Application
An application that runs on the server side and creates a dynamic page is called a web
application. Currently, Servlet, JSP, Struts, Spring, Hibernate, JSF, etc. technologies are used
for creating web applications in Java.
3) Enterprise Application
4) Mobile Application
An application which is created for mobile devices is called a mobile application. Currently,
Android and Java ME are used for creating mobile applications.
10
A list of most important features of Java language is given below.
1. Simple
2. Object-Oriented
3. Portable
4. Platform independent
5. Secured
6. Robust
7. Architecture neutral
8. Interpreted
9. High Performance
10. Multithreaded
11. Distributed
12. Dynamic
11
4. MULTI-THREADED CHAT APPLICATION
import java.io.*;
import java.util.*;
import java.net.*;
12
// Server class
public class Server
{
Socket s;
13
// Create a new handler object for handling this request.
ClientHandler mtch = new ClientHandler(s,"client " + i, dis, dos);
}
}
}
// ClientHandler class
class ClientHandler implements Runnable
{
Scanner scn = new Scanner(System.in);
private String name;
final DataInputStream dis;
final DataOutputStream dos;
Socket s;
boolean isloggedin;
14
// constructor
public ClientHandler(Socket s, String name,
DataInputStream dis, DataOutputStream dos)
{
this.dis = dis;
this.dos = dos;
this.name = name;
this.s = s;
this.isloggedin=true;
}
@Override
public void run() {
String received;
while (true)
{
try
{
// receive the string
received = dis.readUTF();
System.out.println(received);
if(received.equals("logout")){
this.isloggedin=false;
this.s.close();
break;
}
15
StringTokenizer st = new StringTokenizer(received, "#");
String MsgToSend = st.nextToken();
String recipient = st.nextToken();
e.printStackTrace();
}
}
try
{
// closing resources
this.dis.close();
this.dos.close();
}catch(IOException e){
e.printStackTrace();
}
}
16
}
Output:
New client request received : Socket[addr=/127.0.0.1,port=61818,localport=1234]
Creating a new handler for this client...
Adding this client to active client list
New client request received : Socket[addr=/127.0.0.1,port=61819,localport=1234]
Creating a new handler for this client...
Adding this client to active client list
Limitations:
Although the above implementation of server manages to handle most of the scenarios,
there are some shortcomings in the approach defined above.
One clear observation from above programs is that if the number of
clients grew large, the searching time would increase in the handler
class. To avoid this increase, two hash maps can be used. One with name
as the key, and index in active list as the value. Another with index as
key, and associated handler object as value. This way, we can quickly
look up the two hashmaps for matching recipient. It is left to the readers
to implement this hack to increase efficiency of the implementation.
Another thing to notice is that this implementation doesn’t work well
when users disconnect from the server. A lot of errors would be
thrown because disconnection is not handled in this implementation. It
can easily be implemented as in previous basic TCP examples. It is also
left for the reader to implement this feature in the program.
1-SendMessage : This thread will be used for sending the message to other clients. The
working is very simple, it takes input the message to send and the recipient to deliver to. Note
that this implementation assumes the message to be of the format message # recipient, where
recipient is the name of the recipient. It then writes the message on its output stream which is
connected to the handler for this client. The handler breaks the message and recipient part and
deliver to particular recipient. Lets look at how this thread can be implemented.
17
@Override
public void run() {
while (true) {
2-readMessage : A similar approach is taken for creating a thread for receiving the messages. When
any client tries to write on this clients input stream, we use readUTF() method to read that message.
The following snippet of how this thread is implemented is shown below-
Thread readMessage = new Thread(new Runnable() {
@Override
public void run() {
while (true) {
try {
e.printStackTrace();
}
}
}
});
18
The remaining steps of client side programming are similar to previous examples. A brief
explanation is as follows –
1. Establish a Socket Connection
2. Communication
Communication occurs with the help of the readMessage and sendMessage
threads. Separate threads for reading and writing ensures simultaneous sending
and receiving of messages.
// Java implementation for multithreaded chat client
// Save file as Client.java
import java.io.*;
import java.net.*;
import java.util.Scanner;
// getting localhost ip
InetAddress ip = InetAddress.getByName("localhost");
// sendMessage thread
19
Thread sendMessage = new Thread(new Runnable()
{
@Override
public void run() {
while (true) {
try {
// write on the output stream
dos.writeUTF(msg);
} catch (IOException e) {
e.printStackTrace();
}
}
}
});
// readMessage thread
Thread readMessage = new Thread(new Runnable()
{
@Override
public void run() {
while (true) {
try {
// read the message sent to this client
String msg = dis.readUTF();
System.out.println(msg);
} catch (IOException e) {
20
e.printStackTrace();
}
}
}
});
sendMessage.start();
readMessage.start();
}
}
Output :
From client 0 :
hello#client 1
client 1 : heya
how are you#client 1
client 1 : fine..how about you
logout
From client 1 :
client 0 : hello
heya#client 0
client 0 : how are you
fine..how about you#client 0
logout
Important points :
To send a message from any client, type the message, followed by a “#” and
then the name of the recipient client. Please note that this implementation gives
names as “client 0”, “client 1″….”client n” and so carefully names must be
appended int the end. After that press Enter key.
Once a message is sent, the handler for this client will receive the message and it
will be delivered to the specified client.
If any client sends a message to this client, the readMessage thread will
automatically print the message on the console.
Once a client is done with chatting, he can send a “logout” message without any
recipient name so that server would know that this client has logged off the
system. It is recommended to send a logout message before closing the terminal
for the client to avoid any errors.
21
5. CONCLUSION
This case study is a thorough surveyed and researched with the help of my group members.
We learned the importance of IDE, especially the importance and advantages of ECLIPSE.
We developed an application on ECLIPSE IDE using JAVA programming language.
22