Posts

Showing posts from July, 2013

DirectByteBuffer in Java

Image
MappedByteBuffer is a way to read and write binary files directly in Java. It allows you to address file data at the bytes level, so it is convenient and potentially high performance. It maps a file region into the virtual address space of the Java process. Here's a simple example of how to use it (also on GitHub ): public class MappedByteBufferTest {        public static void main(String[] args) throws IOException {            //WRITE FILE            int len = 200;            RandomAccessFile file = new RandomAccessFile("output.txt", "rw");                    MappedByteBuffer outputBuffer = file.getChannel().map(FileChannel.MapMode.READ_WRITE, 0, len);            for (int i = 0; i < len; i++)                outputBuffer.put((byte) i);...

MovieSieve

Image
Bubble Chart, by genre's popularity at the box office My family enjoys watching movies together at home. It takes us a long time to find a movie we all want to watch. In iTunes, Rotten Tomatoes, IMDB, and Netflix, all the movies are tabulated in flat lists. It would be easier to browse through hundreds of movies by viewing all the movie titles, release dates, popularity rankings, and genres in one place. This inspired me to create  MovieSieve , an interactive chart that helps people find movies. I focused on making it clear, simple, and informative. My prototype uses  D3.js  and data scraped from  IMDB . The bubble chart shows the popularity of each genre. It is based on what all the movies of that genre have grossed at the box office. Clicking on a genre's bubble generates a TreeMap of the genre, colored by decade. The larger the cell, the larger the movie's box office revenue. I had a lot of fun using MovieSieve. I will be thinking of adding imp...

Young Coders: Some Basics

Before our first session, start playing around with Java!  The first step in learning how to program is to learn how to output to the console. Not only will printing show you what your program is doing, but it will also help you debug. That’s why almost everyone’s first program is to print out “Hello, World!” to the console! 1 2 3 4 5 public class HelloWorld{     public static void main(String[] args) {        System.out.println( "Hello, World!" );     } }

Young Coders: Getting Started

Image
Young Coders Summer Program 2013 Under the "Young Coders" label, I'll post class notes. This is also where you can ask questions, discuss solutions to programming problems, and share ideas. There are many options for programming in Java, from sophisticated IDEs such as IntelliJ and Eclipse to text editors like NotePad, Emacs, and Vi. I recommend Dr. Java for beginners because there’s no need for project management. It is also easier to use than raw text editors, but less complicated sometimes than full featured IDEs.

Base 64 and Binary Line Reader

Image
Base64   is a standard to encode binary data into ASCII characters for easy transportation (such as email/SMTP and HTTP/MIME). People also often use Base64 as a storage format for sensor and computer log data because they can use line break characters as record boundary markers.  To decode Base64 data, a common way in Java is to use BufferedReader's readLine method to read encoded records line by line and then decode them. The problem is, readLine returns a String object, which is fairly expensive if there are billions of records. Since the original data is in binary, the String objects are unnecessary.  In Java, there are no JDK classes that can read bytes line by line. I implemented ByteLineReader   to fill the gap. Although the idea sounds simple, it was a little tricky to manage the buffers.  On my 2 year old Macbook Pro, my implementation can reach 70 MB/s to saturate my HDD bandwidth.  I found two Base64 decoder implementations to t...

GoldRush: Android App Development

Image
This is my first post! I'm going to talk about Java programming on Android devices. I got a 7 inch Samsung Galaxy Tab from DigiPen's summer camp . I have always been an iPad user, so using the Android device was a new experience. While the Galaxy Tab is similar to the iPad in many ways, it had some nice features the iPad did not have. The live wallpapers I downloaded were fun - I enjoyed touching the screen and seeing the water ripple, and occasionally poking at the fish in the "koi pond". The widgets turned out to be very useful because they quickly gave me information like weather, emails, and the news. I also liked the Google keyboard, which helped me to type faster and more accurately by sliding between letters. Android allows for more customization than iOS and has a lot of potential to be a mobile information dashboard.