JavaChap Blog Java and Technology musings for the masses

15Nov/110

6th Grader and iPhone Application Developer

Not sure which makes me feel like more of a slacker, his mutliple apps in the App Store or his excellent public speaking

Filed under: General No Comments
1Sep/110

The 5 Biggest Ways to Boost MySQL Scalability

Sean Hall with some really good MySQL advice:

  1. Tune those queries. Biggest bang for your buck. Enable the slow query log and watch it. Once you've found a heavy resource intensive query, optimize it! Tune what receives real-world traffic.
  2. Employ Master-Master Replication. Immediately have a read-only slave for your application to hit as well.
  3. Use Your Memory. Set innodb_buffer_pool_size, key_buffer_size and other key options.
  4. RAID Your Disk I/O. Use RAID 10 mirroring and striping. On EC2 striping across a number of EBS volumes using the Linux md software raid.
  5. Tune Key Parameters. speeds up inserts & updates with innodb_flush_log_at_trx_commit=2; create a tablespace and underlying datafile for each table with innodb_file_per_table.

Full details at the original article.

11Jul/110

Enumeration Mapping in Hibernate

In this simple tutorial i will show you, how to map a Java 5 Enumeration (enum) to a varchar column in Hibernate. The use-case that i'm going to demonstrate is very simple, I have a User class which has a reference to an Enumeration Gender.

Gender Enumeration
package com.javachap.domain.user;
/**
 * Male or Female. Used to customize Account messages (e.g. he or she usage) and
 * to choose the default profile picture.
 */
public enum Gender {
    Male, Female;
}
User Domain:
package com.javachap.domain.user;

public class User {

    private String firstName;
    private String lastName;
    private Gender gender;
    private String email

    /**
     * Gets the <code>User</code>'s firstName
     *
     * @return the firstName
     */
    public String getFirstName() {
        return firstName;
    }

    /**
     * Sets the <code>User</code>'s firstName
     *
     * @param firstName the firstName to set
     */
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    /**
     * Gets the <code>User</code>'s lastName
     *
     * @return the lastName
     */
    public String getLastName() {
        return lastName;
    }

    /**
     * Sets the <code>User</code>'s lastName
     *
     * @param lastName the lastName to set
     */
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    /**
     * Gets the <code>User</code>'s email
     *
     * @return the email
     */
    public String getEmail() {
        return email;
    }

    /**
     * Sets the <code>User</code>'s email
     *
     * @param email the email to set
     */
    public void setEmail(String email) {
        this.email = email;
    }
}
Hibernate Mapping (HBM):
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
  <class table="user" name="com.javachap.domain.user.User">

    <id name="uid" column="usr_uid">
      <generator class="increment"/>
    </id>

    <property name="firstName" type="java.lang.String" column="usr_first_name"/>

    <property name="lastName" type="java.lang.String" column="usr_last_name" />

    <property name="gender" column="usr_gender" not-null="true">
	  <type name="org.hibernate.type.EnumType">
         <param name="enumClass">com.javaachap.domain.user.Gender</param>
         <param name="type">12</param>
      </type>
    </property>

    <property name="email" type="java.lang.String" column="usr_email"/>

  </class>
</hibernate-mapping>

By default Hibernate persists the enumeration value as integer in the database when type param is not specified, In order to store the enum display name, we use a param type, which should be pointed to value in java.sql.Types. Since we want to store the enum display name in database we have mapped it to 12 which is equivalent to java.sql.Types.VARCHAR.

Hibernate Annotation Based Mapping:

If you prefer convention over configuration, below is the way to map an enum using annotation.

public class User {

   @Enumerated(EnumType.STRING)
   Gender gender

}
10Jul/110

Java 7′s Fork/Join Framework

Eric Bruno:

Fork/Join is an enhancement to the ExecutorService implementation that allows you to more easily break up processing to be executed concurrently, and recursively, with little effort on your part. It's based on the work of Doug Lea, a thought leader on Java concurrency, at SUNY Oswego. Fork/Join deals with the threading hassles; you just indicate to the framework which portions of the work can be broken apart and handled recursively. It employs adivide and conquer algorithm that works like this in pseudocode (as taken from Doug Lea's paper on the subject):

http://drdobbs.com/blogs/java/231000556

4Jul/110

Understanding Java Weak References

Ethan Nicholas :

I'm sure some of you are grumbling by now, as I'm talking about an API which is nearly a decade old and haven't said anything which hasn't been said before. While that's certainly true, in my experience many Java programmers really don't know very much (if anything) about weak references, and I felt that a refresher course was needed. Hopefully you at least learned a little something from this review.

weak reference, simply put, is a reference that isn't strong enough to force an object to remain in memory. Weak references allow you to leverage the garbage collector's ability to determine reachability for you, so you don't have to do it yourself.

http://weblogs.java.net/blog/2006/05/04/understanding-weak-references

16May/110

Learning by Doing

Filed under: General No Comments
4May/116

Must see Telugu movies of the Decade (2001-2010)

In developing ‘My Top Telugu Movies of the Decade’, I knew there was no way I could rank my movies from 1st to 25th.  Any attempt would be futile.  How do I pit my favorite comedy against my favorite action? I instead organized them by year of release. Not only does this relieve the pressure of ranking each one, but emphasizes the time and context of its release.

I know that this list is completely subjective. It is not the ’25 best ever’, it is simply my favorites and recommendations. Chances are, there are a couple films here that you disliked or were greatly disappointed in. But again these are my favorites and recommendations.

Movie Year
Nuvvu Naaku Nachchav 2001
Murari 2001
Khushi 2001
Manmadhudu 2002
Indra 2002
Santosham 2002
Idiot 2002
Missamma 2003
Tagore 2003
Shankar Dada MBBS 2004
Varsham 2004
Anand 2004
Arya 2004
Nuvvostanante Nenoddantana 2005
Atadu 2005
Chatrapathi 2005
Bommarillu 2006
Aa Naluguru 2006
Pokiri 2006
Sri Ramadasu 2006
Chandamama 2007
Happy Days 2007
Gamyam 2008
Magadheera 2009
Arundathi 2009
Ye  Maya Chesave 2010
Leader 2010
15Nov/100

MySQL Import and Export

Here are few MySQL Queries/commands that i regularly use for exporting and importing MySQL data.  This is for my reference, but just thought this might be useful for newbies.

MySQL Table Data Export and Import
  • To export the just table data please use the following query
    SELECT * INTO OUTFILE 'data.txt' FIELDS TERMINATED BY ',' FROM mytable;
    
  • To import the csv file into table execute the following SQL Query.
    LOAD DATA INFILE 'data.txt' INTO TABLE mytable FIELDS TERMINATED BY ',';
    
Copy the contents of one database to another
  • First, create the new database
    create database db2;
    
  • Then, from the command-line, do the following to copy the contents from db1 to db2.
    $ mysqldump -u root --password=pass db1 | mysql -u root --password=pass db2
    
MySQL Dump
  • To export the MySQL database into a dump file, please execute the following command
    $ mysqldump -u root --password=pass db1 &gt; dbdump.sql
    
Create MySQL User
  • Creating MySQL user and granting access
    CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'myuser';
    GRANT ALL ON *.* TO 'myuser'@'localhost' IDENTIFIED BY 'myuser';
    
10Sep/104

iPhone 4 first impressions

I have been using this baby for about 4 weeks. So decided to write my thoughts about the latest and greatest iPhone 4

The Retina Display -  Boy you gotta use it to understand how cool it is. When i looked at my old 2G  after using 4G i feel like 'wait a minute is this the display i have been using all these days", it looks so crappy. This is best resolution i have ever seen. I just feel like touching the objects, fonts look so amazing.

The Hardware - This is the first overhaul of the design since the original iPhone. All i can say is its just super super sexy. It feel's like a rock solid in your hand. Its 25% thinner than 3GS. Feels so good in my hand that i want to carry it without a case, but I'm scared that i may damage the phone without the case. So i have to put the case on even if i don't like it.

The Camera - iPhone 4 comes with 5 MP Camera with Flash and front facing VGA Cam. The pictures are really cool, and the best part is the HD (720p) video recording. Even though its tough to copy large videos over 1GB of size.

iOS 4 - Multitasking is a welcome feature. Even though its limited, its a good start.  Enjoying the ability to set background for the home screen.

Issues - Some basic features are not supported by iPhone. Wish Cupertino company will add these features soon.

  • No File transfer using Bluetooth.
  • File Explorer is missing.
  • Unable to close all running applications in single shot.

Conclusion - I'm loving it.

18Feb/108

How to Enable Permalinks in WordPress – Yahoo Hosting

Problem : WordPress Permalinks don’t work on Yahoo! hosting because they do not give their users access to the htaccess file – which means you cannot create the mod_rewrite rules needed for custom permlinks. Any other WordPress feature.. addon or plugin that you may need your .htaccess file for? Forget it – they do not give you access to it. Period.

Solution: Go to Permalink Settings > Select Custom Structure. And define the value as /index.php/%postname%/ Then your URL will look like http://yoursite.com/index.php/your-post-title.

Huh finally Permanlinks are enabled for my blog. Just incase if you dont know, Permalinks will help you on SEO. Yes Yahoo hosting sucks !