Showing posts with label Tips and Tricks. Show all posts
Showing posts with label Tips and Tricks. Show all posts

Dec 3, 2009

Performance Optimization for large I/O Operations

This article discussed about the following topics

  • Issues with export & import of huge files
  • Our Approaches to resolve these issues
  • NIO package advantage
  • Performance issues during serialization
  • Progressive rendering
  • Case Studies with Solutions

Issues while exporting huge files

Issues faced during exporting or importing of large Data/Files:

  • It takes long time to export or import a huge data/file.
  • Out of Memory error during the file I/O operation or copying to a location.
  • In some instances the application hangs. Hard disks are very good at reading and writing sizable chunks of data, but they are much less efficient when working with small blocks of data.
  • Transaction timeouts.

Our Approach-Key points

The basic rules for speeding up I/O performance are

  • To maximize I/O performance, you should batch read and write operations.
  • Use Buffered stream operation to achieve batch read and write operations or use Java NIO package.
  • Minimize accessing the hard disk.
  • Minimize processing bytes and characters individually.
  • Minimize accessing the underlying operating system.
  • Better understanding of java.io and nio package  package can lead to major improvements in I/O performance.

Let us look at some of the techniques to improve I/O performance

  • Large chunks of a file are read from a disk and then accessed a byte or character at a time. This is a problem.
  • Use buffering to minimize disk access and underlying operating system. As shown below, with buffering

Without buffering : inefficient code

try
{
File f = new File("myFile.txt");
FileInputStream fis = new FileInputStream(f);
int count = 0;
int b = ;
while((b = fis.read()) != -1)
{
if(b== '\n')
{
count++;
}
}
// fis should be closed in a finally block.
fis.close() ;
}
catch(IOException io)
{
}


Note : fis.read() is a native method call to theunderlying system.



With Buffering: yields better performance



try
{
File f = new File("myFile.txt");
FileInputStream fis = new FileInputStream(f);
BufferedInputStream bis = new BufferedInputStream(fis);
int count = 0;
int b = ;
while((b = bis.read()) != -1)
{
if(b== '\n')
{
count++;
}
}
//bis should be closed in a finally block.
bis.close() ;
}
catch(IOException io)
{
}


Note: bis.read() takes the next byte from the input buffer and only rarely access the underlying operating system.




  • Instead of reading a character or a byte at a time, the above code with buffering can be improved further by reading one line at a time as shown below:



FileReader fr = new FileReader(f); 
BufferedReader br = new BufferedReader(fr);
While (br.readLine() != null) count++;



  • It is recommended to use logging frameworks like Log4J or apache commons  logging, which uses buffering instead of using default behavior of System.out.println(…..) for better performance.



Use the NIO package




  • If you are using JDK 1.4 or later use the NIO package, which uses performance-enhancing features like buffers to hold data, memory mapping of files, non-blocking I/O operations etc.


  • Previously Java IO code must read data from the file system, bring it up into JVM memory, and then push it back down to the file system through Java IO.


  • Java NIO has the potential to really improve performance in a lot of areas. File copies is just one of them


  • Provides the ability to monitor multiple I/O operations concurrently, also known as "multiplexing."


  • Multiplexed NIO is a technique that moves all the I/O work into a single thread that watches over many I/O operations executing concurrently.



NIO-Example



Basic file-to-file copy algorithm implemented using 'NIO':



public static void copyFile(File sourceFile, File destFile) throws IOException
{
if(!destFile.exists())
{
destFile.createNewFile();
}
FileChannel source = null;
FileChannel destination = null;
try
{
source = new FileInputStream(sourceFile).getChannel();
destination = new FileOutputStream(destFile).getChannel();
destination.transferFrom(source, 0, source.size());
}
finally
{
if(source != null)
{
source.close();
}
if(destination != null)
{
destination.close();
}
}
}


Use the NIO package




  • Note that there is no reference to the buffering used or the implementation of the actual copy algorithm.


  • This is key to the potential performance advantages of this algorithm.



Serialization Example




  • Serializing a class and writing to an Output stream.


  • This stems from the fact that serialization is a recursive process.


  • If your class has Jpanel then all of the Swing UI widgets and any objects they reference in a class are written. This is one care item to be taken care during Serialization.


  • To improved Serialization we need to take care when object are serialized.


  • Use the transient keyword to specify when the object implements Serialization.



 


image

public class TestObject implements Serializable
{
private int value;
private String name;
private Date timeStamp;
private JPanel panel;
public TestObject(int value)
{
this.value = value;
name = new String("Object:" + value);
timeStamp = new Date();
panel = new JPanel();
panel.add(new JTextField());
panel.add(new JButton("Help"));
panel.add(new JLabel("This is a text label"));
}
}
//Writing objects to a stream:
for (int i =0;i <50; i++)
{
vector.addElement(new TestObject(i));
}
Stopwatch timer = new Stopwatch().start();
try
{
OutputStream file = new FileOutputStream("Out.test");
OutputStream buffer = new BufferedOutputStream(file);
ObjectOutputStream out = new ObjectOutputStream(buffer);
out.writeObject(vector);
out.close();
}
catch (Exception e)
{
e.printStackTrace();
}
timer.stop();
System.out.println("elapsed = " + timer.getElapsedTime());
//Reading Objects From the Stream:
Stopwatch timer = new Stopwatch().start();
try
{
InputStream file = new FileInputStream("Out.test");
InputStream buffer = new BufferedInputStream(file);
ObjectInputStream in = new ObjectInputStream(buffer);
vector = (Vector)in.readObject();
in.close();
}
catch (Exception e)
{
e.printStackTrace();
}
timer.stop();
System.out.println("elapsed = " + timer.getElapsedTime());
//Improved serializable object
public class TestObjectTrans implements Serializable
{
private int value;
private transient String name;
private Date timeStamp;
private transient JPanel panel;
public TestObjectTrans(int value)
{
this.value = value;
timeStamp = new Date();
initTransients();
}
public void initTransients()
{
name = new String("Object:" + value);
panel = new JPanel();
panel.add(new JTextField());
panel.add(new JButton("Help"));
panel.add(new JLabel("This is a text label"));
}
private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException
{
in.defaultReadObject();
initTransients();
}
}


Case Study 1



Requirement :




  • Export the data to an export sheet when export data link is clicked.


  • Data is retrieved from a table which has 65 columns and more than 80,000 records.



Solution:




  • To achieve the above requirement read the records using readLine() and store it in a String Buffer and write to an Output Stream using NIO.


  • Keep a counter and which will count the number of records.


  • The string Buffer length to be set to 0 and clear the memory and flush the output stream when counter count reaches 20.


  • Clearing will have the advantage of not storing the huge data in memory and write the data quickly to the outputstream.



Case Study 2



Requirement:




  • Read a CSV file of 50MB and insert the data into a DB based on few processing instructions.



Solution:




  • Read the file from the remote Location and copy to a local location using java NIO on the server for faster retrieval. This should be a temporary file.


  • Use readLine() of the file InputStream and process data is set of 50 by storing them in a String Buffer.


  • Use a batchupdate to store data in records of 50 it in the database.


  • Incase if there is an exception in process of updating the batch job then we will add the 50 records in an exception list & process them one by one separately.


  • The logger will contain the error log for records which were not updated with exception.



Case Study 3



Requirement:




  • User selects to generate a 500 pages PDF report on click of a link/submit of a page.



Solution:




  • Since the report size is too huge of 500 page. We will loading the whole page in background, but just show around first 10 to 20 pages on click or submit so that user UI is not hanged/idle till all the 500 pages.


  • As the user scroll down the PDF the remaining pages will be loaded parallel in background.


  • Progressive rendering is the act of displaying each object as it is downloaded.


  • A method and a system are provided for processing displayed text and progressively displaying results of processing the displayed text. In some embodiments, displayed text may be submitted as processing requests to process portions of the displayed text Both IE and FF supports progressive rendering;


  • They differ on how they render tables.


  • Internet Explorer renders a , it downloads all the objects within the table before displaying it. This is required so that Internet Explorer can render the table with the correct width for each column.


  • Firefox renders all objects progressively regardless if it's in a table. That is to say - each object is displayed as soon as it is downloaded.


  • If a html page has to display a table with more than 1000 records then make an Ajax call and load the data progressively for a set of 50 records.


Performance Optimization for large I/O Operations

This article discussed about the following topics

  • Issues with export & import of huge files
  • Our Approaches to resolve these issues
  • NIO package advantage
  • Performance issues during serialization
  • Progressive rendering
  • Case Studies with Solutions

Issues while exporting huge files

Issues faced during exporting or importing of large Data/Files:

  • It takes long time to export or import a huge data/file.
  • Out of Memory error during the file I/O operation or copying to a location.
  • In some instances the application hangs. Hard disks are very good at reading and writing sizable chunks of data, but they are much less efficient when working with small blocks of data.
  • Transaction timeouts.

Our Approach-Key points

The basic rules for speeding up I/O performance are

  • To maximize I/O performance, you should batch read and write operations.
  • Use Buffered stream operation to achieve batch read and write operations or use Java NIO package.
  • Minimize accessing the hard disk.
  • Minimize processing bytes and characters individually.
  • Minimize accessing the underlying operating system.
  • Better understanding of java.io and nio package  package can lead to major improvements in I/O performance.

Let us look at some of the techniques to improve I/O performance

  • Large chunks of a file are read from a disk and then accessed a byte or character at a time. This is a problem.
  • Use buffering to minimize disk access and underlying operating system. As shown below, with buffering

Without buffering : inefficient code

try
{
File f = new File("myFile.txt");
FileInputStream fis = new FileInputStream(f);
int count = 0;
int b = ;
while((b = fis.read()) != -1)
{
if(b== '\n')
{
count++;
}
}
// fis should be closed in a finally block.
fis.close() ;
}
catch(IOException io)
{
}


Note : fis.read() is a native method call to theunderlying system.



With Buffering: yields better performance



try
{
File f = new File("myFile.txt");
FileInputStream fis = new FileInputStream(f);
BufferedInputStream bis = new BufferedInputStream(fis);
int count = 0;
int b = ;
while((b = bis.read()) != -1)
{
if(b== '\n')
{
count++;
}
}
//bis should be closed in a finally block.
bis.close() ;
}
catch(IOException io)
{
}


Note: bis.read() takes the next byte from the input buffer and only rarely access the underlying operating system.




  • Instead of reading a character or a byte at a time, the above code with buffering can be improved further by reading one line at a time as shown below:



FileReader fr = new FileReader(f); 
BufferedReader br = new BufferedReader(fr);
While (br.readLine() != null) count++;



  • It is recommended to use logging frameworks like Log4J or apache commons  logging, which uses buffering instead of using default behavior of System.out.println(…..) for better performance.



Use the NIO package




  • If you are using JDK 1.4 or later use the NIO package, which uses performance-enhancing features like buffers to hold data, memory mapping of files, non-blocking I/O operations etc.


  • Previously Java IO code must read data from the file system, bring it up into JVM memory, and then push it back down to the file system through Java IO.


  • Java NIO has the potential to really improve performance in a lot of areas. File copies is just one of them


  • Provides the ability to monitor multiple I/O operations concurrently, also known as "multiplexing."


  • Multiplexed NIO is a technique that moves all the I/O work into a single thread that watches over many I/O operations executing concurrently.



NIO-Example



Basic file-to-file copy algorithm implemented using 'NIO':



public static void copyFile(File sourceFile, File destFile) throws IOException
{
if(!destFile.exists())
{
destFile.createNewFile();
}
FileChannel source = null;
FileChannel destination = null;
try
{
source = new FileInputStream(sourceFile).getChannel();
destination = new FileOutputStream(destFile).getChannel();
destination.transferFrom(source, 0, source.size());
}
finally
{
if(source != null)
{
source.close();
}
if(destination != null)
{
destination.close();
}
}
}


Use the NIO package




  • Note that there is no reference to the buffering used or the implementation of the actual copy algorithm.


  • This is key to the potential performance advantages of this algorithm.



Serialization Example




  • Serializing a class and writing to an Output stream.


  • This stems from the fact that serialization is a recursive process.


  • If your class has Jpanel then all of the Swing UI widgets and any objects they reference in a class are written. This is one care item to be taken care during Serialization.


  • To improved Serialization we need to take care when object are serialized.


  • Use the transient keyword to specify when the object implements Serialization.



 


image

public class TestObject implements Serializable
{
private int value;
private String name;
private Date timeStamp;
private JPanel panel;
public TestObject(int value)
{
this.value = value;
name = new String("Object:" + value);
timeStamp = new Date();
panel = new JPanel();
panel.add(new JTextField());
panel.add(new JButton("Help"));
panel.add(new JLabel("This is a text label"));
}
}
//Writing objects to a stream:
for (int i =0;i <50; i++)
{
vector.addElement(new TestObject(i));
}
Stopwatch timer = new Stopwatch().start();
try
{
OutputStream file = new FileOutputStream("Out.test");
OutputStream buffer = new BufferedOutputStream(file);
ObjectOutputStream out = new ObjectOutputStream(buffer);
out.writeObject(vector);
out.close();
}
catch (Exception e)
{
e.printStackTrace();
}
timer.stop();
System.out.println("elapsed = " + timer.getElapsedTime());
//Reading Objects From the Stream:
Stopwatch timer = new Stopwatch().start();
try
{
InputStream file = new FileInputStream("Out.test");
InputStream buffer = new BufferedInputStream(file);
ObjectInputStream in = new ObjectInputStream(buffer);
vector = (Vector)in.readObject();
in.close();
}
catch (Exception e)
{
e.printStackTrace();
}
timer.stop();
System.out.println("elapsed = " + timer.getElapsedTime());
//Improved serializable object
public class TestObjectTrans implements Serializable
{
private int value;
private transient String name;
private Date timeStamp;
private transient JPanel panel;
public TestObjectTrans(int value)
{
this.value = value;
timeStamp = new Date();
initTransients();
}
public void initTransients()
{
name = new String("Object:" + value);
panel = new JPanel();
panel.add(new JTextField());
panel.add(new JButton("Help"));
panel.add(new JLabel("This is a text label"));
}
private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException
{
in.defaultReadObject();
initTransients();
}
}


Case Study 1



Requirement :




  • Export the data to an export sheet when export data link is clicked.


  • Data is retrieved from a table which has 65 columns and more than 80,000 records.



Solution:




  • To achieve the above requirement read the records using readLine() and store it in a String Buffer and write to an Output Stream using NIO.


  • Keep a counter and which will count the number of records.


  • The string Buffer length to be set to 0 and clear the memory and flush the output stream when counter count reaches 20.


  • Clearing will have the advantage of not storing the huge data in memory and write the data quickly to the outputstream.



Case Study 2



Requirement:




  • Read a CSV file of 50MB and insert the data into a DB based on few processing instructions.



Solution:




  • Read the file from the remote Location and copy to a local location using java NIO on the server for faster retrieval. This should be a temporary file.


  • Use readLine() of the file InputStream and process data is set of 50 by storing them in a String Buffer.


  • Use a batchupdate to store data in records of 50 it in the database.


  • Incase if there is an exception in process of updating the batch job then we will add the 50 records in an exception list & process them one by one separately.


  • The logger will contain the error log for records which were not updated with exception.



Case Study 3



Requirement:




  • User selects to generate a 500 pages PDF report on click of a link/submit of a page.



Solution:




  • Since the report size is too huge of 500 page. We will loading the whole page in background, but just show around first 10 to 20 pages on click or submit so that user UI is not hanged/idle till all the 500 pages.


  • As the user scroll down the PDF the remaining pages will be loaded parallel in background.


  • Progressive rendering is the act of displaying each object as it is downloaded.


  • A method and a system are provided for processing displayed text and progressively displaying results of processing the displayed text. In some embodiments, displayed text may be submitted as processing requests to process portions of the displayed text Both IE and FF supports progressive rendering;


  • They differ on how they render tables.


  • Internet Explorer renders a , it downloads all the objects within the table before displaying it. This is required so that Internet Explorer can render the table with the correct width for each column.


  • Firefox renders all objects progressively regardless if it's in a table. That is to say - each object is displayed as soon as it is downloaded.


  • If a html page has to display a table with more than 1000 records then make an Ajax call and load the data progressively for a set of 50 records.


Nov 21, 2009

Tips & Tricks for SQUID (Proxy) Server

Overview

This article will be helpful to improve your squid performance in any hectic and slow bandwidth / traffic kind of scenario. This will also helpful to the organization, who will use the only one Squid Server Hardware and giving the internet access to more then 1000 users. Even, you can bypass or stream line your SSL / SAFE ports for any outgoing traffic, which needs to be allow.

1) Faster Performance of Cache

To take the advantage of the Squid Cache, mount the “Cache directory” on “diskd” format. Also use more than 1 hard disk and mount /cache directory on each hard disk to get faster performance of cache.

2) Partition & Mount Point

Create and Mount the /log and /var directory on separate hard disk to faster performance of Squid Server.

3) Bandwidth Management

If you have Lower Bandwidth and Higher End Server with minimum 3 harddisk for Cache and 4 GB Minimum Ram, then keep:

“maximum_object_size 4028 KB” &
“maximum_object_size_in_memory 3072 KB”
And, If you have Higher Bandwidth and Lowered Server, then keep:
“maximum_object_size 1024 KB” &
“maximum_object_size_in_memory 512 KB”


4) Only 1 Authentication



To set the one user can access the internet from one system only on same time, add the below line to your squid.conf file.



acl only1 max_user_ip -s 1
http_access deny only1


5) Squid File Modify



When ever you need to change your squid.conf file, save it and write the command as below to take the change effect immediately:



squid –k reconf


6) Cache Initialization



If and problem persist regarding to initializing the squid cache, give the write permission to the specified directory. (i.e. chmod 777 /cache)



7) Use Maximum Memory for Squid 



If you have more than sufficient memory in your squid server, set the below lines in your squid.conf file, to get the highest performance of your unused memory.



memory_pools on
memory_pools_limit 2048 MB


If you set the value of memory_pools_limit to 0, squid will keep all memory it can.



8) Retry while Error



If set “retry_on_error on”, squid will automatically retry requests when receiving an error response. This is mainly useful if you are in a complex cache hierarchy to work around access control errors.



9) Memory Warning



If you set this to “high_memory_warning 2048 MB”, and the memory usage will be exceeds to determined value, Squid prints a WARNING with debug level 0 to get the administrators attention.

10) Bypass the SSL ports 



To bypass the SSL ports from squid server, mentioned the acl as below:



acl SSL_ports port 443
http_access deny CONNECT !SSL_ports

Tips & Tricks for SQUID (Proxy) Server

Overview

This article will be helpful to improve your squid performance in any hectic and slow bandwidth / traffic kind of scenario. This will also helpful to the organization, who will use the only one Squid Server Hardware and giving the internet access to more then 1000 users. Even, you can bypass or stream line your SSL / SAFE ports for any outgoing traffic, which needs to be allow.

1) Faster Performance of Cache

To take the advantage of the Squid Cache, mount the “Cache directory” on “diskd” format. Also use more than 1 hard disk and mount /cache directory on each hard disk to get faster performance of cache.

2) Partition & Mount Point

Create and Mount the /log and /var directory on separate hard disk to faster performance of Squid Server.

3) Bandwidth Management

If you have Lower Bandwidth and Higher End Server with minimum 3 harddisk for Cache and 4 GB Minimum Ram, then keep:

“maximum_object_size 4028 KB” &
“maximum_object_size_in_memory 3072 KB”
And, If you have Higher Bandwidth and Lowered Server, then keep:
“maximum_object_size 1024 KB” &
“maximum_object_size_in_memory 512 KB”


4) Only 1 Authentication



To set the one user can access the internet from one system only on same time, add the below line to your squid.conf file.



acl only1 max_user_ip -s 1
http_access deny only1


5) Squid File Modify



When ever you need to change your squid.conf file, save it and write the command as below to take the change effect immediately:



squid –k reconf


6) Cache Initialization



If and problem persist regarding to initializing the squid cache, give the write permission to the specified directory. (i.e. chmod 777 /cache)



7) Use Maximum Memory for Squid 



If you have more than sufficient memory in your squid server, set the below lines in your squid.conf file, to get the highest performance of your unused memory.



memory_pools on
memory_pools_limit 2048 MB


If you set the value of memory_pools_limit to 0, squid will keep all memory it can.



8) Retry while Error



If set “retry_on_error on”, squid will automatically retry requests when receiving an error response. This is mainly useful if you are in a complex cache hierarchy to work around access control errors.



9) Memory Warning



If you set this to “high_memory_warning 2048 MB”, and the memory usage will be exceeds to determined value, Squid prints a WARNING with debug level 0 to get the administrators attention.

10) Bypass the SSL ports 



To bypass the SSL ports from squid server, mentioned the acl as below:



acl SSL_ports port 443
http_access deny CONNECT !SSL_ports

Nov 20, 2009

Top 10 Blackberry Troubleshooting Tips

Introduction

Use this article to resolve a problem involving or relating to the BlackBerry wireless device, before engaging the help of your BlackBerry technical support provider.

Troubleshooting Tips

Tip 1

Check the signal strength. Sufficient signal strength allows the BlackBerry device to send and receive wireless information.

  • Turn on the device.
  • On the device Home screen, click Options and select Status.
  • In the Signal field, verify the value is less than 100 dBm.

Note: For BlackBerry devices, verify GPRS, or EDGE network status indicators appear in the status section on the Home screen.

Tip 2

Reset the device.

Tip 3

Check network settings. Appropriate network settings enable the device to send and receive information on the wireless network.

For BlackBerry wireless devices based on Java

  • On the device Home screen, click Options and select Network.
  • Click Scan for Networks and verify the device is running on the correct network.

For RIM Wireless Handhelds based on C++

  • On the RIM handheld, click Options and select Network Settings.
  • In the Radio field, verify the value is set to On.
  • Verify the appropriate country is set for Roaming.
  • Verify the status is active.
  • Click the trackwheel and select Register Now.
  • Verify the handheld registration request has been sent

Tip 4

Verify the device-to-computer connection to confirm that the device connects properly to the personal computer.

  • Verify the device is properly connected to the personal computer.
  • Close and open BlackBerry Desktop Manager.
  • Verify the device is detected.

Tip 5

Synchronize the device with the BlackBerry Desktop Software in order to verify that the information is current.

  • Connect the device to the personal computer.
  • In Desktop Manager, open Intellisync.
  • Click Configure PIM and select the application check box you want to synchronize.
  • Click OK.
  • Verify the Synchronize PIM option is selected.
  • Click Synchronize Now.

Tip 6

Send a test message from the mail client to the device. If you receive the message in your device Inbox, this proves your messaging and collaboration server is able to process internal messaging.

Tip 7

Send a message and personal identification number (PIN) message from the device. This confirms that you can send messages from the device to the mail client or to other recipients with a BlackBerry device.

Tip 8

Verify messages are redirected to the device based on the following message redirection method:

  • BlackBerry Enterprise Server - Check with your BlackBerry Enterprise Server administrator to verify the BlackBerry Enterprise Server is working as expected.
  • BlackBerry Desktop Redirector - Confirm the BlackBerry Desktop Redirector is running on the personal computer and displays a Running status.
  • BlackBerry Internet Service - Contact your service provider to verify the account is provisioned properly.

Tip 9

Run the BlackBerry Application Loader in order to verify that your applications are loaded correctly.

Warning: Back up the device data with the Backup and Restore application before your

complete the following steps.

  • Connect the device to the personal computer.
  • In Desktop Manager, open Application Loader.
  • Click Next and follow the on-screen instructions

Tip 10

For specific issues and troubleshooting tips, search the Support Knowledge Base.

Conclusion

If you are still experiencing issues after troubleshooting, Consult the BlackBerry Technical Support (Incase of India it is with Airtel-9871427070)

Top 10 Blackberry Troubleshooting Tips

Introduction

Use this article to resolve a problem involving or relating to the BlackBerry wireless device, before engaging the help of your BlackBerry technical support provider.

Troubleshooting Tips

Tip 1

Check the signal strength. Sufficient signal strength allows the BlackBerry device to send and receive wireless information.

  • Turn on the device.
  • On the device Home screen, click Options and select Status.
  • In the Signal field, verify the value is less than 100 dBm.

Note: For BlackBerry devices, verify GPRS, or EDGE network status indicators appear in the status section on the Home screen.

Tip 2

Reset the device.

Tip 3

Check network settings. Appropriate network settings enable the device to send and receive information on the wireless network.

For BlackBerry wireless devices based on Java

  • On the device Home screen, click Options and select Network.
  • Click Scan for Networks and verify the device is running on the correct network.

For RIM Wireless Handhelds based on C++

  • On the RIM handheld, click Options and select Network Settings.
  • In the Radio field, verify the value is set to On.
  • Verify the appropriate country is set for Roaming.
  • Verify the status is active.
  • Click the trackwheel and select Register Now.
  • Verify the handheld registration request has been sent

Tip 4

Verify the device-to-computer connection to confirm that the device connects properly to the personal computer.

  • Verify the device is properly connected to the personal computer.
  • Close and open BlackBerry Desktop Manager.
  • Verify the device is detected.

Tip 5

Synchronize the device with the BlackBerry Desktop Software in order to verify that the information is current.

  • Connect the device to the personal computer.
  • In Desktop Manager, open Intellisync.
  • Click Configure PIM and select the application check box you want to synchronize.
  • Click OK.
  • Verify the Synchronize PIM option is selected.
  • Click Synchronize Now.

Tip 6

Send a test message from the mail client to the device. If you receive the message in your device Inbox, this proves your messaging and collaboration server is able to process internal messaging.

Tip 7

Send a message and personal identification number (PIN) message from the device. This confirms that you can send messages from the device to the mail client or to other recipients with a BlackBerry device.

Tip 8

Verify messages are redirected to the device based on the following message redirection method:

  • BlackBerry Enterprise Server - Check with your BlackBerry Enterprise Server administrator to verify the BlackBerry Enterprise Server is working as expected.
  • BlackBerry Desktop Redirector - Confirm the BlackBerry Desktop Redirector is running on the personal computer and displays a Running status.
  • BlackBerry Internet Service - Contact your service provider to verify the account is provisioned properly.

Tip 9

Run the BlackBerry Application Loader in order to verify that your applications are loaded correctly.

Warning: Back up the device data with the Backup and Restore application before your

complete the following steps.

  • Connect the device to the personal computer.
  • In Desktop Manager, open Application Loader.
  • Click Next and follow the on-screen instructions

Tip 10

For specific issues and troubleshooting tips, search the Support Knowledge Base.

Conclusion

If you are still experiencing issues after troubleshooting, Consult the BlackBerry Technical Support (Incase of India it is with Airtel-9871427070)

Nov 17, 2009

DB2 Tuning Tips

1) Take out any / all-Scalar functions coded on columns in predicates. For example, this is the most common:

SELECT EMPNO, LASTNAME

FROM EMPLOYEE

WHERE YEAR(HIREDATE) = 2005

Should be coded as:

SELECT EMPNO, LASTNAME

FROM EMPLOYEE

WHERE HIREDATE BETWEEN ‘2005-01-01’ and ‘2005-12-31’


2) Take out any / all mathematics coded on columns in predicates. For example:



SELECT EMPNO, LASTNAME

FROM EMPLOYEE

WHERE SALARY * 1.1 > 50000.00

Should be coded as:

SELECT EMPNO, LASTNAME

FROM EMPLOYEE

WHERE SALARY > 50000.00 / 1.1


3) Stay away from ‘Distinct’ if at all possible.



If duplicates are to be eliminated from the result set, try:



- ‘Group By’ which looks to take advantage of any  associated indexes to eliminate a sort for uniqueness.



- Rewriting the query using an ‘In’ or ‘Exists’ subquery.



This will work if the table causing the duplicates (due to a one to many relationship) does not have data being  returned as part of the result set.



4) Minimize the SQL requests to DB2.



This is huge in performance tuning of programs, especially batch programs because they tend to process more data. Every time an SQL call is sent to the database manager, there is overhead in sending the SQL statement to DB2, going from one address space in the operating system to the DB2 address space for SQL execution.



In general, developers need to minimize:



- The number of time cursors are Opened/Closed



- The number of random SQL requests (noted as synchronized reads in  DB2 monitors).



5) Give prominence to Stage 1 over Stage 2 Predicates.



Always try to code predicates as Stage 1 and index able. In general, Stage 2 predicates do not perform as well and consume extra CPU. See the IBM SQL Reference Guide to determine what predicates are Stage 1 vs. Stage 2 and make sure to go to the correct Version of DB2 when checking. Recommendation: Use Visual Explain. 



IBM DB2 Manuals: Search on ==> Summary of Predicate Processing



6) Never put filtering logic within application code.



It is always best to have all the filtering logic that is needed written as predicates in a SQL statement. Do not leave some predicates out and have the database manager bring in extra rows and then eliminate / bypass some of the rows through program logic checks. (Some people call this Stage 3 processing)..



Deviate only when performance is an issue and not all other efforts have provided significant enough improvement in performance.



7) When using cursors, use ROWSET positioning and fetching using multi row fetch, multi row update, and multi row insert. New as of V8.



DB2 V8 introduced support for the manipulation of multiple rows on fetches, updates, and insert processing. Prior versions of DB2 would only allow for a program to process one row at a time during cursor processing. Now having the ability to fetch, update, or insert more than 1 row at a time reduces network traffic and other related costs associated with each call to DB2. The recommendation is to start with 100 row fetches, inserts, or updates, and then test other numbers. It has been proven many times that this process reduces runtime on average of 35%. Consult the IBM DB2 manuals for further detail and coding examples.



8) Take advantage of Scalar Full selects within the Select clause whenever possible. New as of V8:



Many times the output needed from SQL development requires a combination of  Detail and aggregate data together. There are typically a number of ways to code  this with SQL, but with the Scalar Full select now part of DB2 V8, there is now another option that is very efficient as long as indexes are being used.



For Example: Individual Employee Report with Aggregate Department Averages



SELECT E1.EMPNO, E1.LASTNAME, 

E1.WORKDEPT, E1.SALARY, (SELECT AVG(E2.SALARY)

FROM EMPLOYEE E2

WHERE E2.WORKDEPT = E1.WORKDEPT)

AS DEPT_AVG_SAL

FROM EMPLOYEE E1

ORDER BY E1.WORKDEPT, E1.SALARY


9) Watch out for tablespace scans.



What do you do? If you as a developer see that a tablespace scan is occurring in your SQL execution, then go through the following checklist to help figure out why?



- The predicate(s) may be poorly coded in a non-indexable way.



- The predicates in the query do not match any available indexes on the table.



- The table could be small, and DB2 decides a tablespace scan may be faster than index processing.



- The catalog statistics say the table is small, or maybe there are no statistics on the table.



- The predicates are such that DB2 thinks the query is going to retrieve a large enough amount of data that would require a tablespace scan.



- The predicates are such that DB2 picks a non-clustered index, and the number of pages to retrieve is high enough based on total number of pages in the table to require a tablespace scan.



- The tablespace file or index files could physically be out of shape and need a REORG.



- The predicates in the query do not match any available indexes on the table





10) Only code the columns needed in the Select portion of the SQL statement.



Having extra columns can have an affect on:



- The optimizer choosing ‘Index Only’



- Expensiveness of any sorts



- Optimizer’s choice of join methods


DB2 Tuning Tips

1) Take out any / all-Scalar functions coded on columns in predicates. For example, this is the most common:

SELECT EMPNO, LASTNAME

FROM EMPLOYEE

WHERE YEAR(HIREDATE) = 2005

Should be coded as:

SELECT EMPNO, LASTNAME

FROM EMPLOYEE

WHERE HIREDATE BETWEEN ‘2005-01-01’ and ‘2005-12-31’


2) Take out any / all mathematics coded on columns in predicates. For example:



SELECT EMPNO, LASTNAME

FROM EMPLOYEE

WHERE SALARY * 1.1 > 50000.00

Should be coded as:

SELECT EMPNO, LASTNAME

FROM EMPLOYEE

WHERE SALARY > 50000.00 / 1.1


3) Stay away from ‘Distinct’ if at all possible.



If duplicates are to be eliminated from the result set, try:



- ‘Group By’ which looks to take advantage of any  associated indexes to eliminate a sort for uniqueness.



- Rewriting the query using an ‘In’ or ‘Exists’ subquery.



This will work if the table causing the duplicates (due to a one to many relationship) does not have data being  returned as part of the result set.



4) Minimize the SQL requests to DB2.



This is huge in performance tuning of programs, especially batch programs because they tend to process more data. Every time an SQL call is sent to the database manager, there is overhead in sending the SQL statement to DB2, going from one address space in the operating system to the DB2 address space for SQL execution.



In general, developers need to minimize:



- The number of time cursors are Opened/Closed



- The number of random SQL requests (noted as synchronized reads in  DB2 monitors).



5) Give prominence to Stage 1 over Stage 2 Predicates.



Always try to code predicates as Stage 1 and index able. In general, Stage 2 predicates do not perform as well and consume extra CPU. See the IBM SQL Reference Guide to determine what predicates are Stage 1 vs. Stage 2 and make sure to go to the correct Version of DB2 when checking. Recommendation: Use Visual Explain. 



IBM DB2 Manuals: Search on ==> Summary of Predicate Processing



6) Never put filtering logic within application code.



It is always best to have all the filtering logic that is needed written as predicates in a SQL statement. Do not leave some predicates out and have the database manager bring in extra rows and then eliminate / bypass some of the rows through program logic checks. (Some people call this Stage 3 processing)..



Deviate only when performance is an issue and not all other efforts have provided significant enough improvement in performance.



7) When using cursors, use ROWSET positioning and fetching using multi row fetch, multi row update, and multi row insert. New as of V8.



DB2 V8 introduced support for the manipulation of multiple rows on fetches, updates, and insert processing. Prior versions of DB2 would only allow for a program to process one row at a time during cursor processing. Now having the ability to fetch, update, or insert more than 1 row at a time reduces network traffic and other related costs associated with each call to DB2. The recommendation is to start with 100 row fetches, inserts, or updates, and then test other numbers. It has been proven many times that this process reduces runtime on average of 35%. Consult the IBM DB2 manuals for further detail and coding examples.



8) Take advantage of Scalar Full selects within the Select clause whenever possible. New as of V8:



Many times the output needed from SQL development requires a combination of  Detail and aggregate data together. There are typically a number of ways to code  this with SQL, but with the Scalar Full select now part of DB2 V8, there is now another option that is very efficient as long as indexes are being used.



For Example: Individual Employee Report with Aggregate Department Averages



SELECT E1.EMPNO, E1.LASTNAME, 

E1.WORKDEPT, E1.SALARY, (SELECT AVG(E2.SALARY)

FROM EMPLOYEE E2

WHERE E2.WORKDEPT = E1.WORKDEPT)

AS DEPT_AVG_SAL

FROM EMPLOYEE E1

ORDER BY E1.WORKDEPT, E1.SALARY


9) Watch out for tablespace scans.



What do you do? If you as a developer see that a tablespace scan is occurring in your SQL execution, then go through the following checklist to help figure out why?



- The predicate(s) may be poorly coded in a non-indexable way.



- The predicates in the query do not match any available indexes on the table.



- The table could be small, and DB2 decides a tablespace scan may be faster than index processing.



- The catalog statistics say the table is small, or maybe there are no statistics on the table.



- The predicates are such that DB2 thinks the query is going to retrieve a large enough amount of data that would require a tablespace scan.



- The predicates are such that DB2 picks a non-clustered index, and the number of pages to retrieve is high enough based on total number of pages in the table to require a tablespace scan.



- The tablespace file or index files could physically be out of shape and need a REORG.



- The predicates in the query do not match any available indexes on the table





10) Only code the columns needed in the Select portion of the SQL statement.



Having extra columns can have an affect on:



- The optimizer choosing ‘Index Only’



- Expensiveness of any sorts



- Optimizer’s choice of join methods


SSH configuration in Solaris 8

Configuring OpenSSH on Solaris 8

Solaris 8 doesn’t come with the SSH and SFTP like features, to enable these we have to configure and install a third party package OpenSSH.

/dev/random and /dev/random built-in, but patches have been released to correct  this. The packages need to be on the system to use ssh properly are openssl,  openssh, zlib and libgcc .All the packages are freely available on www.sunfreeware.com.

Installation Steps:

Step 1:
a) Installing the random patches for Solaris 8 (creates /dev/random files) if doesn’t  installed.
Patches: 112438-03 for Solaris 8 sparc
112439-02 for Solaris 8 X86
We will get “PRNG is not seeded” error if you proceed without this patch

b) After installation take a reconfiguration boot to create new devices.
#reboot -- -r
Step 2:
Installing the packages Below mentioned packages are needed to be downloaded and installed as below:
openssh-5.2p1-sol8-sparc-local.gz
openssl-0.9.8k-sol8-sparc-local.gz
zlib-1.2.1-sol8-sparc-local.gz
libgcc-3.4.6-sol8-sparc-local.gz
Install the following packages –
a) #gunzip openssh-5.2p1-sol8-sparc-local.gz
b) #gunzip openssl-0.9.8k-sol8-sparc-local.gz
c) #gunzip zlib-1.2.1-sol8-sparc-local.gz
d) #gunzip libgcc-3.4.6-sol8-sparc-local.gz
e) #pkgadd -d openssl-0.9.8k-sol8-sparc-local
f) #pkgadd -d zlib-1.2.1-sol8-sparc-local
g) #pkgadd -d libgcc-3.4.6-sol8-sparch)
#pkgadd -d openssh-5.2p1-sol8-sparc-local
Once we have installed the above packages we will have files in various subdirectories of /usr/local. We should now find ssh in /usr/local/bin and sshd in /usr/local/sbin. Make sure we have /usr/local/bin and /usr/local/sbin in your PATH environment variable.

Step 3:
a) Setting up the sshd user and the /var/empty directory
This method is now the default in openssh.
#mkdir /var/empty
#chown root:sys /var/empty
#chmod 755 /var/empty
#groupadd sshd
#useradd -g sshd -c 'sshd privsep' -d /var/empty -s /bin/false sshd
/var/empty should not contain any files.

b) The /usr/local/etc /sshd_config file defaultly has the last line
Subsystem sftp /usr/libexec/sftp-server
This may need to be changed to
Subsystem sftp /usr/local/libexec/sftp-server

Step 4: Installing ssh and sshd
a) Each machine that you want to communicate with via the ssh client will need to have an sshd daemon running. But first, we need to run the following three lines to create the key information for the server machine. Again, make sure you  have /usr/local/bin and /usr/local/sbin in the PATH.
If we have been running sshd before and have keys in /usr/local/etc, running these commands will overwrite them. As root, enter
# ssh-keygen -t rsa1 -f /usr/local/etc/ssh_host_key -N ""
# ssh-keygen -t dsa -f /usr/local/etc/ssh_host_dsa_key -N ""
# ssh-keygen -t rsa -f /usr/local/etc/ssh_host_rsa_key -N ""
and wait until each is done - this may take a few minutes depending on the speed of your machine.
c) Now we can set up scripts to start the sshd daemon

# cd /etc/init.d
Script---
# cd /etc/init.d
# vi sshd
#!/bin/sh
pid=`/usr/bin/ps -e | /usr/bin/grep sshd | /usr/bin/sed -e 's/^ *//' -e 's/ .*//'`
case $1 in
'start')
/usr/local/sbin/sshd
echo "sshd demon started"
;;
'stop')
if [ "${pid}" != "" ]
then
/usr/bin/kill ${pid}
fi
;;
*)
echo "usage: /etc/init.d/sshd {start|stop}"
;;
esac
# chown root /etc/init.d/sshd
# chgrp sys /etc/init.d/sshd
# chmod 555 /etc/init.d/sshd
# ln -s /etc/init.d/sshd /etc/rc2.d/S98sshd
# /etc/rc2.d/S98sshd start will start the process
# /etc/rc2.d/S98sshd stop will stop the sshd daemon.
# ps -e | grep sshd to see if sshd is running.



References




SSH configuration in Solaris 8

Configuring OpenSSH on Solaris 8

Solaris 8 doesn’t come with the SSH and SFTP like features, to enable these we have to configure and install a third party package OpenSSH.

/dev/random and /dev/random built-in, but patches have been released to correct  this. The packages need to be on the system to use ssh properly are openssl,  openssh, zlib and libgcc .All the packages are freely available on www.sunfreeware.com.

Installation Steps:

Step 1:
a) Installing the random patches for Solaris 8 (creates /dev/random files) if doesn’t  installed.
Patches: 112438-03 for Solaris 8 sparc
112439-02 for Solaris 8 X86
We will get “PRNG is not seeded” error if you proceed without this patch

b) After installation take a reconfiguration boot to create new devices.
#reboot -- -r
Step 2:
Installing the packages Below mentioned packages are needed to be downloaded and installed as below:
openssh-5.2p1-sol8-sparc-local.gz
openssl-0.9.8k-sol8-sparc-local.gz
zlib-1.2.1-sol8-sparc-local.gz
libgcc-3.4.6-sol8-sparc-local.gz
Install the following packages –
a) #gunzip openssh-5.2p1-sol8-sparc-local.gz
b) #gunzip openssl-0.9.8k-sol8-sparc-local.gz
c) #gunzip zlib-1.2.1-sol8-sparc-local.gz
d) #gunzip libgcc-3.4.6-sol8-sparc-local.gz
e) #pkgadd -d openssl-0.9.8k-sol8-sparc-local
f) #pkgadd -d zlib-1.2.1-sol8-sparc-local
g) #pkgadd -d libgcc-3.4.6-sol8-sparch)
#pkgadd -d openssh-5.2p1-sol8-sparc-local
Once we have installed the above packages we will have files in various subdirectories of /usr/local. We should now find ssh in /usr/local/bin and sshd in /usr/local/sbin. Make sure we have /usr/local/bin and /usr/local/sbin in your PATH environment variable.

Step 3:
a) Setting up the sshd user and the /var/empty directory
This method is now the default in openssh.
#mkdir /var/empty
#chown root:sys /var/empty
#chmod 755 /var/empty
#groupadd sshd
#useradd -g sshd -c 'sshd privsep' -d /var/empty -s /bin/false sshd
/var/empty should not contain any files.

b) The /usr/local/etc /sshd_config file defaultly has the last line
Subsystem sftp /usr/libexec/sftp-server
This may need to be changed to
Subsystem sftp /usr/local/libexec/sftp-server

Step 4: Installing ssh and sshd
a) Each machine that you want to communicate with via the ssh client will need to have an sshd daemon running. But first, we need to run the following three lines to create the key information for the server machine. Again, make sure you  have /usr/local/bin and /usr/local/sbin in the PATH.
If we have been running sshd before and have keys in /usr/local/etc, running these commands will overwrite them. As root, enter
# ssh-keygen -t rsa1 -f /usr/local/etc/ssh_host_key -N ""
# ssh-keygen -t dsa -f /usr/local/etc/ssh_host_dsa_key -N ""
# ssh-keygen -t rsa -f /usr/local/etc/ssh_host_rsa_key -N ""
and wait until each is done - this may take a few minutes depending on the speed of your machine.
c) Now we can set up scripts to start the sshd daemon

# cd /etc/init.d
Script---
# cd /etc/init.d
# vi sshd
#!/bin/sh
pid=`/usr/bin/ps -e | /usr/bin/grep sshd | /usr/bin/sed -e 's/^ *//' -e 's/ .*//'`
case $1 in
'start')
/usr/local/sbin/sshd
echo "sshd demon started"
;;
'stop')
if [ "${pid}" != "" ]
then
/usr/bin/kill ${pid}
fi
;;
*)
echo "usage: /etc/init.d/sshd {start|stop}"
;;
esac
# chown root /etc/init.d/sshd
# chgrp sys /etc/init.d/sshd
# chmod 555 /etc/init.d/sshd
# ln -s /etc/init.d/sshd /etc/rc2.d/S98sshd
# /etc/rc2.d/S98sshd start will start the process
# /etc/rc2.d/S98sshd stop will stop the sshd daemon.
# ps -e | grep sshd to see if sshd is running.



References




Nov 16, 2009

CSS Best Practices and Cross-browser Compatibility

This article is consolidation of the best practices which are followed or taken care during the development when a web page is styled using a external or inline style sheet referred to as CSS (Cascading Style Sheet). The best practices are arrived at after evaluating and analyzing the working web pages. Some of the concepts shared in this article are widely available on the internet but few are exclusively on the basis of experience and learning. Cascading style sheets are, in general terms, a collection of formatting rules that control the appearance, or presentation, of content on a web page. Implementing CSS within a page or site is done in one of three ways:

  • Inline: A one-time style applied within the code as an attribute of a given element (or tag).
  • Embedded: A style sheet declaration in the head of the document that will only effect that single page on the site.
  • External: A physical CSS file containing rules (styles) that is linked to from multiple pages within the site.

This article can be helpful or can act as a reference for any project which has web-based solutions.

Coding Practices

1. Use the correct – Doctype, Document Type Definition
Choosing a suitable Doctype for your site is the best thing you should do when it comes to writing (X)HTML code. This block of code helps the browser render properly the content of the site and it is also the first needed code for standards compliant (X)HTML documents. As a personal recommendation I think the best Doctype is XHTML 1 – Strict.

<!DOCTYPE html PUBLIC-//W3C//DTD XHTML 1.0 Strict//EN
http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd>


2. Make it Readable

The readability of your CSS is incredibly important, though most people overlook why it's important. Great readability of your CSS makes it much easier to maintain in the future, as you'll be able to find elements quicker. Also, you'll never know who might need to look at your code later on.



Group 1: All on one line

 



.someDiv { background: red; padding: 2em; border: 1px solid black; }


Group 2: Each style gets its own line



.someDiv {
background: red;
padding: 2em;
border: 1px solid black;
}


Both practices are perfectly acceptable, though you'll generally find that group two despises group one! Just remember - choose the method that looks best TO YOU. That's all that matters.



3. Keep it Consistent


Along the lines of keeping your code readable is making sure that the CSS is consistent. You should start to develop your own "sub-language" of CSS that allows you to quickly name things. There are certain classes that I create in nearly every theme, and I use the same name each time. For example, I use ".caption-right" to float images which contain a caption to the right.



Think about things like whether or not you'll use underscores or dashes in your ID's and class names, and in what cases you'll use them. When you start creating your own standards for CSS, you'll become much more proficient.



4. Use a Reset


Most CSS frameworks have a reset built-in, but if you're not going to use one then at least consider using a reset. Resets essentially eliminate browser inconsistencies such as heights, font sizes, margins, headings, etc. The reset allows your layout look consistent in all browsers.


The MeyerWeb (http://meyerweb.com/eric/tools/css/reset/index.html) is a popular reset, along with Yahoo's developer reset (http://developer.yahoo.com/yui/reset/) Or you could always roll your own reset if that tickles your fancy.




html, body, div, span,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
img, ins, kbd, q, s, samp,
small, strike, strong,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td {
margin: 0;
padding: 0;
border: 0;
outline: 0;
font-size: 100%;
vertical-align: baseline;
background: transparent;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}


5. Organize the Stylesheet with a Top-down Structure


It always makes sense to lay your stylesheet out in a way that allows you to quickly find parts of your code. I recommend a top-down format that tackles styles as they appear in the source code. So, an example stylesheet might be ordered like this:




  • Generic classes (body, a, p, h1, etc.)


  • #header


  • #nav-menu


  • #main-content



Don't forget to comment each section!



/****** main content *********/
styles goes here...
/****** footer *********/
styles go here...


6. Combine Elements


Elements in a stylesheet sometimes share properties. Instead of re-writing previous code, why not just combine them? For example, your h1, h2, and h3 elements might all share the same font and color:




h1, h2, h3 {font-family: tahoma, color: #333}


We could add unique characteristics to each of these header styles if we wanted (ie. h1 {size: 2.1em}) later in the stylesheet.



7. Create Your HTML First


Many designers create their CSS at the same time they create the HTML. It seems logical to create both at the same time, but actually you'll save even more time if you create the entire HTML mockup first. The reasoning behind this method is that you know all the elements of your site layout, but you don't know what CSS you'll need with your design. Creating the HTML layout first allows you to visualize the entire page as a whole, and allows you to think of your CSS in a more holistic, top-down manner.




8. Use Multiple Classes

Sometimes it's beneficial to add multiple classes to an element. Let's say that you have a <div> "box" that you want to float right, and you've already got a class .right in your CSS that floats everything to the right. You can simply add an extra class in the declaration, like so:



<div class="box right"></div>


Be very careful when using ids and class-names like "left" and "right." How come? Let's imagine that, down the road, you decide that you'd rather see the box floated to the LEFT. In this case, you'd have to return to your HTML and change the class-name - all in order to adjust the presentation of the page.



This is not semantic. Remember - HTML is for markup and content. CSS is for presentation.



If you must return to your HTML to change the presentation (or styling) of the page, you're doing it wrong!



9. Use Shorthand


You can shrink your code considerably by using shorthand when crafting your CSS. For elements like padding, margin, font and some others, you can combine styles in one line. For example, a div might have these styles:




#crayon {
margin-left: 5px;
margin-right: 7px;
margin-top: 8px;
}


You could combine those styles in one line, like so:



#crayon {
margin: 8px 7px 0px 5px; // top, rightright, bottombottom, and left values, respectively.
}


10. Comment your CSS


Just like any other language, it's a great idea to comment your code in sections. To add a comment, simply add /* behind the comment, and */ to close it, like so:




/* Here's how you comment CSS */


11. Understand the Difference between Block vs. Inline Elements



Block elements are elements that naturally clear each line after they're declared, spanning the whole width of the available space. Inline elements take only as much space as they need, and don't force a new line after they're used.

Here are the lists of elements that are either inline or block:




span, a, strong, em, img, br, input, abbr, acronym


And the block elements:



div, h1...h6, p, ul, li, table, blockquote, pre, form


12. Don’t use too many id’s and classes


In the past, I used for most of my tags id’s and classes. That was wrong. Instead of a crowded code you can choose to use CSS selectors in order to identify and stylize content. This is another measure in keeping your code clean.



13. Check for Closed Elements First When Debugging

If you're noticing that your design looks a distorted, there's a good chance it's because you've left off a closing </div>. You can use the XHTML validator (http://validator.w3.org/)to help sniff out all sorts of errors too.



14. Never Use Inline Styles


When you're hard at work on your markup, sometimes it can be tempting to take the easy route and sneak in a bit of styling. <p style="color: red;"> I'm going to make this text red so that it really stands out and makes people take notice! </p>


Sure -- it looks harmless enough. However, this points to an error in your coding practices.



When creating your markup, don't even think about the styling yet. You only begin adding styles once the page has been completely coded. Instead, finish your markup, and then reference that P tag from your external stylesheet.



Better we use like below



#someElement > p {
color: red;
}


15. Place all External CSS Files within the Head Tag


Technically, you can place stylesheets anywhere you like. However, the HTML specification recommends that they be placed within the document HEAD tag. The primary benefit is that your pages will seemingly load faster.



16. Learn How to Target IE

You'll undoubtedly find yourself screaming at IE during some point or another. It's actually become a bonding experience for the community. The first step, once you've completed your primary CSS file, is to create a unique "ie.css" file. You can then reference it only for IE by using the following code.




<!--[if lt IE 7]>
<link rel="stylesheet" type="text/css" media="screen" href="path/to/ie.css"
/>
<![endif]-->


This code says, "If the user's browser is Internet Explorer 6 or lower, import this stylesheet. Otherwise, do nothing." If you need to compensate for IE7 as well, simply replace "lt" with "lte" (less than or equal to).



17. Style ALL Elements

This best practice is especially true when designing for clients. Just because you haven't use a blockquote doesn't mean that the client won't. Never use ordered lists? That doesn't mean he won't! Do yourself a service and create a special page specifically to show off the styling of every element:



ul, ol, p, h1-h6, blockquotes, etc.


18. Alphabetize your Properties

While this is more of a frivolous tip, it can come in handy for quick scanning.



#cotton-candy {
color: #fff;
float: left;
font-weight: bold;
height: 200px;
margin: 0;
padding: 0;
width: 150px;
}


19. Make Use of Generic Classes


You'll find that there are certain styles that you're applying over and over. Instead of adding that particular style to each ID, you can create generic classes and add them to the IDs or other CSS classes.



For example, I find myself using float:right and float:left over an over in my designs. So I simply add the classes .left and .right to my stylesheet, and reference it in the elements.




.left {float:left}
.rightright {float:rightright}
<div id="coolbox" class="left">...</div>


This way you don't have to constantly add "float:left" to all the elements that need to be floated.



20. Use "Margin: 0 auto" to Center Layouts

Many beginners to CSS can't figure out why you can't simply use float: center to achieve that centered effect on block-level elements. If only it were that easy! Unfortunately, you'll need to use




  • margin: 0 auto; // top, bottombottom - and left, rightright values, respectively.

    to center divs, paragraphs or other elements in your layout. 



By declaring that both the left AND the right margins of an element must be identical, the have no choice but to center the element within its containing element.



21. Don't Just Wrap a DIV Around It

When starting out, there's a temptation to wrap a div with an ID or class around an element and create a style for it.



<div class="header-text"><h1>Header Text</h1></div>


Sometimes it might seem easier to just create unique element styles like the above example, but you'll start to clutter your stylesheet. This would have worked just fine:



<h1>Header Text</h1>


Then you can easily add a style to the h1 instead of a parent div.



22. Hack Less

Avoid using as little browser-specific hacks if at all possible. There is a tremendous pressure to make sure that designs look consistent across all browsers, but using hacks only makes your designs harder to maintain in the future. Plus, using a reset file can eliminate nearly all of the rendering irregularities between browsers.



23. Use Absolute Positioning Sparingly

Absolute positioning (http://www.w3schools.com/Css/pr_class_position.asp) is a handy aspect of CSS that allows you to define where exactly an element should be positioned on a page to the exact pixel. However, because of absolute positioning disregard for other elements on the page, the layouts can get quite hairy if there are multiple absolutely positioned elements running around the layout.



24. Use Text-transform

Text-transform is a highly-useful CSS property that allows you to "standardize" how text is formatted on your site. For example, say you're wanting to create some headers that only have lowercase letters. Just add the text-transform property to the header style like so:




text-transform: lowercase;


Now all of the letters in the header will be lowercase by default. Text-transform allows you to modify your text (first letter capitalized, all letters capitalized, or all lowercase) with a simple property.



25. Don't use Negative Margins to Hide Your h1


Oftentimes people will use an image for their header text, and then either use display:none or a negative margin to float the h1 off the page. Google might think it's spam.



26. Ems vs. Pixels

There's always been a strong debate as to whether it's better to use pixels (px) or ems (em) when defining font sizes. Pixels are a more static way to define font sizes, and ems are more scalable with different browser sizes and mobile devices. With the advent of many different types of web browsing (laptop, mobile, etc.), ems are increasingly becoming the default for font size measurements as they allow the greatest form of flexibility. About.com also has a great article on the differences between the measurement sizes (http://webdesign.about.com/cs/typemeasurements/a/aa042803a.htm).



27. Don't Underestimate the List

Lists are a great way to present data in a structured format that's easy to modify the style. Thanks to the display property, you don't have to just use the list as a text attribute. Lists are also great for creating navigation menus and things of the sort.


Many beginners use divs to make each element in the list because they don't understand how to properly utilize them. It's well worth the effort to use brush up on learning list elements to structure data in the future.



28. Avoid Extra Selectors



It's easy to unknowingly add extra selectors to our CSS that clutters the stylesheet. One common example of adding extra selectors is with lists. 



body #container .someclass ul li {....}


In this instance, just the .someclass li would have worked just fine.



.someclass li {...}


Adding extra selectors won't bring Armageddon or anything of the sort, but they do keep your CSS from being as simple and clean as possible.



29. Add Margins and Padding to All


Different browsers render elements differently. IE renders certain elements differently than Firefox. IE 6 renders elements differently than IE 7 and IE 8. While the browsers are starting to adhere more closely to W3C standards, they're still not perfect (*cough IE cough*).



One of the main differences between versions of browsers is how padding and margins are rendered. If you're not already using a reset, you might want to define the margin and padding for all elements on the page, to be on the safe side. You can do this quickly with a global reset, like so:



* {margin:0;padding:0;}


Now all elements have a padding and margin of 0, unless defined by another style in the stylesheet. The problem is that, because EVERYTHING is zeroed out with this method, you'll potentially cause yourself more harm than help. Are you sure that you

want every single element's margins and padding zeroed? If so - that's perfectly acceptable. But at least consider it.



30. Line 'em Up!

Generally speaking, you should strive to line up your elements as best as possible. Take a look at you favorite designs. Did you notice how each heading, icon,  paragraph, and logo lines up with something else on the page? Not doing this is one of the biggest signs of a beginner.



31. Use Multiple Stylesheets



Depending on the complexity of the design and the size of the site, it's sometimes easier to make smaller, multiple stylesheets instead of one giant stylesheet. Aside from it being easier for the designer to manage, multiple stylesheets allow you to leave out CSS on certain pages that don't need them. For example, I might having a polling program that would have a unique set of styles. Instead of including the poll styles to the main stylesheet, I could just create a poll.css and the stylesheet only to the pages that show the poll. <editors-note> However, be sure to consider the number of HTTP requests that are being made. Many designers prefer to develop with multiple stylesheets, and then combine them into one file. This reduces the number of HTTP requests to one. Also, the entire file will be cached on the user's computer.



32. Validate your HTML and CSS


Validating your CSS and XHTML does more than give a sense of pride: it helps you quickly spot errors in your code. If you're working on a design and for some reason things just aren't looking right, try running the markup and CSS validator and see what errors pop up. Usually you'll find that you forgot to  close a div somewhere, or a missed semi-colon in a CSS property.



33. Test in multiple browsers

Test in multiple browsers as you go. Generally, you'll find that non-IE browsers behave similarly and IE is a special case - especially if you follow the advice above. When necessary, you can add IE hacks in a separate stylesheet and only load it for IE users.



Quirksmode.com (http://www.quirksmode.org/) is a good place for hunting down random browser differences.



Browsershots.org (http://browsershots.org/) can help show how your page will be displayed in an assortment of browsers and operating systems.



Cross-browser compatibility



Browsers parse code differently. Internet viewers use a variety of browsers. It is a  good idea to design your website so the vast majority of viewers can get the full  benefit of your site.



The best website designs are compatible with the most popular browsers, thus being cross browser compatible. Standard coding practices and cross-browser compatibility goes hand in hand.



Code the web page in the latest version of the browser and then use separate style sheet for the browsers which are creating challenges.



Test, test, test in browsers. I would recommend having at least three browsers downloaded onto your computer: Internet Explorer, Firefox and Opera/Safari. The browsers listed cost nothing to download.



The more testing you do of your site while it is being constructed, the more sure you  can be of its appearance to your audience. Frequent testing also reveals problems early in the design process, making them easier to pinpoint.



Browser Compatibility Check for Internet Explorer Versions from 5.5 to 8  (http://www.mydebugbar.com/wiki/IETester/HomePage)



IETester is a free WebBrowser that allows you to have the rendering and JavaScript engines of IE8, IE7 IE 6 and IE5.5 on Windows 7, Vista and XP, as well as the installed  IE in the same process. http://browsershots.org/ (http://browsershots.org/)


Check Browser Compatibility, Cross Platform Browser Test - Browsershots



More info :





Links to useful add-ons






Web Developer (https://addons.mozilla.org/en-US/firefox/addon/60): A straight-forward add-on that gives you some extra menu selections for using and disabling different cascading style sheets so you can test them out.



HttpFox (https://addons.mozilla.org/en-US/firefox/addon/6647): HttpFox monitors all incoming and outgoing HTTP traffic between the browser and servers. Reports include request and response headers, sent and received cookies, querystring parameters, POST parameters and response body.



HTML Validator (https://addons.mozilla.org/en-US/firefox/addon/249): Just as the name of this addon implies, HTML Validator is all about making sure that your code is up to par. You can also check pages that you are visiting, and thanks to a little indicator in the corner of your browser, you’ll quickly see if the page is in compliance or has errors. Once you click on the indicator you will see a full version of the code that will identify what the problems are.



Firebug (https://addons.mozilla.org/en-US/firefox/addon/1843): Probably the most essential tool for any developer using Firefox. Firebug will allow you to monitor the activities of a page you are visiting, write new code, debug what you’ve already worked on and a whole lot more.



YSlow (https://addons.mozilla.org/en-US/firefox/addon/5369): YSlow is a Firefox add-on that integrates with the popular Firebug tool for Firefox. YSlow applies three predefined rulesets or a user-defined ruleset to test the performance of a page. Then, it suggests things you could do to improve it.



IE Tab (https://addons.mozilla.org/en-US/firefox/addon/1419): This is a great tool for web developers, since you can easily see how your web page displayed in IE with just one click and then switch back to Firefox.



Internet Explorer Developer Toolbar

(http://www.microsoft.com/downloads/details.aspx?familyid=e59c3964-672d-4511-bb3e-2d5e1db91038&displaylang=en) IE Developer Toolbar is the IE add-on that provides me the features I like in my Firefox extensions.



These guidelines can help you grow as a coder and also will give a professional feeling to your Stylesheets. Although the standards are not yet fully supported by all  browsers in all circumstances, creating standards-compatible pages is the best way to ensure good rendering. As always, learning to use new technologies will take some time and will give you some incompatibility headaches. Nonetheless the results will be well worth the investment.


Text Widget

Copyright © Vinay's Blog | Powered by Blogger

Design by | Blogger Theme by