Monday, December 16, 2013

Web Services :: Bottom Up vs Top Down Web Services

Bottom Up vs Top Down Web Services

Top-down means you start with a WSDL and then create all the necessary scaffolding in Java all the way down.
Bottom-up means you start with a Java method, and generate the WSDL from it.

Tuesday, July 23, 2013

Gen :: Solve When Virus Hit My Flash and Hide My Files

What to do When Virus Hit My Flash and Hide My Files?

Try the following steps:
1. Go to Start > Run > type cmd
2. Dos will open type cd\
3. Now type the drive letter in which you want to Unhide the files lets suppose in my case its E: this will open the E: drive
4. If you want to see all hidden files and folders   type E:\>dir/ah
5. Now type attrib *. -h -s /s /d
6. Now close cmd using exit command


then move all the files you need on the flash , format it to insure all viruses are cleaned.

Sunday, June 30, 2013

Java :: How To Override toString

How To Override toString
@Override public String toString()
{
return this.get(Field you want to return); // e.g: getName();
}

Why to use this kind override?
Sometimes we need to add for example a collection to a combo box so instead of looping
 over the object list you override the toString in that object to return one of the object variables

Sunday, June 9, 2013

Java :: HotSpot

Java HotSpot

The Java HotSpot Virtual Machine is a core component of the Java SE platform. It implements the Java Virtual Machine Specification, and is delivered as a shared library in the Java Runtime Environment. As the Java bytecode execution engine, it provides Java runtime facilities, such as thread and object synchronization, on a variety of operating systems and architectures. It includes dynamic compilers that adaptively compile Java bytecodes into optimized machine instructions and efficiently manages the Java heap using garbage collectors, optimized for both low pause time and throughput. It provides data and information to profiling, monitoring and debugging tools and applications.
HotSpot is an "ergonomic" JVM. Based upon the platform configuration, it will select a compiler, Java heap configuration, and garbage collector that produce good to excellent performance for most applications. Under special circumstances, however, specific tuning may be required to get the best possible performance. The resources collected here will help the reader understand and tune the Java HotSpot Virtual Machine.

The Java HotSpot Performance Engine Architecture

Wednesday, May 1, 2013

Java :: Why Java extends only one class?


Why Java extends only one class?
From SCJP 6 study guide:
"Some languages (like C++) allow a class to extend more than one other class.
This capability is known as "multiple inheritance." The reason that Java's
creators chose not to allow multiple inheritance is that it can become quite
messy. In a nutshell, the problem is that if a class extended two other classes,
and both superclasses had, say, a doStuff() method, which version of doStuff()
would the subclass inherit? This issue can lead to a scenario known as the
"Deadly Diamond of Death," because of the shape of the class diagram that
can be created in a multiple inheritance design. The diamond is formed when
classes B and C both extend A, and both B and C inherit a method from A. If
class D extends both B and C, and both B and C have overridden the method
in A, class D has, in theory, inherited two different implementations of the
same method. Drawn as a class diagram, the shape of the four classes looks
like a diamond."


Tuesday, April 30, 2013

SQL :: Convert Integer to String

Convert Integer to String
you can convert an integer to string using the following query:

select CAST(ID as varchar2(50)) as ID_STRING from TABLE_NAME.

Have a nice day.

Sunday, April 28, 2013

Java :: Quartz

Steps to use Quartz 

1- Download Quartz
From http://quartz-scheduler.org/downloads/catalog and after free registration.
Extract the archive file and copy quartz-2.1.7.jar (or the name of the downloaded version) to your project libraries.

2- Download slf4j
From http://www.slf4j.org/download.html copy slf4j-api-1.7.5.jar (or the name of the downloaded version) to your project libraries.

3- Create Main Class and Implement Job Interface
Use the bellow example:


public static void main(String[] args) {
SchedulerFactory sf = new StdSchedulerFactory();
Scheduler sched;
try {
sched = sf.getScheduler();
JobDetail job = JobBuilder.newJob(Main.class)
.withIdentity("SimpleJob").build();
Trigger trigger = TriggerBuilder
.newTrigger()
.withIdentity("SimpleJob")
.withSchedule(
SimpleScheduleBuilder.simpleSchedule()
.withIntervalInSeconds(5).repeatForever())
.build();
Scheduler scheduler = new StdSchedulerFactory().getScheduler();
scheduler.start();
scheduler.scheduleJob(job, trigger);

} catch (SchedulerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

or you can download the source from:
https://github.com/firask86/QuartzExample

The example demonstrate simple and cron schedule.




Thursday, April 18, 2013

Java :: Singleton Pattern

Definition
Singleton pattern is one of the most commonly used patterns, it is used to ensure that only one instance of an object is created, and as in the implementation example you can see that a check for a STATIC variable if not exists create one (and it will be only the first time off-course) then the same instance will be returned always.
Focus on that the main constructor for the class should be implemented as private to make sure that no one can create an object for your class using else than getInstance method

Implementation

 public class SingletonClass {
   private static SingletonClass instance;

   private SingletonClass() {}

   public static SingletonClass getInstance() {
    if(instance == null) {
     instance = new SingletonClass();
     return instance;
    } else {
      return instance;
   }
 }

Sunday, March 17, 2013

Java :: HashMap Vs HashTable



 HashMap Vs HashTable

There are several differences between HashMap and Hashtable in Java:
  1. Hashtable is synchronized, whereas HashMap is not. This makes HashMap better for non-threaded applications, as unsynchronized Objects typically perform better than synchronized ones.
  2. Hashtable does not allow null keys or values. HashMap allows one null key and any number of null values.
  3. One of HashMap's subclasses is LinkedHashMap, so in the event that you'd want predictable iteration order (which is insertion order by default), you could easily swap out the HashMap for a LinkedHashMap. This wouldn't be as easy if you were using Hashtable.
Since synchronization is not an issue for you, I'd recommend HashMap.
Reference: 
http://stackoverflow.com/questions/40471/differences-between-hashmap-and-hashtable

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