Narendra Dhami

My Site

Archive for September, 2009

SEO Basics – 5 online tools to check your rank

Posted by Narendra Dhami on September 26, 2009

ince in the last post I gave you some hints on how to enhance your website SEO ranking, it’s time now to present some online tools that will show your current SEO ranking; like any good webmaster knows, day after day you have to track the positioning of your website on search engines, analyzing and optimizing constantly your pages for them, it is essential if you want to climb without difficulty in SERP positions.

Search engine rank is one of the basic keys to succeed online, if you know the basic keywords you are using to promote your website through meta tags or back-links. More…

Posted in SEO | Leave a Comment »

PHP Quizes

Posted by Narendra Dhami on September 25, 2009

PHP Quiz part 1

Simple things of PHP can be just as fun as the advanced things in
To prove that I wanted to make a small quiz, and here it is.

Below you’ll see 10 pieces of PHP5 code, the goal is to figure
out the code and know the output before you actually run it.
Have fun!

Comment and closing tag

<?php //
Without cheating.. What will you see when you run this single line of
?\?> php code

Echo print and get what

  // What do you expect from this ?
  echo print( 1 ); ?>

What wil eval to true

  // How many times will we get ‘true’ ?

  $boolean  = false;
  echo ($boolean) ? ‘true’ : ‘false’;

  $boolean  = ‘0’;
  echo ($boolean) ? ‘true’ : ‘false’;

  $boolean  = ’00’;
  echo ($boolean) ? ‘true’ : ‘false’;

First a cast, then an increment, but what is shown?

  // What number will you get to see?
  $integer = (int) ‘PHP’;
  echo ++$integer;

Float boat

        // What number will be
        $a = 0.1 + 0.7;
        echo (int) ($a*10) + 1 ;

Array key fun


        $a[ 1 ] = “The one”;
        $a[“a”] = “The second”;
        $a[“1”] = “The who?”;
        $a[“A”] = “CaSe FuN”;
        $a[“01”]= “The last”;

        echo count($a); // How many
do you expect?

Array count


        $one    =
range(1, 3);
        $two    = 7;
        echo count($one) +
count($two); // How much will the be?

Array key existence


        // Will it be isset?

= range(10,20);
$a[11]          = “The one
and only”;
$a[’11’]        = null;

        if (isset($a[11])) {
echo “Yes, it’s isset!”;
        } else {
echo “No, it’s not isset.”;

Array evil sort


$a      = array(0, 1, 0.1=>’a’,

        echo count($a); // Is it what
you expected?

Array reference voodoo


        $a =
        foreach($a as
&$value)  {}
        foreach($a as
$value)   {}

str_rot13( implode(”, $a) ); // how many letters

PHP Quiz part 2

A short quiz this time, but that doesn’t make it less fun. Do you
know the answer to all of them? Get a cup of coffee and kill 10 minutes
with round two…

As always, think of the answer before you execute the code or
look it up. You can find round one here.

Array pointer

What will the output be ?
$array = range(0,5);
as $v) {
  echo $v;

ArrayAccess and isset fun

isset or not isset, thats the question.
$a          = new ArrayObject;
$null       = NULL;

if (isset($null))
        echo 1;
} else {
        echo 2;

if (isset($a[‘fubar’])) {
        echo 1;
} else {
        echo 2;

if (array_key_exists(‘fubar’,
$a)) {
        echo 1;
} else {
        echo 2;


The output might be confusing..


How many notices will be thrown?
function a( & $array) {}
function b($array) {}

OR or || – operator precedence

What will the output be?
( 1
? 0 : 1
or 1 ),
( 1
? 0 : 1
|| 1 );

Nesting structures

Will this error, or not?
if (1):
    echo ‘one’;
    if(2) {
        echo ‘two’;
    echo ‘not

PHP Quiz part 3

Welcome to another part of the PHP Quiz series, again some
interesting questions to crack your brain about. If you have some nice
additions or questions, be sure to leave a comment. Enjoy part three!

As always, think of the answer before you execute the code or
look it up. You can find round two here.

Unset cast

What is the type of $a and what is the type of $b
$a = “A”;
$b = (unset) $a;

Form fun

What will the output be?
<form method=“post” action=“” enctype=“text/plain”>
    <input name=“search”
    <input type=“submit”>
        error_reporting( E_ALL );
        echo (string) filter_input(INPUT_POST, ‘search’);

Fun with strings

Strings in PHP are versatile, but how versatile are they… What
will the output be?$juggling = “Itffkhmf”;

$rox = “Spy”;

$b = $c
= “”;
for ($i=0;
$i<strlen($juggling); $i++) {

    $b .= $juggling[
$i ];

for ($i=0;
$i<strlen($rox); $i++) {

    $c .= $rox[
$i ];


var_dump( $b,
$c );

Referenced returning

Do you know the referencing details? What will the output be?class RR {
  public $varA = “z”,
= “z”,
= “z”;

& getA() {
    return $this->varA;

& getB() {
    return $this->varB;

getC() {
    return $this->varC;

$rr = new RR;

// Option A,
method only

$a = $rr->getA();

$rr->varA = “a”;

// Option B,
both method and assign

$b = & $rr->getB();
$rr->varB = “b”;

// Option C,
assign only

$c = & $rr->getC();
$rr->varC = “c”;

$b, $c);

For what it’s worth

$obj    = new stdClass;
$int    = 1;
$string = “a”;

* 2),
* 3),
* 4);

Global precedence

function multiply($b) {

    $a = 100;
    global $a;

    return $a * $b;


Making the (seemingly) impossible, possible

Don’t use codepad to figure out whats happening, since that gives
a big hint right away. Try it on the CLI and think about what is
happening first.class A {
  private $A;

class B extends A {
  public $AA;

// How many
keys, and what are the keys?

var_dump( (array) new B()

Posted in PHP | Leave a Comment »

InnoDB Configuration and Optimization

Posted by Narendra Dhami on September 24, 2009

Just thought i should have a quick guide for configuring an optimized for innodb my.cnf

use innodb_data_home_dir & innodb_data_file_path to specify the location and size of the tablespace.

innodb_data_home_dir = /path/to/data
innodb_data_file_path = ibdata1:50M;ibdata2:50M:autoextend:max:10G
innodb_autoextend_increment = 10

This asks innodb to create two files ibdata1 & ibdata2 (as tablespace) and keep them in the /path/to/data directory. Both would be of 50 MB initially, but ibdata2 would expand automatically by innodb_autoextend_increment MBs (yes the value is in MB) till the max size of 10 GB. InnoDB forms the directory path for each data file by textually concatenating the value of innodb_data_home_dir to the data file name, adding a path name separator (slash or backslash) between values if necessary.

By default innodb creates all its tables in the tablespace specified by the innodb_data_file_path directory – in a single file – as specified. But there is another option using which you can ask innodb to create tablespace for each table.


Innodb would now store each newly created table in its own table_name.ibd file – which would contain both the data and the index.

Lets look at some optimization and performance settings for innodb


If you have a large number of innodb tables, you will need to increase this value. It is used to store data dictionary information and other internal data structures. If the value is low, you might see warning messages in the mysql error log.


Innodb uses some table level locking for generating auto increment values – which is configurable. If the value is set to 0 (traditional mode), for all insert statements, a table level auto_inc lock is obtained and maintained till the end of the insert statement. If the value is set to 1(consecutive lock mode), all bulk insert-like statements obtain and maintain the auto_inc lock on the whole table. But simple inserts use a new locking method where a lightweight mutex is used during the allocation of auto-increment values, and no table-level AUTO-INC lock is used. If the value is set to 2 (interleaved lock mode), no insert-like statements use the table-level AUTO-INC lock, and multiple statements can execute at the same time. This is the fastest and most scalable lock mode, but it is not safe when using statement-based replication or recovery scenarios when SQL statements are replayed from the binary log. Here auto-increment values are guaranteed to be unique and monotonically increasing across all concurrently executing insert-like statements. However, because multiple statements can be generating numbers at the same time (that is, allocation of numbers is interleaved across statements), the values generated for the rows inserted by any given statement may not be consecutive.


The larger the buffer pool the less disk I/O would be needed to access data in tables. Generally buffer pool should be around 50% of available memory size. Very large values can result in paging and slow down the system.


The number of threads that can commit at the same time. Should be equal to the number of available cpus or cores.


If the value is 0, the log buffer is written out to the log file once per second and the flush to disk operation is performed on the log file, but nothing is done at a transaction commit. When the value is 1 (the default), the log buffer is written out to the log file at each transaction commit and the flush to disk operation is performed on the log file. When the value is 2, the log buffer is written out to the file at each commit, but the flush to disk operation is not performed on it. However, the flushing on the log file takes place once per second also when the value is 2. Note that the once-per-second flushing is not 100% guaranteed to happen every second, due to process scheduling issues.

The default value of 1 is the value required for ACID compliance. Better performance can be achieved by setting the value different from 1, but then you can lose at most one second worth of transactions in a crash. With a value of 0, any mysqld process crash can erase the last second of transactions. With a value of 2, then only an operating system crash or a power outage can erase the last second of transactions.


The size of buffer that innodb uses to write log files on disk. A large buffer allows large transactions to run without a need to write the log to disk before the transactions commit.


The size of each log file in a log group. The combined size of log files must be less than 4GB. Sensible values range from 1MB to 1/N-th of the size of the buffer pool, where N is the number of log files in the group. The larger the value, the less checkpoint flush activity is needed in the buffer pool, saving disk I/O. But larger log files also mean that recovery is slower in case of a crash.


The number of log files in the log group.


The maximum no of tablespaces that innodb can keep open at one time.


If this is enabled, InnoDB support for two-phase commit in XA transactions is enabled, which causes an extra disk flush for transaction preparation. If you do not wish to use XA transactions, you can disable this variable to reduce the number of disk flushes and get better InnoDB performance.


InnoDB tries to keep the number of operating system threads concurrently inside the engine less than or equal to the limit given by this variable. Once the number of threads reaches this limit, additional threads are placed into a wait state within a FIFO queue for execution. Threads waiting for locks are not counted in the number of concurrently executing threads. By default this value should be twice the number of available cpus/cores.

Using some of the data here, you can easily setup a machine to perform better using innodb. You will always have to choose between performance and reliability as both are inversely proportional. As performance increases the reliability of data would decrease. The variables that i have set here are for high performance only.

Posted in MySQL | Leave a Comment »

Quick and Dirty MySQL Performance Troubleshooting

Posted by Narendra Dhami on September 17, 2009

What are the first things you should look at after learning of a sudden change in MySQL server performance?

Sooner or later, you’re going to get that phone call (or email, SMS, instant message, tweet, or whatever): The database is slow! Fix ASAP! And you’ll be expected to very quickly figure out what’s slowing things down–often wither very little context, background, or sense of what may have changed recently at the application layer.

It’s just a server. How hard could it be?

Well, as we all know “that depends.” It depends on a lot of things that you likely have little time to investigate in the middle of a crisis. So where should you focus your time and attention?

This article assumes that you have little to no good monitoring on the server and virtually no idea of what “typical” usage looks like either. Sadly, that’s a real-world situation for a lot of MySQL administators–especially those in smaller organizations who are expected to wear half a dozen different hats on any given day.

In other words, let’s go back to basics and talk about high-level performance troubleshooting–not fancy high end hardware or new releases of software that you haven’t had a chance to try yet.

Hardware Bottlenecks

The first thing I tend to do is check for hardware bottlenecks. That means logging into the box and running a small list of commands to get a quick idea of what’s happening. Mainly I’m looking for stress points. Which resources are most constrained right now? CPU? Memory? Disk I/O? Something else?

There are three main utilities I’ll run to in a situation like this:

  • top
  • vmstat
  • iostat

First I’m going to use top to see if anything is hogging CPU on the machine. If there are non-mysql processes using a substantial percentage of the CPU cores, I’m going to want to have a look at what that is and see about limiting its use or moving it a dedicated server. If I see mysqld using up a lot of CPU, I know it’s working hard and will have to drill into what’s happening inside of MySQL (maybe some poorly written queries). If nothing is apparently chewing up the CPU time, I know that the problem is likely elsewhere.

Next I’ll run vmstat over a fairly short interval–typically 5 or 10 seconds.

$ vmstat 5

‘ll generally run this for at least two or three minutes to get a sense of what the CPU and memory use are like. I’m also watching to see how much time the CPU is stalled waiting for I/O requests. Doing this for several minutes will make the occasional spikes really stand out and also allow for more time to catch those cron jobs that fire up every few minutes.

The last thing I’ll check before poking at MySQL itself is iostat. Just as with vmstat, I’m going to run it with a short interval (5 or 10 seconds) and do so for several minutes. I’ll likely filter the output so that I only see the output for the most active disk or array (the one where all of MySQL’s data lives).

$ iostat -x 5 | grep sdb

I’m looking closely at the % busy and tps to get a qualitative feel for how “busy” the I/O subsystem is, and I’ll watch both Blk_wrtn/s and Blk_read/s to figure out how many blocks are being written and read every second.

Once I have a basic feel for what the system is doing, I’ll start digging into MySQL itself a bit.

Probing MySQL

Looking inside MySQL is a sort of two-layer problem for me. First I want a high-level picture of what it seems to be doing and then I want to dig into the storage engine(s) doing all the I/O work, since I/O is a very common bottleneck.

For the highest level view, I want to see a number of things quickly:

  • how many queries per second is the server handling
  • how many clients are connected (and active)
  • are there many “slow” queries being executed
  • what, if any, unusual errors are being logged

The first few items can be answered by looking at the results of a few SHOW PROCESSLIST commands along with some SHOW GLOBAL STATUS. Or, better yet, by using a tool that is able to summarize and prevent that data in a more friendly and efficient manner. innotop and mytop both do that. (I wrote mytop but fully admit that innotop is more feature rich and frequently maintained. But either will handle the basics.) Sorting the running queries by execution time is often revealing.

To find out about slow queries I’m going hope that the slow query log is enabled and the server has a sane long_query_time. But even the default of 10 seconds is helpful in truly bad situations.

I’ll also want to glance through MySQL’s error log to make sure nothing bad-looking has started to appear.

With that out of the way, I’ll generally dive into the storage engine statistics. And nowadays that almost always means asking InnoDB to cough up some information with SHOW ENGINE INNODB STATUS. While there’s a wealth of information to process in that output, I’m mainly interested in a few high-level stats at the end.

Total memory allocated 23904405026; in additional pool allocated 37084160
Buffer pool size   1310720
Free buffers       1
Database pages     1274443
Modified db pages  770518
Pending reads 1
Pending writes: LRU 0, flush list 1, single page 0
Pages read 733227814, created 65128628, written 1679994934
98.63 reads/s, 3.09 creates/s, 227.34 writes/s
Buffer pool hit rate 999 / 1000

I’m usually keen to see that the buffer pool hit rate is good. The closer to 1000 / 1000 things get, the happier I am. I also want to see how mange pages are being read and written per second. If either of those seems high, it should correspond to a high volume of I/O seen earlier in iostat.

The Culprit?

In nine out of ten cases, the culprit is obvious by now–or was obvious half way through this exercise. The reality is that most of the time changes that are very easy to spot are responsible for a sudden decline in performance. The trick is this: you have to be looking in order to see them!

Silly as that sounds, it’s been my experience that most problems go undetected until someone complains–especially in smaller IT groups where there isn’t someone regularly looking after the MySQL server that runs just fine 99.9% of the time. And since it fails so infrequently, nobody bothers to setup decent monitoring or performance logging infrastructure to detect problems before end users are impacted.

Sound familiar?

Just a Start…

The tasks I’ve presented here are just the beginning. Once you’ve got a good sense of what’s happening on a MySQL server, you can really start to dig in and think about how to improve the situation. Do you add or change hardware? Modify the application? Adjust some of MySQL or InnoDB’s run-time or start-time parameters?

Original From

Posted in MySQL | Leave a Comment »

A-Z 52+ Java Core API Packages You Must Know

Posted by Narendra Dhami on September 17, 2009

This tutorial provides more than 52 Core API Packages defined by Java. These all the 52 Core API Packages are listed in alphabetical order.Beside Core API Packages, there are also some other Java Packages described in this tutorial.


1. java.applet

java.applet package provides the classes necessary to create an applet and the classes an applet uses to communicate with its applet context. The applet framework involves two entities: the applet and the applet context. An applet is an embeddable window with a few extra methods that the applet context can use to initialize, start, and stop the applet. The applet context is an application that is responsible for loading and running applets. For example, the applet context could be a Web browser or an applet development environment.

2. java.awt

java.awt package is the main package of the AWT, or Abstract Windowing Toolkit. It contains classes for graphics, including the Java 2D graphics capabilities introduced in the Java 2 platform, and also defines the basic graphical user interface (GUI) framework for Java. java.awt also includes a number of heavyweight GUI objects, many of which have been superseded by the javax.swing package.

3. java.awt.color

java.awt.color package supports color spaces and profiles. It contains an implementation of a color space based on the International Color Consortium (ICC) Profile Format Specification, Version 3.4, August 15, 1997. It also contains color profiles based on the ICC Profile Format Specification.

4. java.awt.datatransfer

java.awt.datatransfer package provides classes to support transfer of data to and from the system clipboard. Only string data is supported, and only cut, copy, and paste. Transferable interface is implemented by classes that represent data to be transferred. It includes methods to determine the possible data flavors of the object and to retrieve the data itself.

5. java.awt.dnd

java.awt.dnd package supports drag and drop operations.This package defines the classes and interfaces necessary to perform Drag and Drop operations in Java. It defines classes for the drag-source and the drop-target, as well as events for transferring the data being dragged. This package also provides a means for giving visual feedback to the user throughout the duration of the Drag and Drop operation.

6. java.awt.event

java.awt.event package provides interfaces and classes for dealing with different types of events fired by AWT components.

7. java.awt.font

java.awt.font package provides classes and interface relating to fonts.

8. java.awt.geom

java.awt.geom package provides classes for defining and performing operations on objects related to two-dimensional geometry.

9. package provides classes that allow input of Japenese, Chinese and Korean characters to text editing components.

10. package provides interfaces that enable the development of input methods that can be used with any Java runtime environment. Input methods are software components that let the user enter text in ways other than simple typing on a keyboard. They are commonly used to enter Japanese, Chinese, or Korean – languages using thousands of different characters – on keyboards with far fewer keys. However, this package also allows the development of input methods for other languages and the use of entirely different input mechanisms, such as handwriting recognition.

11. java.awt.image

java.awt.image package provides classes and interfaces for processing images.

12. java.awt.image.renderable

java.awt.image.renderable package provides classes and interfaces for producing rendering-independent images.

13. java.awt.print

java.awt.print package contains classes and interfaces that support printing. It has been introduced in Java 1.2 and supersedes the PrintJob class of the java.awt package. The most important class in this package is PrinterJob; it coordinates the printing process. The Printable and Pageable interfaces represent printable objects or documents that can be printed with a PrinterJob.


14. java.beans

java.beans package contains classes related to developing beans – components based on the JavaBeansTM architecture. A few of the classes are used by beans while they run in an application. For example, the event classes are used by beans that fire property and vetoable change events. However, most of the classes in this package are meant to be used by a bean editor. In particular, these classes help the bean editor
create a user interface that the user can use to customize the bean.

15. java.beans.beancontext

java.beans.beancontext package provides classes and interfaces relating to bean context. A bean context is a container for beans and defines the execution environment for the beans it contains. There can be several beans in a single bean context, and a bean context can be nested within another bean context. This package also contains events and listener interface for beans being added and removed from a bean context.


16. package provides for system input and output through data streams, serialization and the file system. Unless otherwise noted, passing a null argument to a constructor or method in any class or interface in this package will cause a NullPointerException to be thrown.


17. java.lang

java.lang package provides classes that are fundamental to the design of the Java programming language. The most important classes are Object, which is the root of the class hierarchy, and Class, instances of which represent classes at run time.

18. java.lang.annotation

java.lang.annotation package provides library support for the Java programming language annotation facility.

19. java.lang.instrument

java.lang.instrument package provides services that allow Java programming language agents to instrument programs running on the JVM. The mechanism for instrumentation is modification of the byte-codes of methods.

20. package provides the management interface for monitoring and management of the Java virtual machine as well as the operating system on which the Java virtual machine is running. It allows both local and remote monitoring and management of the running Java virtual machine.

21. java.lang.ref

java.lang.ref package provides reference-object classes, which support a limited degree of interaction with the garbage collector. A program may use a reference object to maintain a reference to some other object in such a way that the latter object may still be reclaimed by the collector. A program may also arrange to be notified some time after the collector has determined that the reachability of a given object has changed.

22. java.lang.reflect

java.lang.reflect package provides classes and interfaces for obtaining reflective information about classes and objects. Reflection allows programmatic access to information about the fields, methods and constructors of loaded classes, and the use reflected fields, methods, and constructors to operate on their underlying counterparts on objects, within security restrictions.


23. java.math

java.math package provides classes for performing arbitrary-precision integer arithmetic (BigInteger) and arbitrary-precision decimal arithmetic (BigDecimal). BigInteger is analogous to Java’s primitive integer types except that it provides arbitrary precision, hence operations on BigIntegers do not overflow or lose precision. In addition to standard arithmetic operations, BigInteger provides modular arithmetic, GCD calculation, primality testing, prime generation, bit manipulation, and a few other miscellaneous operations. BigDecimal provides arbitrary-precision signed decimal numbers suitable for currency calculations and the like. BigDecimal gives the user complete control over rounding behavior, allowing the user to choose from a comprehensive set of eight rounding modes.


24. package provides the classes for implementing networking applications. Using the socket classes, you can communicate with any server on the Internet or implement your own Internet server. A number of classes are provided to make it convenient to use Universal Resource Locators (URLs) to retrieve data on the Internet.

25. java.nio

java.nio package defines buffers, which are containers for data, and provides an overview of the other NIO packages.

26. java.nio.channels

java.nio.channels package defines channels, which represent connections to entities that are capable of performing I/O operations, such as files and sockets; defines selectors, for multiplexed, non-blocking I/O operations.

27. java.nio.channels.spi

java.nio.channels.spi package provides Service-provider classes for the java.nio.channels package.

28. java.nio.charset

java.nio.charset package defines charsets, decoders, and encoders, for translating between bytes and Unicode characters.

29. java.nio.charset.spi

java.nio.charset.spi package provides Service-provider classes for the java.nio.charset package.


30. java.rmi

java.rmi package provides classes for remote method invocation.

31. java.rmi.activation

java.rmi.activation package provides classes for activation of persistent objects.

32. java.rmi.dgc

java.rmi.dgc package provides classes and interface for RMI distributed garbage-collection (DGC).

33. java.rmi.registry

java.rmi.registry package provides a class and two interfaces for the RMI registry. A registry is a remote object that maps names to remote objects. A server registers its remote objects with the registry so that they can be looked up. When an object wants to invoke a method on a remote object, it must first lookup the remote object using its name. The registry returns to the calling object a reference to the remote object, using which a remote method can be invoked.

34. java.rmi.server

java.rmi.server package provides classes and interfaces for supporting the server side of RMI. A group of classes are used by the stubs and skeletons generated by the rmic stub compiler. Another group of classes implements the RMI Transport protocol and HTTP tunneling.


35. package contains the classes and interfaces that implement the Java security architecture. These classes can be divided into two broad categories. First, there are classes that implement access control and prevent untrusted code from performing sensitive operations. Second, there are authentication classes that implement message digests and digital signatures and can authenticate Java classes and other objects.

36. package defines, but does not implement, an incomplete framework for working with access control lists (ACLs). This package was added in Java 1.1, but has been superseded in Java 1.2 by the access-control mechanisms of the package.

37. package provides classes and interfaces for parsing and managing certificates, certificate revocation lists (CRLs), and certification paths. It contains support for X.509 v3 certificates and X.509 v2 CRLs.

38. package provides interfaces for generating RSA (Rivest, Shamir and Adleman AsymmetricCipher algorithm) keys as defined in the RSA Laboratory Technical Note PKCS#1, and DSA (Digital Signature Algorithm) keys as defined in NIST’s FIPS-186.

39. package provides classes and interfaces for key pecifications and algorithm parameter specifications.A key specification is a transparent representation of the key material that constitutes a key. A key may be specified in an algorithm-specific way, or in an algorithm-independent encoding format (such as ASN.1). This package contains key specifications for DSA public and private keys, RSA public and private keys, PKCS #8 private keys in DER-encoded format, and X.509 public and private keys in DER-encoded format. An algorithm parameter specification is a transparent representation of the sets of parameters used with an algorithm. This package contains an algorithm parameter specification for parameters used with the DSA algorithm.

40. java.sql

java.sql package provides the API for accessing and processing data stored in a data source (usually a relational database) using the JavaTM programming language. This API includes a framework whereby different drivers can be installed dynamically to access different data sources. Although the JDBC API is mainly geared to passing SQL statements to a database, it provides for reading and writing data from any data source with a tabular format. The reader/writer facility, available through the javax.sql.RowSet group of interfaces, can be customized to use and update data from a spread sheet, flat file, or any other tabular data source.


41. java.text

java.text package consists of classes and interfaces that are useful for writing internationalized programs that handle local customs, such as date and time formatting and string alphabetization, correctly.

42. java.text.spi

java.text.spi package provides Service provider classes for the classes in the java.text package.


43. java.util

java.util package contains the collections framework, legacy collection classes, event model, date and time facilities, internationalization, and miscellaneous utility classes (a string tokenizer, a random-number generator, and a bit array).

44. java.util.concurrent

java.util.concurrent package contains Utility classes commonly useful in concurrent programming. This package includes a few small standardized extensible frameworks, as well as some classes that provide useful functionality and are otherwise tedious or difficult to implement.

45. java.util.concurrent.atomic

java.util.concurrent.atomic package provides a small toolkit of classes that support lock-free thread-safe programming on single variables.

46. java.util.concurrent.locks

java.util.concurrent.locks package provides Interfaces and classes which provide a framework for locking and waiting for conditions that is distinct from built-in synchronization and monitors. The framework permits much greater flexibility in the use of locks and conditions, at the expense of more awkward syntax.

47. java.util.jar

java.util.jar package provides classes for reading and writing the JAR (Java ARchive) file format, which is based on the standard ZIP file format with an optional manifest file. The manifest stores meta-information about the JAR file contents and is also used for signing JAR files.

48. java.util.logging

java.util.logging package provides the classes and interfaces of the JavaTM 2 platform’s core logging facilities. The central goal of the logging APIs is to support maintaining and servicing software at customer sites.

49. java.util.prefs

java.util.prefs package allows applications to store and retrieve user and system preference and configuration data. This data is stored persistently in an implementation-dependent backing store. There are two separate trees of preference nodes, one for user preferences and one for system preferences.

50. java.util.regex

java.util.regex package provides classes for matching character sequences against patterns specified by regular expressions.

51. java.util.spi

java.util.spi package provides Service provider classes for the classes in the java.util package.

52. package provides classes for reading and writing the standard ZIP and GZIP file formats. Also includes classes for compressing and decompressing data using the DEFLATE compression algorithm, which is used by the ZIP and GZIP file formats. Additionally, there are utility classes for computing the CRC-32 and Adler-32 checksums of arbitrary input streams.

Some other Java Packages

1. javax.accessibility.*
2. javax.activation.*
3. javax.bluetooth.*
4. javax.crypto.*
5. javax.ejb.*
6. javax.enterprise.*
7. javax.faces.*
8. javax.ide.*
9. javax.imageio.*
10. javax.jms.*
11. javax.mail.*
13. javax.microedition.*
14. javax.naming.*
16. javax.print.*
17. javax.resource.*
18. javax.rmi.*
20. javax.servlet.*
21. javax.sound.*
22. javax.sql.*
23. javax.swing.*
24. javax.transaction.*
25. javax.xml.*

sources: , ,

Posted in Java | 3 Comments »

Freeware Utilities

Posted by Narendra Dhami on September 10, 2009

NirSoft web site provides a unique collection of small and useful freeware utilities, all of them developed by Nir Sofer. More …

Posted in Utilities | Leave a Comment »

Optimizing PHP

Posted by Narendra Dhami on September 8, 2009

A HOWTO on Optimizing PHP

PHP is a very fast programming language, but there is more to optimizing PHP than just speed of code execution.

In this chapter, we explain why optimizing PHP involves many factors which are not code related, and why tuning PHP requires an understanding of how PHP performs in relation to all the other subsystems on your server, and then identifying bottlenecks caused by these subsystems and fixing them. We also cover how to tune and optimize your PHP scripts so they run even faster.

Achieving High Performance

When we talk about good performance, we are not talking about how fast your PHP scripts will run. Performance is a set of tradeoffs between scalability and speed. Scripts tuned to use fewer resources might be slower than scripts that perform caching, but more copies of the same script can be run at one time on a web server.

In the example below, A.php is a sprinter that can run fast, and B.php is a marathon runner than can jog forever at the nearly the same speed. For light loads, A.php is substantially faster, but as the web traffic increases, the performance of B.php only drops a little bit while A.php just runs out of steam.
More …

Posted in PHP | Leave a Comment »

How To Set Up Database Replication In MySQL

Posted by Narendra Dhami on September 7, 2009

This tutorial describes how to set up database replication in MySQL. MySQL replication allows you to have an exact copy of a database from a master server on another server (slave), and all updates to the database on the master server are immediately replicated to the database on the slave server so that both databases are in sync. This is not a backup policy because an accidentally issued DELETE command will also be carried out on the slave; but replication can help protect against hardware failures though. More …

Adding More Slaves …

Switching Masters During Fail-over …

Master to Slave and Master to Master ….

Posted in MySQL | 1 Comment »

MySQL Stored Procedures

Posted by Narendra Dhami on September 3, 2009

MySQL 5.0 finally introduces functionality for Stored Procedures. So what exactly are stored procedures? That is the kind of question that gets database professionals who use other DBMS’s raising their eyebrows. Stored procedures have been integral to Oracle, PostgreSQL, DB-2, MS-SQL server and others for years, and it has long been a sore point that MySQL has not had them. But there is no snobbery here – if you are a MySQL newbie, or have been using MySQL for years and want to find out what all the fuss is about, read on. If it is your eyebrows that are raised, and you just want to know how MySQL implements them, you will be relieved to know MySQL stored procedures are very similar to the DB2 implementation, as both are based on the SQL:2003 standard.

A stored procedure is simply a procedure that is stored on the database server. MySQL developers have to date unthinkingly written and stored their procedures on the application (or web) server, mainly because there hasn’t been an option. That has been limiting. Some have claimed that there are two schools of thought – one claiming that logic should be in the application, the other saying it should reside in the database. However, most professionals would not bind themselves to one or other viewpoint at all times. As always, there are times when doing either makes sense. Unfortunately, some of the staunchest adherents of the in the application school are only there because until now they have had no choice, and it is what they are used to doing. So why would we want to place logic on the database server?

More …
Part 1  
Part 2  
Part 3

Posted in MySQL | Leave a Comment »

Create daemons in PHP

Posted by Narendra Dhami on September 3, 2009

Everyone knows PHP can be used to create websites. But it can also be used to create desktop applications and commandline tools. And now with a class called System_Daemon, you can even create daemons using nothing but PHP. And did I mention it was easy?
What is a Daemon?

A daemon is a Linux program that run in the background, just like a ‘Service’ on Windows. It can perform all sorts of tasks that do not require direct user input. Apache is a daemon, so is MySQL. All you ever hear from them is found in somewhere in /var/log, yet they silently power over 40% of the Internet.

You reading this page, would not have been possible without them. So clearly: a daemon is a powerful thing, and can be bend to do a lot of different tasks.
Why PHP?

Most daemons are written in C. It’s fast & robust. But if you are in a LAMP oriented company like me, and you need to create a lot of software in PHP anyway, it makes sense:

* Reuse & connect existing code
Think of database connections, classes that create customers from your CRM, etc.
* Deliver new applications very fast
PHP has a lot of build in functions that speed up development greatly.
* Everyone knows PHP (right?)
If you work in a small company: chances are there are more PHP programmers than there are C programmers. What if your C guy abandons ship?

Possible use cases

* Website optimization
If you’re running a (large) website, jobs that do heavy lifting should be taken away from the user interface and scheduled to run on the machine separately.
* Log parser
Continually scan logfiles and import critical messages in your database.
* SMS daemon
Read a database queue, and let your little daemon interface with your SMS provider. If it fails, it can easily try again later!
* Video converter (think Youtube)
Scan a queue/directory for incoming video uploads. Make some system calls to ffmpeg to finally store them as Flash video files. Surely you don’t want to convert video files right after the upload, blocking the user interface that long? No: the daemon will send the uploader a mail when the conversion is done, and proceed with the next scheduled upload

Deamons vs Cronjobs

Some people use cronjobs for the same Possible use cases. Crontab is fine but it only allows you to run a PHP file every minute or so.

* What if the previous run hasn’t finished yet? Overlap can seriously damage your data & cause siginificant load on your machines.
* What if you can’t afford to wait a minute for the cronjob to run? Maybe you need to trigger a process the moment a record is inserted?
* What if you want to keep track of multiple ‘runs’ and store data in memory.
* What if you need to keep your application listening (on a socket for example)

Cronjobs are a bit rude for this, they may spin out of control and don’t provide a framework for logging, etc. Creating a daemon would offer more elegance & possibilities. Let’s just say: there are very good reasons why a Linux OS isn’t composed entirely of Cronjobs 🙂
How it works internally

(Nerd alert!) When a daemon program is started, it fires up a second child process, detaches it, and then the parent process dies. This is called forking. Because the parent process dies, it will give the console back and it will look like nothing has happened. But wait: the child process is still running. Even if you close your terminal, the child continues to run in memory, until it either stops, crashes or is killed.

In PHP: forking can be achieved by using the Process Control Extensions. Getting a good grip on it, may take some studying though. More …

Posted in PHP | Leave a Comment »