Sun Microsystems Education, Project and Career Oppurtunities for Students

Saturday, November 29, 2008

I was often asked by some student friends about the projects they can work on, here I would like to introduce some of the oppurtunities students can explore with Sun Microsystem's brand open source software like Netbeans, Glassfish, OpenSolaris, JavaFX, OpenSPARC, VirtualBox, OpenOffice, Java and MySQL to name a few, the reason why Sun technologies can be a compelling choice for the student community is Sun technologies are available to you free or open source and it has a rich developer community, forums, mailing lists which can always help you.

For a student, Sun Microsystem's open source technologies are a boon to say the least in that they get every thing they need from IDE, Database, Application programming language, the highly secure Solaris Operating system, in short, virtually a complete software stack for free, its extremely important that they explore these technologies at the earlier phases of their academics so that they can reap the full benefits of these technologies which will help them not only in executing successful academic research projects with the latest cutting edge technologies but also end up in lucrative professional careers as well. Here are the step by step approach a student can take as far as exploring these technologies.GetJava Download Button

I am not sure about your specific interests but sky is the limit as far as exploring Sun Microsystems open source technologies are concerned, you can get everything you need to explore completely for FREE with open source to play with, for example if you are interested in hardware design, then openSPARC is for you, interested in exploring the highly scalable and secure operating system? then OpenSolaris is for you, or a programming geek, go with Open Java.

Start with any of the above technologies you are interested in, download them for free, install them, start playing with, you will appreciate these technologies for sure.Innovate on OpenSolaris

Visit the above page, register as a student and get access to all training materials and courses right from learning java, exploring Netbeans, open source, etc absolutely FREE!

Got struck? You can always post your questions by visiting the above page, get advice from experts for solutions to your problems related to these technologies.

Sun has tie ups with leading universities all over the world and has a Campus Ambassador program for student developers, which students can leverage to a greater extent to fulfil their academic objectives as well as career goals, I know that through this program, there are several students mentored by Sun Engineers which resulted in exciting projects, one such example, openSolaris in USB developed in India.
The Events Calendar page updates about the Sun Microsystem's campus events for different universities where one can check the future Sun events in their universities, also look for Sun Microsystems job or internships available for students,where one can kick start their careers with cutting edge technologies with Sun.

For more details about oppurtunities and career options available to students with Sun open source technologies, do contact me, also you can always look for more details in Sun Student Central web page anytime.

Changing Java Webstart Settings: Opening JNLP files with a specific JRE

Friday, November 28, 2008

JNLP (Java Network Launching Protocol) files launched from browser are used to execute Java Webstart applications, the difference between Java Webstart applications and Java applets are Java Webstart applications don't run inside the browser (consider them as a Java application launched through browser which runs on the client machine but not in the browser context), whereas a java applet runs in an web browser context, they are executed in a sandbox with security restrictions and they may not access local data.

Java Webstart applications are lauched by javaws (can be found in JAVA_HOME/bin/javaws).

Java Webstart applications can be used when a software application needs to be run on the client system without browser dependency (which applets require), as obvious Java Webstart applications are platform independent software and can be launched from any platform with the supported JRE for the application (say Java 1.4 or 1.5).

Often we may need to launch a Java Webstart application on a specific JRE, this may be done by changing Java Webstart settings by selectively enabling the specific JRE as default or by specifying the javaws path upon prompted before opening the Java Webstart application, we will specifically see how to run a single java webstart application with two different JREs (JRE Version 1.5 and 1.6).

The sample web application used is a java swing text validation utility which can be found here, use this application to try out both the approaches.

Selectively Enabling Java Application runtime settings:

1. Launch Java Webstart settings (All Programs -> Control Panel -> Java)

2. Click on Java tab -> View button on Java Application Runtime Settings

3. One can see the all the JRE versions installed in that machine, by default all of them would be enabled, see the below figure.

Figure 1: JNLP Runtime settings showing installed JRE versions

4. To enable only a specific JRE to be used to launch applications by default, enable only that specific JRE, for example from the above figure, to select only Java 1.6 runtime to launch your Webstart applications, uncheck Java 1.5 option (see the above figure), click OK, click Apply from the Java Application Runtime Settings section, then restart the browser.

Choosing a specific JRE version for Java Webstart applications on the fly by specifying the javaws path:

One can also specify the path for javaws on the specific JRE installation location to be used to execute Java webstart applications. Before doing this, one needs to enable the prompt user option through the Java Runtime settings before executing a Webstart application .

1. Launch Java Webstart settings (All Programs -> Control Panel -> Java)

2. Click Advanced tab

3. Expand JNLP File/MIME Association, select the Prompt User option, click Apply, restart the browser (see below).

Figure 2: Changing JNLP/MIME Association settings

4. Now whenever you open a JNLP file, you will be prompted with options to open the application either with the default settings or choosing the JRE location (javaws,) if the location of javaws is selected, then that JRE will be used (see the below figure).

Figure 3: Specifying the JRE location (javaws) to open a Java Webstart Application

Mounting CDROM ISO Images in Solaris using lofiadm

Wednesday, November 12, 2008

Many a times we need to mount an ISO Image from CDROM to install a product, in Solaris this process is simplified with the lofiadm command which I used recently to install ISOs and hope this will be a useful reference.

lofiadm is a system administration command in Solaris which allows a file to be associated with a block device which can then be mounted on the local file system.

For example assume that a product is shipped as an ISO Image which needs to be installed, if the ISO file path is /var/tmp/CDImage.iso (say), then the sequence of steps to associate the ISO Image to the block device and mount it to the local file system would be as follows.

1. Remove existing ISO Block device using lofiadm if any

/usr/sbin/lofiadm -d /dev/lofi/1

2. Using lofiadm, associate the CD ISO Image as a block device

/usr/sbin/lofiadm -a /var/tmp/CDImage.iso

3. Mount the CD-ROM block device in the local file system.

/usr/sbin/mount -F hsfs -o ro /dev/lofi/1 /mnt

(Make sure you unmount any existing mounts in /mnt using /usr/sbin/umount /mnt)

Note: In the above mount command the hsfs represents High Seirra file system, a CD-ROM file system for Solaris.

4. cd /mnt to invoke the installer.

(Make sure you cleanup the block device and unmount the /mnt after the installation is complete using /usr/sbin/mount -F hsfs -o ro /dev/lofi/1 /mnt and /usr/sbin/lofiadm -d /dev/lofi/1 respectively).

Self Improvement: The Hidden Secret in Think and Grow Rich

Here I want to share my views about the books I read till date which made some difference to me and are also making a mark among readers with their uniqueness among plethora of writings available these days on virtually every subject, this one is for ambitious persons who want to accomplish their goals but need an organized way of approaching things, in general this book can be regarded as an excellent complimentary for Napoleon hill's inspirational writing "Think and Grow Rich" used by many over decades.

Even though this is a technical blog, but I still see some purpose of putting this here so that readers can benefit out of this in pursuing their endeavors, which may be technical accomplishments too (but not limited to of course).

The reading "The Hidden Secret in Think and Grow Rich" appealed to me because of the following reasons.

1. Short, precise, and concise This book is just about 100 odd pages, so it won't take much to get the crux of the idea.

2. Lucid explanation of the steps Some of the key factors to success which you will find in "Think and Grow Rich" like Desire, Faith, Auto Suggestion, Specialized Knowledge, Imagination, Organized Planning, Decision, Persistence, Master Mind, Transmutation, Subconsious mind, Brian, Sixth sense are connected very well in this writing at the respective chapters and most importantly explains how each step when executed in the correct order would naturally lead to the habit of inculcating the other attributes of success, for example if you have STRONG desire, faith and organized plan, you will naturally be persistent, etc.

3. Practical and Logical steps I came through this e-book when I was recommended by one of my friend on the article "How to find what you love to do", if you love that reading you would appreciate "The Hidden Secret in Think and Grow Rich" for sure because this is not a mere book, but also has practical exercises which one should follow in order to realize their dreams (like you should take notes whenever some idea strikes, always write, to-do lists, how to break a huge task into reasonable small chunks, etc).

4. It will work.. How far is up to the desire of the individuals but if you have a strong desire to get the best of this book for your self improvement or accomplishing your mission, then you will get more than the value of your money for sure.

5. Examples, inspirational success stories, etc Though you are strongly advised to go through Napoleon Hill's "Think and Grow Rich" before proceeding this one, you can still grasp the examples in this book even otherwise. Most of the stories were examples of how organized execution would lead to accomplishment of your mission with inspiring stories of great persons over the centuries, which in turn would fuel the fire in your belly to accomplish your goals.

6. Supplementary workbooks and reports You would also get a free "The Hidden Secret Workbook" and a report "The Three Biggest Mistakes People Make With The Hidden Secret" with these you can evaluate your strengths, how you can use them to work for you and avoiding common pitfalls which you might make in setting your goals, also you would get a free electronic copy of "Think and Grow Rich".

Even though I am skeptical of too much examples, success stories, motivational and self improvement books, after reading this that perception changed quite a lot as this has very practical and proven ways to get where you want, also I recommend you to go through the self improvement articles of Brian which would make interesting and refreshing readings.

Implementing a simple HTTP Server in java for handling POST methods: A File Upload HTTP Server

Sunday, November 2, 2008

Note: An updated version of this post can be found in which will handle any kind of file uploads (text and binary files) of large size.

In the last section on java, we have seen how to implement a simple/lightweight HTTP/Web Server to handle HTTP GET methods. In this section, we will see how to implement a simple HTTP/Web server in java to handle POST methods with an example of a file upload server using the POST method through a client form data.

The benefit of implementing our own HTTP Server to handle GET/POST methods is that we can use them for some simple/lightweight applications which doesn't require an Apache Web server or a servlet container to be deployed to handle HTTP client requests, also these simple HTTP servers can be used as utility classes which can be integrated in a small scale applications.

The below HTTP POST Server does the following functions.

1. Displays the File upload form when the home page is accessed (, displays error for other invalid GET requests.

2. Uploads a text file through the file upload form and submit it, the end result is that the file will be uploaded in the directory where the HTTPPOSTServer class runs, Note: This code will work only for text files.

3. Handles text files upto 2MB.

I have tested the code in IE 7, Firefox and Chrome (BTW I needed to change the code a lot to make it IE compatible). The lesson learned, always test your code in IE first to avoid disappointments as its likely to give you some tough time the other way around (nothing against IE though).

So here's the code.

Listing 1:

  1 /*
2 *
3 * Author: S.Prasanna
4 * @version 1.00
5 */
7 import*;
8 import*;
9 import java.util.*;
11 public class HTTPPOSTServer extends Thread {
13 static final String HTML_START =
14 "<html>" +
15 "<title>HTTP POST Server in java</title>" +
16 "<body>";
18 static final String HTML_END =
19 "</body>" +
20 "</html>";
22 Socket connectedClient = null;
23 BufferedReader inFromClient = null;
24 DataOutputStream outToClient = null;
27 public HTTPPOSTServer(Socket client) {
28 connectedClient = client;
29 }
31 public void run() {
33 String currentLine = null, postBoundary = null, contentength = null, filename = null, contentLength = null;
34 PrintWriter fout = null;
36 try {
38 System.out.println( "The Client "+
39 connectedClient.getInetAddress() + ":" + connectedClient.getPort() + " is connected");
41 inFromClient = new BufferedReader(new InputStreamReader (connectedClient.getInputStream()));
42 outToClient = new DataOutputStream(connectedClient.getOutputStream());
44 currentLine = inFromClient.readLine();
45 String headerLine = currentLine;
46 StringTokenizer tokenizer = new StringTokenizer(headerLine);
47 String httpMethod = tokenizer.nextToken();
48 String httpQueryString = tokenizer.nextToken();
50 System.out.println(currentLine);
52 if (httpMethod.equals("GET")) {
53 System.out.println("GET request");
54 if (httpQueryString.equals("/")) {
55 // The default home page
56 String responseString = HTTPPOSTServer.HTML_START +
57 "<form action=\"\" enctype=\"multipart/form-data\"" +
58 "method=\"post\">" +
59 "Enter the name of the File <input name=\"file\" type=\"file\"><br>" +
60 "<input value=\"Upload\" type=\"submit\"></form>" +
61 "Upload only text files." +
63 sendResponse(200, responseString , false);
64 } else {
65 sendResponse(404, "<b>The Requested resource not found ...." +
66 "Usage:</b>", false);
67 }
68 }
69 else { //POST request
70 System.out.println("POST request");
71 do {
72 currentLine = inFromClient.readLine();
74 if (currentLine.indexOf("Content-Type: multipart/form-data") != -1) {
75 String boundary = currentLine.split("boundary=")[1];
76 // The POST boundary
78 while (true) {
79 currentLine = inFromClient.readLine();
80 if (currentLine.indexOf("Content-Length:") != -1) {
81 contentLength = currentLine.split(" ")[1];
82 System.out.println("Content Length = " + contentLength);
83 break;
84 }
85 }
87 //Content length should be < 2MB
88 if (Long.valueOf(contentLength) > 2000000L) {
89 sendResponse(200, "File size should be < 2MB", false);
90 }
92 while (true) {
93 currentLine = inFromClient.readLine();
94 if (currentLine.indexOf("--" + boundary) != -1) {
95 filename = inFromClient.readLine().split("filename=")[1].replaceAll("\"", "");
96 String [] filelist = filename.split("\\" + System.getProperty("file.separator"));
97 filename = filelist[filelist.length - 1];
98 System.out.println("File to be uploaded = " + filename);
99 break;
100 }
101 }
103 String fileContentType = inFromClient.readLine().split(" ")[1];
104 System.out.println("File content type = " + fileContentType);
106 inFromClient.readLine(); //assert(inFromClient.readLine().equals("")) : "Expected line in POST request is "" ";
108 fout = new PrintWriter(filename);
109 String prevLine = inFromClient.readLine();
110 currentLine = inFromClient.readLine();
112 //Here we upload the actual file contents
113 while (true) {
114 if (currentLine.equals("--" + boundary + "--")) {
115 fout.print(prevLine);
116 break;
117 }
118 else {
119 fout.println(prevLine);
120 }
121 prevLine = currentLine;
122 currentLine = inFromClient.readLine();
123 }
125 sendResponse(200, "File " + filename + " Uploaded..", false);
126 fout.close();
127 } //if
128 }while (inFromClient.ready()); //End of do-while
129 }//else
130 } catch (Exception e) {
131 e.printStackTrace();
132 }
133 }
135 public void sendResponse (int statusCode, String responseString, boolean isFile) throws Exception {
137 String statusLine = null;
138 String serverdetails = "Server: Java HTTPServer";
139 String contentLengthLine = null;
140 String fileName = null;
141 String contentTypeLine = "Content-Type: text/html" + "\r\n";
142 FileInputStream fin = null;
144 if (statusCode == 200)
145 statusLine = "HTTP/1.1 200 OK" + "\r\n";
146 else
147 statusLine = "HTTP/1.1 404 Not Found" + "\r\n";
149 if (isFile) {
150 fileName = responseString;
151 fin = new FileInputStream(fileName);
152 contentLengthLine = "Content-Length: " + Integer.toString(fin.available()) + "\r\n";
153 if (!fileName.endsWith(".htm") && !fileName.endsWith(".html"))
154 contentTypeLine = "Content-Type: \r\n";
155 }
156 else {
157 responseString = HTTPPOSTServer.HTML_START + responseString + HTTPPOSTServer.HTML_END;
158 contentLengthLine = "Content-Length: " + responseString.length() + "\r\n";
159 }
161 outToClient.writeBytes(statusLine);
162 outToClient.writeBytes(serverdetails);
163 outToClient.writeBytes(contentTypeLine);
164 outToClient.writeBytes(contentLengthLine);
165 outToClient.writeBytes("Connection: close\r\n");
166 outToClient.writeBytes("\r\n");
168 if (isFile) sendFile(fin, outToClient);
169 else outToClient.writeBytes(responseString);
171 outToClient.close();
172 }
174 public void sendFile (FileInputStream fin, DataOutputStream out) throws Exception {
175 byte[] buffer = new byte[1024] ;
176 int bytesRead;
178 while ((bytesRead = != -1 ) {
179 out.write(buffer, 0, bytesRead);
180 }
181 fin.close();
182 }
184 public static void main (String args[]) throws Exception {
186 ServerSocket Server = new ServerSocket (5000, 10, InetAddress.getByName(""));
187 System.out.println ("HTTP Server Waiting for client on port 5000");
189 while(true) {
190 Socket connected = Server.accept();
191 (new HTTPPOSTServer(connected)).start();
192 }
193 }
194 }


The working of the code is pretty simple, the HTTP server checks for a GET or POST method, and if its a GET method (line 53) for the home page, it displays the file upload form through which the user can upload the file, in case of any other invalid GET requests other than home page, an error message is displayed (line 65).

Line 70 handles POST request and checks the content type (line 74), POST boundary (line 75), content length (line 81) and the file name (line 98), once these values are parsed, the file is uploaded successfully (lines 108 - 126) provided the file length is 88).

I have commented out some assertions which should be true when parsing the POST request string, but then the code will only work when assertions were enabled (using java -ea HTTPPOSTServer), which in general is not a good practice, therefore if you want to learn more about how HTTP POST requests, add your own assertions while parsing the POST request when you expect something in the request line which should match a particular string.

Copyright © 2016 Prasanna Seshadri,, All Rights Reserved.
No part of the content or this site may be reproduced without prior written permission of the author.