Page Count

Sunday, November 27, 2016

Regular Expression in java


1 [abc] a, b, or c (simple class)
2 [^abc] Any character except a, b, or c (negation)
3 [a-zA-Z] a through z or A through Z, inclusive (range)
4 [a-d[m-p]] a through d, or m through p: [a-dm-p] (union)
5 [a-z&&[def]] d, e, or f (intersection)
6 [a-z&&[^bc]] a through z, except for b and c: [ad-z] (subtraction)
7 [a-z&&[^m-p]] a through z, and not m through p: [a-lq-z](subtraction)

X?  X, once or not at all
X*  X, zero or more times
X+  X, one or more times
X{n}    X, exactly n times
X{n,}   X, at least n times
X{n,m}  X, at least n but not more than m times

Reluctant quantifiers
X?? X, once or not at all
X*? X, zero or more times
X+? X, one or more times
X{n}?   X, exactly n times
X{n,}?  X, at least n times
X{n,m}? X, at least n but not more than m times

Possessive quantifiers
X?+ X, once or not at all
X*+ X, zero or more times
X++ X, one or more times
X{n}+   X, exactly n times
X{n,}+  X, at least n times
X{n,m}+ X, at least n but not more than m times

Tuesday, October 18, 2016

Most Common mistakes in Java Coding.

1. Copy & Paste

Its one of the most powerful tool and technique in the typical programmer. But at the same time its too dangerous that you ought to forgot the code according to you requirements. So always be cautious about what piece of code you are copying. Read at least two to three times to avoid the tricky for fishy things while your unit testing.

2. Exception Catch Block.

Always give priority to write some thing useful and meaning full statements in the exception catch block.It really worth when you troubling shooting the issues. Never leave this block with empty or sop's. And always throw the exception to the calling method.

3. String operations

Since String is immutable object, when you do any operation on string that results a new object. So after you do any modifications on String and do assign the string some object and use it.

4. Null pointers

Don't perform the operations on objects without checking the Object null condition. And while checking the null condition always provide 'null' key word as the first operand. e.g. if(null != object) . Especially while printing any calling any methods on an object.

5. Result Set next() operation.

Be in mindful that when ever you call resultset.next() operation cursor moves from one row to its next row.




CRON Expressions

 
CRON expression.
 
Cron-Expressions are used to configure instances of CronTrigger. Cron-Expressions are strings that are actually made up of seven sub-expressions, that describe individual details of the schedule. These sub-expression are separated with white-space, and represent:

  1. Seconds
  2. Minutes
  3. Hours
  4. Day-of-Month
  5. Month
  6. Day-of-Week
  7. Year (optional field)
 
 
 
+-------------------- second (0 - 59)
|  +----------------- minute (0 - 59)
|  |  +-------------- hour (0 - 23)
|  |  |  +----------- day of month (1 - 31)
|  |  |  |  +-------- month (1 - 12)
|  |  |  |  |  +----- day of week (0 - 6) (Sunday=0 or 7)
|  |  |  |  |  |  +-- year [optional]
|  |  |  |  |  |  |
*  *  *  *  *  *  * command to be executed 
 
 
Examples.
 
1. For every 10 seconds 
 
0/10 * * 1/1 * ? 
 
2. For every Sunday midnight at 23:00 
 
0 0 23 ? * SUN
 
Some of the frequently used schedules
 
 
You can play with http://www.cronmaker.com/ website for more number of combinations. 

Cron Expression Examples
Cron Expression Example
Creates Trigger that Fires at
0 0 12 * * ?
12 pm (noon) every day
0 15 10 ? * *
10:15 am every day
0 15 10 * * ?
10:15 am every day
0 15 10 * * ? *
10:15 am every day
0 15 10 * * ? 2005
10:15 am every day during the year 2005
0 * 14 * * ?
Every minute starting at 2 pm and ending at 2:59 pm, every day
0 0/5 14 * * ?
Every 5 minutes starting at 2 pm and ending at 2:55 pm, every day
0 0/5 14,18 * * ?
Every 5 minutes starting at 2 pm and ending at 2:55 pm, AND fires every 5 minutes starting at 6 pm and ending at 6:55 pm, every day
0 0-5 14 * * ?
Every minute starting at 2 pm and ending at 2:05 pm, every day
0 10,44 14 ? 3 WED
2:10 pm and at 2:44 pm every Wednesday in the month of March.
0 15 10 ? * MON-FRI
10:15 am every Monday, Tuesday, Wednesday, Thursday and Friday
0 15 10 15 * ?
10:15 am on the 15th day of every month
0 15 10 L * ?
10:15 am on the last day of every month
0 15 10 ? * 6L
10:15 am on the last Friday of every month
0 15 10 ? * 6L
10:15 am on the last Friday of every month
0 15 10 ? * 6L 2002-2005
10:15 am on every last friday of every month during the years 2002, 2003, 2004 and 2005
0 15 10 ? * 6#3
10:15 am on the third Friday of every month
0 0 12 1/5 * ?
12 pm (noon) every 5 days every month, starting on the first day of the month
0 11 11 11 11 ?
Every November 11th at 11:11 am.







































 
 
 
  
 
 
 
 
 

Wednesday, July 27, 2016

Programming Guide Lines

1. Modularization

Do not write the whole logic code in one block/function instead delegate the each and individual responsibility to each function. For example if you are converting one Date time format to another write this logic in Utils and use it. It might be useful in other place as well.

And if you come across any common piece which is repeated in you logic put it in a function call where ever needed. This is basic fundamental rule.

2.Single Responsibility.

Always delegate single responsibility to one block/function of code. Don't mess multiple operations in a single block/function. And make sure block/function of name should ideally match to what it actually does.

3. Name Justification

Always declare the class, method or variable names based on its purpose. And don't use any shorter names.
The one who reads your code should get idea what actually it does.

RESTful Service Java Implentaions


Jax RS API and its implementation Clarification

  1. The API does not provide any implementation code (concrete classes that do the actual processing). The API only specifies interfaces, annotations, exceptions. There can be concrete classes with some very basic, core behavior. The idea of standard APIs, like JAX-RS, is to give developers something to code against regardless of the underlying platform and implementation.
  2. Jersey, RestEasy and CXF are the implementations - it includes many concrete classes that actually handle the business promised by the API according to JSR  (Java Specification Request) 311. In JAX-RS case - it handles requests and responses.

Apache CXF - CXF is the implementation from Apache Group.

Jersey - the JAX-RS Reference Implementation from Sun.
We're using Jersey as its packed full of features (e.g. WADL, implicit views, XML/JSON/Atom support) has a large and vibrant developer community behind it and has great spring integration.
RESTEasy - JBoss's JAX-RS project. 
If you use JBoss/SEAM you might find REST easy integrates a better option.

Note: Since Jboss acquired by RedHat Linux, Jboss origination has re-named the open Source Jboss to Wildfly and started releasing the version of Jboss after 7.0. Now the current Wildfly (Jboss) version is  10. Check for more info at http://wildfly.org/downloads/

Now RedHat Jobss now called as Jboss EAP and enterprice version is now licensed.
 https://www.redhat.com/en/eap-calculator

Monday, June 20, 2016

Spring Boot Advantages

1. With Spring Boot you can focus more on business features and less on infrastructure.
2. With Spring Boot, project gets added with required libraries and configurations based on reasonable assumptions that Spring boot makes. Assumptions will be made based on the class path.
3. Spring Boot doesn’t generate code or make edits to your files. Instead, when you start up your application, Spring Boot dynamically wires up beans and settings and applies them to your application context. 

Spring Boot = Spring Framework + Embded HTTP Servers (Tomcat, Jetty etc..) - XM Configurations

For more information visit http://projects.spring.io/spring-boot/

JDK Vs JRE

JDK = JRE + Java Development tools
JRE = JVM + Java inbuilt packages + Run time libraries

Most of the people always has the doubt of why JDK is again having JRE inside ? Though it got provided out of the JDK.

Standard JRE doesn't have tools like javac, javaDB and tool.jar
So make sure you always point JDK JRE in your project build path.

Except the above difference rest of the things are same with Standard JRE's and JRE inside JDK.