RaKasUniverse.info

I still don't know why I registered this domain!

Archive for the ‘java’ tag

Java Zip API: How to Create a Zip File Using Java

with 4 comments

This is a follow-up to my earlier post “Java Zip API: How to Read a Zip File Using Java“. This time it’s about how to create a zip file using Java. This is even simpler than reading a zip file.

Following is a very simple example which create a zip file named RaKasUniverse.zip. Inside that zip file we will create a directory named MyDirectory and inside that, we will have a file named MyFile.txt. That text file will contain the text “Java Zip API: How to Create a Zip File Using Java”. In the example we will be using following classes from Java API.
Read the rest of this entry »

Written by Rakhitha

July 11th, 2010 at 10:59 pm

Fun with Java Reflections: Access Private Member Fields/Methods of other Classes

without comments

This is a follow-up to my earlier post on Java Reflections.  In the earlier post I just showed how to invoke methods of an object dynamically using reflection. Here I am going to talk about accessing attributes of another object using reflection, with a little twist.

Just like my earlier post I’ll start this with an exercise.

Write a class with a private member variable only. No get/set methods. But add a toString() method to output the content of that private variable.

Like Following….

Now write another class. It should create an instance of above class, and set your name as the value of ‘name’ attribute in that object.

Read the rest of this entry »

Java Core API: Introduction to Java Reflections

with 6 comments

Here is an exercise for you!

Write a java program that take two or more command line arguments. 1st argument is a class name. 2nd argument is a method name. Rest of the arguments are string values to be passed in to that method.

Your program has to load the class specified in first argument (this class may not be available at compile time). Create an instance of that class. Then invoke the method given in the 2nd argument on that object passing the values given in rest of the arguments as parameters to that function. To simplify things lets say all parameters are string.

The answer is reflections. To give you a very simplified description, Reflections allow you to access members of a class/object dynamically in run time without having to hard-code things in the source code. This is slower than hard-coding. But it is very useful when the class/methods/fields that you need to access are not known or not available at compile time. Also in some cases you can do cool things like accessing private members.

Read the rest of this entry »

Java Zip API: How to Read a Zip File Using Java

with 3 comments

Java API give a very simple set of classes to deal with zip files in its java.util.zip package. I am just going to show how to access the content of a zip file using these classes. Basically in java point of view a zip file is a collection of zip entries. you just select the zip entry that you like to read and extract its content using an InputStream. However this API do not support handling of password protected zip files.

Read the rest of this entry »

Written by Rakhitha

June 11th, 2010 at 6:52 pm

Posted in Java Stuff

Tagged with , , , ,

Me, My Self and Java

without comments

Programming is my main hobby. I wrote my first computer program when I was 11 years old. Then I was using GW BBASIC. Since then I have learned QBASIC, Pascal, Visual Basic, Perl, Java, PLSQL, C++,  PHP, C#, bit of Python and many other things over time. I screwed up  my A/L for it but fortunately managed to get in to a career in Software Development. When I was a school kid I built some web sites using ASP and Perl but they were never published. And I spent a great deal of time learning regular expressions. Graphics Design was not my thing. So I ended up as an applications programmer.

Read the rest of this entry »

Free Tool to Bulk Convert JPG, PNG, GIF Images to PDF

with 3 comments

WISH YOU A VERY HAPPY SINGHALA AND HINDU NEW YEAR!!! :)

This post is about a very simple tool that I wrote in 2007 when we were studying at SLIIT. I published this at the time on Google Code. But I noticed that not many people are finding it there. Thats why I am posting about it here.

When we were doing our final-year research projects at SLIIT, it was mandatory to write our reports using Latex. It obviously seemed that we are wasting our time using Latex, instead of using MS Word or something that we already know how to work with. But after some time we noticed that Latex is a better tool to produce technical documentation. It lets you visualize your documentation work in a modularized way allowing different people to work on different parts of the document. Output produced by Latex document rendering gives you better quality with less effort. Unlike word processors it separate content and formatting in a simple way and allow you to produce very good-looking reports with minimum effort.

Read the rest of this entry »

Written by Rakhitha

April 14th, 2010 at 12:29 am

How I Upload Photos to Facebook: Automated Bulk Image Resizing and Adding Copyright Notices

with one comment

If you are using a super fast internet connection. And you have plenty of time to add copyright notices to photos one at a time, this post is not for you.

I am using a crappy internet connection. I also find that java based face book photo uploader takes a long time compared to the amount of data it has to upload. And it often fails. If I use HTML based uploader, it takes a lone time to upload everything, five photos at a time. It often mess things up if you try to do parallel uploads (like giving you a log-in page instead of uploading stuff). Picasa uploader might be a good idea but Google finally made Picasa way to complicated to do simple things. It used to be simple. This post is about a simple tool that I created to make my life easy when uploading photos to Facebook.

Read the rest of this entry »