Monday, February 25, 2013

Java :: String ValueOf Vs String Concatenation

String ValueOf Vs String Concatenation

From stack over flow I found bellow answer, as conclusion:
"Never use (+ "") to convert values to string, instead use String.valueOf."




public void foo(){
int intVar = 5;
String strVar = intVar+"";    
}
This approach uses StringBuilder to create resultant String
public void foo();
  Code:
   0:   iconst_5
   1:   istore_1
   2:   new     #2; //class java/lang/StringBuilder
   5:   dup
   6:   invokespecial   #3; //Method java/lang/StringBuilder."<init>":()V
   9:   iload_1
   10:  invokevirtual   #4; //Method java/lang/StringBuilder.append:(I)Ljava/lan
g/StringBuilder;
   13:  ldc     #5; //String
   15:  invokevirtual   #6; //Method java/lang/StringBuilder.append:(Ljava/lang/
String;)Ljava/lang/StringBuilder;
   18:  invokevirtual   #7; //Method java/lang/StringBuilder.toString:()Ljava/la
ng/String;
   21:  astore_2
   22:  return

public void bar(){
int intVar = 5;
String strVar = String.valueOf(intVar);
}
This approach invokes simply a static method of String to get the String version of int
public void bar();
  Code:
   0:   iconst_5
   1:   istore_1
   2:   iload_1
   3:   invokestatic    #8; //Method java/lang/String.valueOf:(I)Ljava/lang/Stri
ng;
   6:   astore_2
   7:   return

Saturday, February 23, 2013

Java :: How to override equals

How to override equals

All what you need to do is add the following piece if code in your object:


@Override
public boolean equals(Object obj) {
if (obj == null)
return false;
if (obj == this)
return true;
if (obj.getClass() != getClass())
return false;
YourObject rhs = (YourObject ) obj;
if (!rhs.getId().equals(getId())) // For Example
return false;
return true;
}


Have a nice day.

Wednesday, February 13, 2013

Java :: Variable Initialization

Variables initialization Advantages (In / out Constructor)

You can initialize a variable using the following:

  • Inside a constructor:

public Class Test() {
public int var;
  public Test()
{
    var = 10;
  }
}

  • Outside a constructor
public Class Test() {
         public int var = 10;
}


Advantages
Inside Constructor
Outside Constructor
One initialization even if you have multiple constructors

X
Can add exception handling to the initialization
X

More Readable

X
Faster Class Load
-
-


No major difference between both, developer use what you want!!
There is another types as static block will talk about later.

Have a nice day

Tuesday, January 29, 2013

Development Tips :: Responsibilities for Senior Java Developer

Senior Java Developer Responsibilities

A senior Java developer is responsible for developing applications using the Java programming language. A developer in this position is also responsible for overseeing the execution of software development from the conceptual phase to the testing phase. Because this is a senior level position, he may also be responsible for mentoring junior developers as well as working with customers and handling research groups.

Read more: Senior Java Developer Job Description | eHow.com http://www.ehow.com/about_6601671_senior-java-developer-job-description.html#ixzz2JLvCcnbV


I don't think there is an agreement over the job description for the Senior Developer, you can see that a company in Toronto asks for the following:

  • At least 10 year experience in high availability software and system implementation based on J2EE architecture and design patterns
  • Must have experience with asynchronous communications and networks protocols and concepts
  • Oracle 9i or 10g
  • Ant Scripting or Maven
  • Experience with PKI and Security concepts
  • Excellent communication skills
  • Team player and willing to mentor junior developers
  • Process oriented
  • Worked previously in structured environment where process has been followed and respected.

While in New York they asks for the following:

  • - 5+ years experience in J2EE Development 
  • - 3+ years designing UI and J2EE applications
  • - Understanding of standard J2EE UI patterns
  • - Must be able to work off hours when necessary to support production jobs or resolve production issues
While in Sofia,Bulgaria:
  • Software developer with more than 3 years commercial experience
  • Deep knowledge in JAVA technology and OOP principles
  • Understanding and experience with basic design patterns and reusable software design approaches
  • Experience with SWT
  • Excellent communication skills and fluent in English
  • GUI design skills in an IDE context
While in India:
  • Education: (UG –B.Tech/B.E Any Graduate - Any Specialization) AND (PG –Post Graduation Not Required). 
  • Experience: 3-6 years
While in Sydney:
  • 8+ years of overall experience. 
  • Experience with XML, XSLT XPath, and XQuery. 
  • Experience with Spring and Hibernate or IBatis as ORM.
  • Understanding of EDI. 
  • Abilities to drive complex technical design across system domain boundaries. 
  • Experience developing and architecting object-orientated applications using one or more of the following programming languages: J2EE, Spring WebLogic/WebSphere, Application server, Oracle (SQL-PL/SQL). 
  • Demonstrated proficiency in designing distributed applications in which multiple operating systems, languages, and vendor middleware interoperate.
I think that years of experience can't reflect the real experience of the person, yes off course the senior developer should have a years of work experience to say he is a senior but I think 1 year of experience for a developer is better than 3 years for another.

Adding special technologies like knowing Hibernate for example as a condition for recruitment is nonsense from my opinion, as a developer i think i could develop any kind of technology if I have the concept with experience in other related technologies.

Have a nice day.

Monday, January 28, 2013

Java :: String Builder VS String Buffer

String Builder VS String Buffer

StringBuffer is synchronized, StringBuilder is not, So off course string builder is faster.

And applying the following example using i7 processor and 8 GB ram:


public static void main(String args[]) {
long startTime = System.currentTimeMillis();
//StringBuffer concat = new StringBuffer();
StringBuilder concat = new StringBuilder();
for (int i = 0; i < 1000000; i++) {
concat.append(i);
}
long endTime = System.currentTimeMillis();
System.out.print("length: " + concat.length());
System.out.println(" time: " + (endTime - startTime));
}

will returns the following:

Using String Builder 47 Milliseconds.
Using String Buffer  57 Milliseconds.

Soooo, why to use the "String Buffer"??

as mentioned string buffer is synchronized, and that's means what???
It means that string buffer during appending will have to do a new task which is checking and making sure that only one instance is appending to the buffer at the same exact moment, so if you felt that your system will face that case -appending at the same time- you SHOULD use string buffer.

Have a blessed day :)

Sunday, January 27, 2013

Database Naming Convention



Oracle Schema Naming Standards

The following standards will be used in all schemas:
  • Schema objects - All non-table schema objects will be prefixed by their type and all index names will begin with idx, and all constraint names will begin with cons.
     
  • Referential Integrity conventions - All tables will have full RI, including PK constraints, FK constraints and check constraints. The default for foreign key constraints will be "On Delete Restrict", unless otherwise specified.  This means that no parent record can be deleted if there are corresponding child records.
     
  • Primary keys - Oracle Sequences will be used to generate unique row identifiers and all sequence numbers generally will start at one and increment by one.
     
  • Check Constraints - Lists of valid values will be used in all cases to restrict column values and validity

Oracle table naming Standards

To simplify development, we will follow these rules that allow the developer to quickly identify each metadata object, with complete descriptive names:
  • Table Standards
     
    • All table names will be plural (e.g. users vs. user).
    • Full table names will be used whenever possible.
    • If a table name should exceed 30 characters, reduce the size of the table name in this order:
      • From the left of the table name, remove vowels from each word in the table name except for the first vowel of each word.
      •  If the table name is still greater than 30 characters, use standardized shorthand indicators. Record this standard for consistent use.
         

Oracle column naming Standards

  • Column Naming Standards
    • Column names should be spelled out whenever possible.
    • If a column name should exceed 30 characters, reduce the size of the column name in this order:
      • From the left of the column name, remove vowels from each word in the table name except for the first vowel of each word.
      •  If the column name is still greater than 30 characters, use standardized shorthand indicators. Record this standard for consistent use.

Oracle index naming Standards

  • Index Standards
    • Index names should follow this standard:
IDX_ttttt_nn
Where IDX = Index
tttt = Table name the index is built on
nn = Numeric value that makes each table index unique.
    • If an index name should exceed 30 characters, reduce the size of the index name in this order:
      • From the left of the index name, remove vowels from each word in the table name except for the first vowel of each word.
      •  If the index name is still greater than 30 characters, use standardized shorthand indicators. Record this standard for consistent use.

Oracle constraints naming Standards

  • Constraint Standards
    • Primary key constraints will follow this naming convention:
      • PK_nnnnn 
        Where nnnn = The table name that the index is built on.

         
      • UK_nnnnn_nnWhere nnnn = The table name that the index is built on.
                        nn =  A number that makes the constraint unique.

         
      • FK_pppp_cccc_nn
        Where pppp = The parent table name
                    cccc = The child parent table name
                        nn = A number that makes the constraint unique

         
Sample names might include:
  • tables names - persons, islands, dsm_iv_codes

     
  • table column names - first_name, dsm_iv_code_description

     
  • constraint names - pk_ehd_food_establishment, fk_ehd_food_establishment_01

     
  • index names - idx_ssd_dsm_01

Oracle application naming Standards

Application Prefixes - All table/index/column/constraint names will use standard prefixes.  Each application area will be identified with a three-character abbreviation, and this abbreviation will be used for the names of all tables, indexes and constraints.  We will not use system-generated constraint or index names.  For example, assume we have these two application areas:
  • General cross-area objects = GEN
  • Social Services Department = SSD
  • Health Services Department = HSD
Object names - To simplify development, we will follow these standards that allow the developer to quickly identify each metadata object, with complete descriptive names:
  • The application prefix will be used in all metadata entries, including tables, indexes, constraints and table columns.
     
  • The table name will be included in all index, constraint and table column names.
     
  • The type of constraint will be specified in all constraint names, using the abbreviations PK, FK and CHECK



References:

-http://www.dba-oracle.com/standards_schema_object_names.htm
-http://www.toadworld.com/Portals/0/stevenf/Naming%20Conventions%20and%20Coding%20Standards.pdf


Saturday, January 26, 2013

SQL :: Information Schema Views

You can select the structure of your schema (tables, columns, ...etc.) in most DBs

for example SQL using what is called Information Schema Views

SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE'
and oracle uses:
SELECT owner, table_name
  FROM dba_tables
or
SELECT owner, table_name
  FROM all_tables
or
SELECT table_name
  FROM user_tables
good luck :)