Skip to main content

Posts

Different ways to use enum's in java

Technique:  Simple enum and retrieve/reverse lookup using valueOf() public class OrderService {     // Note : enums can be defined in its own file or inside a class if they are only relevant with it.     public enum Status { PROCESSING, SHIPPED, COMPLETED; }     public void update(long orderId, Status status) {          // something     } } // import static OrderService.Status; // import static OrderService.Status.* ; // OrderService service = new OrderService(); // service.update(100L, SHIPPED); // use enum // Status status = Status.valueOf("SHIPPED"); // reverse lookup by constant, throws IllegalArgumentException if no match. // System.out.println ( status.toString() ); // prints value - SHIPPED Technique:  Stores enum constant and value in a map, retrieve/reverse lookup using fromValue() public enum Status {         PROCESSING("processing"), SHIPPED("shippin...

guzra huwa jamana ata nahi dubara

guzra huwa jamana ata nahi dubara hafez khuda tumhara khushiya thi chaar din ki aason hai umr bhar ke  tanhahiyon me aksar royenge yaad karke wo waqt ke jo hum ne ek saath hai guzaara meri khasam hai mujko tum bewafa na kehna majboor thi mahabot sabh kuch pada hai sehna tuta hai zindegi ka ab aakhri sahara mere liye sahr bhi aayi hai raath bankar nikla mera janaza meri barath ban kar accha huwa jo tumne dekha na ye nazara guzra huwa jamana ata nahi dubara hafez khuda tumhara

ArrayList vs LinkedList vs HashSet Performance Comparision

Conclusions Inserting & Reading sequentially from Collection prefer LinkedList/ArrayList Inserting & Reading/Deleting by Search/equals from Collection prefer HashSet Inserting, ArrayList & LinkedList performs best while HashSet takes double the time Reading, HashSet performs best while ArrayList & LinkedList are marginally less Deleting, HashSet performs 10 times better than ArrayList & ArrayList performs 4 times better than LinkedList. LinkedList is slow because of sequencial search Bottom line : unless you are not going to iterate using for(Integer i : list ) then prefer HashSet Inserting/Reading/Deleting integer's from zero till count JDK7 Collection action count time ms ArrayList Insert 100 0/1 LinkedList Insert 100 0/1 HashSet Insert 100 0/1 ArrayList Insert 10000 5 LinkedList Insert 10000 4 HashSet Insert 10000 7 ArrayList Insert 100000 11 LinkedList Insert 100000 11 HashSet Insert 100000 21 ArrayList Get/Read 100 0 LinkedLis...

Password Security Recommendations

User credential / Password Security. Recent security related embarrassment at Yahoo, LinkedIn and Sony has only proved that securing user information needs more considerations. Security is not a product rather a process. First identifying how username/password can be leaked and its price. Basically there are four ways an adversary can find out username/password for one or more accounts stored on the server.  1. Password guessing - Assuming adversary knows username for one or more accounts and they can       deploy dictionary attack to find correct password.  2. Adversary eavesdropping on user network ( Man in Middle Attack)  3. Adversary getting access to user computer through some virus/worm  4. Adversary getting access to username/password table or system on the server. Password Guessing : Fix :   Max invalid attempts strategy should be deployed, i.e. temporary lock the account after 4 or 5 invalid...

Use project specific license in Netbeans + Maven

Use this in pom.xml and Netbeans is intelligent enough to inject appropriate license in all newly created files. <licenses>         <license>             <name>The Apache Software License, Version 2.0</name>             <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>             <distribution>repo</distribution>             <comments>A business-friendly OSS license</comments>         </license>     </licenses> And this is what it produces /*  * Copyright 2012 intesar.  *  * Licensed under the Apache License, Version 2.0 (the "License");  * you may not use this file except in compliance with the License.  * You may obtain a copy of the License at  *  *      http://w...

Forum/Questions feature request to Github & Google

Hey Github/Google why don't you add a forum/questions feature just like other "wiki" and "issues" features. Today there is no way project adopters can ask direct questions to the project community without creating an issue and this will not scale, simply because many non-contributors do not read issues and answer's them. So eventually we are keeping big knowledge base out of helping others adopt or solve problems. Lack of this feature simply discourages people asking questions fearing they are spamming the project with issues, and eventually they will end-up not using the product. And on the other hand if you add this feature it will simply create more value, increase user engagement, and addition of new knowledge base to your system. You might also argue that why we need to duplicate this feature when there are other good sites like StackOverFlow for doing this, but adding or integrating this feature to your products is more natural as users will find...