Saturday, September 1

Year 2038 Bug



Year 2038 Bug


Computer programs, softwares and systems that uses 32 bit integer to represent UNIX Time will fail after 19th, Jan, 2038 at 3:14:07.

What ?

Unix Time is another way of telling time, mostly for computer’s understanding. Each instances are defined as number of seconds elapsed after 1970-01-01 00:00:00.

Eg: UNIX Time for 31st Aug 2012 18:59:09 = 1346439549


On 19th, Jan, 2038 at 3:14:07, the 32 bit signed integer will reach its limit. After that, bit will overflow the 32-bit counter and reset the time to 1st Jan, 1901.

2038 bug


Attention to Mysql Users


Mysql 5 is a 32 bit database, it has a function UNIX_TIMESTAMP() which returns seconds since 1970-01-01 00:00:00. This function will return only 0 after 19th Jan, 2038 03:14:07 GMT.


The end time would be different for each region based on their time zone.

Auckland +12:00 19-01-2038 15:14:07
Sydney +10:00 19-01-2038 13:14:07
Tokyo +9:00 19-01-2038 12:14:07
Beijing +8:00 19-01-2038 11:14:07
Mumbai +5:30 19-01-2038 08:44:07
Dubai +4:00 19-01-2038 07:14:07
Nairobi +3:00 19-01-2038 06:14:07
Cairo +2:00 19-01-2038 05:14:07
Paris +1:00 19-01-2038 04:14:07
London UTC 19-01-2038 03:14:07
Brasilia -3:00 19-01-2038 00:14:07
Atlantic Time -4:00 18-01-2038 23:14:07
Eastern Time -5:00 18-01-2038 22:14:07
Central Time -6:00 18-01-2038 21:14:07
Mountain Time -7:00 18-01-2038 20:14:07
Pacific Time -8:00 18-01-2038 19:14:07
Hawai -10:00 18-01-2038 17:14:07

References:

1. http://en.wikipedia.org/wiki/Year_2038_problem
2. http://dev.mysql.com/doc/refman/4.1/en/date-and-time-functions.html#function_unix-timestamp

Friday, July 27

Google search Tips



 1.      filetype:  For searching for a specific file type only.

E.g.:  Search for ppt files           
           
computer networks filetype:ppt


2.      cache:  This is to load sites quickly.

E.g.:
           
cache:http://www.thehindu.com


3.      movie:  It shows all information regarding the movie.

E.g.:
           
movie:Dark Knight


4.      site:  To search within a site domain

E.g.:
           
entrance result site:gov.in


5.      phonebook:  To get details of a person using phone number

E.g.:
           
phonebook:28576300


6.      “ ”    For searching for an exact phrase

E.g.:
           
how to change tyre


7.        -   To exclude a particular word in the search

E.g.:  To exclude all search relating to cricket match

cricket -game -score

Thursday, July 5

Fix Memory Leak in Java


Fix Memory Leak in Java

Actions to prevent memory leak:

  1. When a reference variable is no longer in use, assign null value to it.
  2. Close DataInputStreams and JDBC Connections.
  3. Shutdown the threads after completion.
  4. Restrict using static classes and methods.
  5. Put less data on Sessions.
  6. Invalidate Sessions.
  7. Set short duration for timeout of sessions.
  8. Avoid using String for concatenation instead use StringBuffer.

How do we know memory leak is happening?

Getting OutOfMemoryError (OOM) is a sign of possible memory leak. The other way is by checking the used JVM heap size. If the heap size is rising with time then clearly you have memory leak.

memory leak java heapdump graph


Debugging memory leak

  • In Tomcat, open Catalina.bat file, set CATALINA_OPTS with XX:+HeapDumpOnOutOfMemoryError
set CATALINA_OPTS=%CATALINA_OPTS% -XX:+HeapDumpOnOutOfMemoryError


  • Now a heap dump is written on the first Out Of Memory Error into %CATALINA_HOME%\bin as java_pid<pid>.hprof
memory leak java heapdump file


  • Or for On-demand, if you are using Java6, then use jmap.exe -dump:format=b,file=HeapDump.hprof  <pid>  
memory leak java jmap




Wednesday, June 27

How to Increase your Laptop Battery Life


Batteries live longer if treated in a gentle manner. The longevity is often a direct result of the environmental stresses applied.

Following are the steps to increase your notebook’s battery life:
  1. Do not ever let your Battery Power fall below 40%.
  2. Do not ever charge at or below 0o C.
  3. Always best to work with Power supply Plugged-in.
  4. Always best to give a 30 min break after 3 hour usage. Shutdown or hibernate the notebook and plug-off the Power supply.
  5. Make sure to leave your battery power between 50% - 40%, if you are not going to use the notebook for long time (like more than 6 hours)
notebook battery power should not decrease 40%


Why not to let Battery Power fall below 40% ?
Do not discharge lithium-ion too deeply. Instead, charge it frequently. Lithium-ion does not have memory problems like nickel-cadmium batteries. No deep discharges are needed for conditioning. Deep discharges will increase the temperature and reduce battery life. If Li-ion cells are discharged below a certain voltage a chemical reaction occurs that make them dangerous if recharged, which is why probably all such batteries in consumer goods now have an "electronic fuse" that permanently disables them if the voltage falls below a set level. The electronic fuse draws a small amount of current from the battery, which means that if a notebook battery is left for a long time without charging it, and with a low initial state of charge, the battery may be permanently destroyed.

Why not charge at or below 0o C ?
Do not charge lithium-ion at or below freezing temperature. Although accepting charge, an irreversible plating of metallic lithium will occur that compromises the safety of the pack.

Why is it best to work with Power supply Plugged-in ?
Plugged-in power supply takes control of the power requirements and stress is relieved from battery. Also less battery discharges occurs.

Why to give a 30 min break after 3 hour usage ?
A continuous usage gives more stress on the battery and raises the battery temperature and thereby reducing life. A frequent break can allow to battery to cool down to a nominal temperature and prevents increase of temperature to critical levels. Degradation of battery occurs faster at higher temperatures. Degradation in lithium-ion batteries is caused by an increased internal battery resistance due to cell oxidation. This decreases the efficiency of the battery, resulting in less net current available to be drawn from the battery.

Why need to keep battery power at 50%-40% before long time non usage of notebook?
When storing, lithium batteries degrade more while fully charged than if they are only 40% charged.



References
http://batteryuniversity.com/learn/article/the_high_power_lithium_ion/

Monday, June 4

How to set Google as default search engine in Internet Explorer

Microsoft has made it really difficult for people using ie8 or ie9 in setting Google as their default search engine.
Follow these simple steps:
  1. Open your Internet Explorer.
  2. Go to this link  http://www.iegallery.com/en-US/Addons/Details/813
  3. Click on "Add to Internet Explorer".
  4. Check the ''Make this my default search provider" option.
  5. Click on "Add" button.
Now Google is set as  default search engine.


Add Google Add-on to Internet Explorer




Make this my default search provider

+ UPDATE on 30-07-2012

Some have complained that they are still not able to see Google search Addon. 

Please access this link http://www.google.com/homepage/search/ and click on "Switch Now!" .

set google as default search



 For More Add-ons in IE, please refer to this link http://www.iegallery.com/Addons .

Monday, December 12

How to make your computer fast

Well it doesn’t matter that you use Pentium 4 (1.2GHz) Processor.

You still can make your system reasonably fast.


Please note:

This article is for Windows XP.

It’s best to perform in the stage order.

The more deeper you go more small sacrifices you make for the only goal “Performance”, “Performance” and  “Performance”.



Following are the stages below:























Stage 1 : Uninstall unwanted softwares

1.      Open Control Panel -> Add or Remove Programs  

2.      Remove software that are not being used, by clicking Remove buttons



3.       Follow the ‘Next’ button, until the software is successfully uninstalled.



Stage 2 : Free more space in C Drive

1.      Delete unwanted files, only the ones you created, in C drive.

2.      Move all the files, only the ones you created, to some other drives.

Note: Don’t touch any system files or Windows folder or Program Files folder

3.       Whenever installing a program next time onwards, keep the destination folder as d:\Program Files\



Stage 3 : Cleanup the Disk


1.      Right-click on C Drive -> Properties



 


  2.      Click on “Disk Cleanup” button, and then wait for some time till it scans the drive.
 
3.      Mark Tick in all the checkbox to safely delete all unnecessary files, and then click ‘Ok’ button.




 

 


Stage 4 : Increase Virtual Memory

1.      Right-click on ‘My Computer’ -> Properties

2.      Select ‘Advanced’ tab -> Click ‘Settings’ under Performance Section.




 

3.      In ‘Performance Options’ Wizard -> ‘Advanced’ tab
4.      In ‘Virtual Memory’ section -> click on ‘Change’ button.







5.      In ‘Virtual Memory’, select C: drive
6.      Select ‘Custom Size’
7.      Enter Initial size (MB): 2046
8.      Enter Maximum size (MB): 3000 or 4092
9.      Click on ‘Set’ button and then on ‘Ok’ button.



 




Stage 5 : Scan and Clean for Viruses

1.      Full scan your computer using the antivirus.
2.      Delete the entire virus found.


Stage 6 : Disk Defragmenter

1.      Right-click on ‘My Computer’ -> Manage




 


2.      In right menu ‘Computer Management(Local)’ -> ‘Storage’ -> ‘Disk Defragmenter’

3.      Select one drive by drive

4.      Click on the ‘Defragment’ button, it may take some time to defragment the drive.



 






Stage 7 : Remove all applications load at start-up (except the really needed ones)

1.      Start -> Run
2.      Type msconfig and then click ‘Ok’ button.


3.      In ‘System Configuration Utility’ -> ‘Startup’ tab
4.      Unmark the tick on the checkbox of the applications that you installed and don’t use as the system starts.

Reason: When your system starts, all the softwares are sharing the memory at the startup till shutdown, even though it’s not used. So its better remove the applications to load at startup to increase the boot-time and system speed.

5.       Click ‘Ok’ and then ‘Restart’ button




 





Stage 8 : Set your system for “Performance” mode rather appearance.


1.      Right-click on ‘My Computer’ -> Properties

2.      Select ‘Advanced’ tab -> Click ‘Settings’ under Performance Section.



 
 

3.      In ‘Performance Options’ Wizard -> ‘Visual Effects’ tab

4.      Select  “Adjust for best performance” option and then click ‘Ok’ button.

 



Stage 9 : Upgrade your RAM to  minimum 2GB or more.

1.      Upgrade your system physical memory to minimum 2 GB or more.
2.      Check the FSB speed and type of your RAM, it can be found out using a software ‘CPU-Z’.
3.      Download ‘CPU-Z’.
4.      Buy a RAM that matches your FSB and DDR version.


Sunday, October 23

Aspect Oriented Programming ( AOP )


Why is AOP required?
We use Object-Oriented Programming (OOP), Functional-Oriented Programming (FOP) models basically to solve Concerns.

- Concerns like reusability of code in case of FOP.
- Concerns like data access, data integrity, data stability in case of OOP.

Even though we use many techniques in OOP to group and encapsulate the concerns into separate, independent entities by providing abstractions. But some concerns still defy these forms of implementation, and are called crosscutting concerns because they "cut across" multiple abstractions in a program.

Example: Logging

Logging is a crosscutting concern, because a logging strategy necessarily affects every logged part of the system. Logging thereby crosscuts all logged classes and methods.


Now Logging aspect is scattered or tangled as code, making it harder to understand and maintain. It is scattered by virtue of the function being spread over a number of unrelated functions that might use it, possibly in entirely unrelated systems, different source languages, etc. 


To change logging means the effect will be cascading to all the classes where logging is implemented. It would be a huge task to modify the places where the logging is called.



Simple Banking Scenario Example – Transfer money to another account
 
void transfer(Account fromAcc, Account toAcc, int amount , Logger logger)
throws Exception 
{
  logger.info("transferring money...");
 
  if (fromAcc.getBalance() < amount) 
  {
    logger.info("Insufficient Funds, sorry");
    throw new InsufficientFundsException();
  }
  fromAcc.withdraw(amount);
  toAcc.deposit(amount);
  logger.info("Successful transaction.");
 
}



Now consider what happens if we suddenly need to change the logging considerations for the application. In the program's current version, logging-related operations appear scattered across numerous methods, and such a change would require a major effort.



AOP’s Rescue Solution

AOP attempts to solve this problem by defining rules :


  1. To find the places where you need to change the code, and
  2. To suggest what new requirements or functionality you need to add.

These rules are called Aspects.

So now a class or jar file is created, loaded or at runtime, the new functionality that you declared is automatically inserted. The extent of the new implementation is how you have defined the aspect rules.



Example:


In the above logging example, I need to add the time when the logging was created.


@Aspect
public class LoggingAspect {
    @Before("call(void Logger.info(String)) && within(*)")
    public void findtime() {
        Logger.out.print(new java.util.Date());
    }
}

So here we have set the :

1st rule is to find the function [Logger.info()] to be modified.

2nd rule is to specify within which all packages [within(*)] the implementation should be done.

3rd rule is to specify what new functionality is to be replaced with [findtime()].

4th rule is to specify whether the new functionality is to be inserted before or after the code [@Before]. 

Now create a following XML config file in META-INF folder on the classpath.



<aspects>

    <aspect name="LoggingAspect"/>

</aspects>


Benefits

Now after each class is loaded in the server, if it pass the aspect conditions then the new functionality will be automatically inserted.

We can create a central place to change the cross cutting concerns. A change in one place is affected in all code.

Deployment in production server is easy as it requires no modification of production code and no or less downtime.

Thursday, September 1

Beware of the Cheap Tricks of Branded Retail Stores



• Stores are trying everything they can think of to disguise the fact that you're going to pay more for clothes.

• Some are using less fabric and calling it the new look. Others are adding cheap stitching and advertising it as a redesign. Chances are you're not going to think it's worth paying several dollars more for the shirt just to have them.

• Retailers are raising prices on merchandise an average of 10 percent in an effort to offset their rising costs for materials and labor. But merchants are worried whether the customers will buy at price hikes. So, retailers are making inexpensive tweaks—additional stitching, fake button holes, torn edges, fancy tags—to justify price increases. These tweaks can add only pennies to $1 to the cost of a garment, but retailers can charge $10 more for them.

 "Stores are making consumers believe they're getting more for their money."

• Spencer Elmen, owner of Cupid's Lingerie, which operates five stores in Arkansas, said he is seeing more items in his store that are even skimpier than usual, from underwear to mini dresses. He says that's because designers are finding clever ways to conceal the fact that they're clothes have less fabric.

 "They're just being more creative with less fabric," Elmen said.

• Another retailer Abercrombie & Fitch is advertising "Redesigned 2012" Jean Collections in its stores and on its website, touting that the jeans are "softer, with the perfect amount of stretch.". They're also mostly priced between $78 and $88, about $10 more than last year.
• The Wall Street Strategies retail analyst, examined the jeans and believes they are "thinner" and of "cheaper quality." and says “That extra stretch, could simply mean the retailer is saving costs by using less denim”.

See How Politicians are trying to make Anti-Corruption Bill ineffective

The Movement  was on its way before but the sudden spark for the Cause came because of Congress led Government failed to take effective action against  Rs17,000 crore Common Wealth Games scam.

 A citizen's forum called 'India Against Corruption' Movement was started on November 14, 2010 to fight against this government inaction.

Govt drafted a Lokball Bill on 2010 and on seeing the Govt drafted Bill, Santosh Hegde and Prashant Bhushan understood that govt was not interested in making a effective Anti-Corruption Bill, so they formed another Bill, Citizens Bill, or  Indian Peoples Bill,or known to all as  Jan Lokpal Bill.

See the difference between Jan Lokpal Bill  and Draft Lokpal Bill (2010)

Jan Lokpal Bill Draft Lokpal Bill (2010)
Lokpal will have powers to initiate suo motu action or receive complaints of corruption from the general public. Lokpal will have no power to initiate suo motu action or receive complaints of corruption from the general public. It can only probe complaints forwarded by the Speaker of the Lok Sabha or the Chairman of the Rajya Sabha.
Lokpal will have the power to initiate prosecution of anyone found guilty. Lokpal will only be an Advisory Body with a role limited to forwarding reports to a "Competent Authority".
Lokpal will have police powers as well as the ability to register FIRs. Lokpal will have no police powers and no ability to register an FIR or proceed with criminal investigations.
Lokpal and the anti corruption wing of the CBI will be one independent body. The CBI and Lokpal will be unconnected.
Punishments will be a minimum of 10 years and a maximum of up to life imprisonment. Punishment for corruption will be a minimum of 6 months and a maximum of up to 7 years.


After that we all know what happened and how Anna Hazare went to first Fast & Agitation – Phase 1 on April 7th  for govt to accept the Jan Lokpal Bill.




Indeed after lot of protest we know how govt setup a new committee to draft the bill and Look below table to see  how govt came with their version of the new bill on August,2011 as proposed against Jan Lokpal bill.

Issue The Jan Lokpal Bill Government's Lokpal Bill
Prime Minister PM can be investigated with permission of seven member Lokpal bench PM can be investigated by Lokpal after she/he vacates office.
Judiciary Can be investigated, though high level members may be investigated only with permission of a seven member Lokpal bench. Judiciary is exempt and will be covered by a separate "judicial accountability bill".
Conduct of MPs Can be investigated with permission of seven member Lokpal bench. Can be investigated, but their conduct within Parliament, such as voting, cannot be investigated.
Lower bureaucracy All public servants would be included. Only senior officers (Group A) will be covered.
Anti-corruption wing of the Central Bureau of Investigation (CBI) The Anti-corruption wing of the CBI will be merged into the Lokpal. The Anti-corruption wing of the CBI not be merged into the Lokpal.
Removal of Lokpal members and Chair Any person can bring a complaint to the Supreme Court, who can then recommend removal of any member to the President. Any "aggrieved party" can raise a complaint to the President, who will refer the matter to the CJI.
Removal of Lokpal staff and officers Complaints against Lokpal staff will be handled by independent boards set-up in each state, composed of retired bureaucrats, judges, and civil society members. Lokpal will conduct inquiries into its own behaviour.
Lokayukta Lokayukta and other local/state anti-corruption agency would remain in place. All state anti-corruption agencies would be closed and responsibilities taken over by centralised Lokpal.
Whistleblower protection Whistleblowers is a person who tells the court about illegal activities done by the corrupt personnel.

Whistleblowers are protected by Lokpal.




No protection granted to whistleblowers by Lokpal Mahima.
Punishment for corruption Lokpal can either directly impose penalties, or refer the matter to the courts. Penalties can include removal from office, imprisonment, and recovery of assets from those who benefited from the corruption. Lokpal can only refer matters to the courts, not take any direct punitive actions. Penalties remain equivalent to those in current law.
Investigatory powers Lokpal can obtain wiretaps ( to make a connection to a telegraph or telephone wire in order to obtain information secretly), issue rogatory letters, and recruit investigating officers. Cannot issue contempt orders. Lokpal can issue contempt orders, and has the ability to punish those in contempt. No authority to obtain wiretaps, issue rogatory letters, or recruit investigating officers.
False, frivolous and vexatious complaints Lokpal can issue fines for frivolous complaints (including frivolous complaints against Lokpal itself), with a maximum penalty of Rs 100,000. Court system will handle matters of frivolous complaints. Courts can give 2–5 years imprisonment and fines of Rs 25,000 to 200,000.
NGOs NGOs not within the scope due to their role in exposing corruption. NGOs are within the scope and can be investigated.