Showing posts with label JAVA. Show all posts
Showing posts with label JAVA. Show all posts

Thursday, June 14, 2012

Maven archetype creation:

There 2 ways to crate archetype.
1. Manually
2. From project
From project is the most preferable way, cause saves your time.
http://maven.apache.org/guides/mini/guide-creating-archetypes.html

There is few steps you should do:
mvn archetype:create -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-quickstart -DgroupId=your-group-id -DartifactId=your-artifact-id -DpackageName=your.package -Dversion=1.0 
mvn org.apache.maven.plugins:maven-archetype-plugin:2.2:create-from-project 
mvn install 
mvn archetype:generate -DarchetypeCatalog=local
1. Create project and fill it
2. Generate archetype from the project which would be generated to target target\generated-sources\archetype
3. Install to archetype to repository
4. Use it

Monday, December 5, 2011

Jpa vs Hibernate

http://java.dzone.com/articles/jpa-performance-optimization

Tuesday, November 15, 2011

Eclipse class decompiler javap

Run->External Tools->External Tools Configuration
Location:
${system_path:javap}
Working directory:
${project_loc}
Arguments:
-classpath ${project_loc}\target\classes -c ${java_type_name}

Wednesday, October 26, 2011

CODE COVERAGE AND CONFIGURATION

http://www.javacodegeeks.com/2011/10/code-coverage-with-unit-integration.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+JavaCodeGeeks+%28Java+Code+Geeks%29&utm_content=Google+Reader

Thursday, August 4, 2011

Spring MVC

HiddenHttpMethodFilter - enable DELETE/PUT in the form

Friday, July 8, 2011

Java web services: performance comparison

http://www.ibm.com/developerworks/webservices/library/j-jws14/index.html?ca=drs-

Wednesday, June 22, 2011

Friday, June 10, 2011

MVC REST

Since spring v.3 provide REST WEBSERVICE features.
git@github.com:sirtoxy/mvcrest.git
Test and try yourself.

Wednesday, April 27, 2011

SOPA Styles

//DOCUMENT LITERAL WRAPPED
//DOCUMENT LITERAL BARE
//RPC ENCODED WRAPPED
//RPC LITERAL WRAPPED

Friday, March 11, 2011

SSL keystore

By default keystore is users directory (example: C:\Users\myname\.keystore)

%JAVA_HOME%\bin>keytool.exe -importcert -file PATH_TO_CERT.cer –v
keytool.exe –list
%JAVA_HOME%\bin>keytool.exe -printcert - file PATH_TO_CERT.cer

Friday, March 4, 2011

Constructor chain execution with overriding methods inside

Note that when the Base constructor is called from within the Sub constructor, "this" clearly refers to an instance of Sub, not Base. Even though "this" has not been completely constructed yet, the JVM knows what class it will ultimately be. This is how it's able call overriding methods from the constructor.

Wednesday, July 7, 2010

Java Closures

Java 7 is going to have lambda expression("closure"). Some people say it's simplification.
Other says no it's harm. Well anonymous classes was a replacement of closures and
as James Gossling says because of time pressure. But the Java culture of programming is formed and
exists a decade. Just try yourself the examples and ask youself:
Is it improve you code? Ask colleges do they understand your code?
Example 1

val SOME 6 =
withReturn
(fn return =>
(app (fn x =>
if 0 = x mod 2 then
return (SOME x)
else
print (Int.toString x))
[1, 3, 5, 6, 7, 9]
; NONE))

What's the result??? It's simple isn't it? 135

Example 2

new Functor(){public Object f(Object x){ ... }}
vs
(lambda (x) ...)
vs
new (){f(x){...}}


Example 3

textField.addActionListner( new ActionListener() {
public void actionPerformed( ActionEvent notUsed ) {
textArea.append( textField.getText() );
}
});
vs
textField.addActionListner( ActionListener()
( notUsed )
textArea.append( textField.getText() );
);

Result: As we see from examples we missing type declaration - so missing the idea
of Java as a language. Simplification of lines of code,lines...No the most for you you IDE
does no matter Eclipse, IntelJ or Netbeans. But if you are a vi or notepad geek just
think maybe it's better for you to write on perl or assembler?


Thursday, May 27, 2010

Modificator for @Autowire

Is it the same?
@Autowired
public indentifier name
@Autowired
private indentifier name

1. Speed issuer. With a private modificator reflection algorith adds only one additional call which is nano seconds time.
name.setAccessible(true);
2. But with a private modificator you don't break object encapsulation

Wednesday, December 23, 2009

SLF4J

SLF4J-simple can't be configured via log4j.properties. To configure it use slf4j-log4j12

org.slf4j
slf4j-log4j12
1.5.8

Tuesday, September 29, 2009

Date Formatter

Is the ParseException happens?

SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy");
Date date = null;
try {
//1
date = df.parse("12-34-2007");
} catch (ParseException e) {
System.out.println("Wrong date");
}
System.out.println(date.toString());

Actually not. To prevent this add to //1
df.setLenient(false);

Letient parameter is true by default that's why to match format strictly need
setting parameter to false

Tuesday, April 7, 2009

Java version number


import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;

public class ClassVersionChecker {
public static void main(String[] args) throws IOException {
for (int i = 0; i < args.length; i++)
checkClassVersion(args[i]);
}

private static void checkClassVersion(String filename) throws IOException {
DataInputStream in = new DataInputStream(new FileInputStream(filename));

int magic = in.readInt();
if (magic != 0xcafebabe) {
System.out.println(filename + " is not a valid class!");
}
int minor = in.readUnsignedShort();
int major = in.readUnsignedShort();
System.out.println(filename + ": " + major + " . " + minor);
in.close();
}
}


1.Compile

javac ClassVersionChecker.java

2.Execute in unix console

find . -name *.class|xargs java -cp /c/tmp ClassVersionChecker|grep 50

where last number is class version

major minor Java platform version
45 3 1.0
45 3 1.1
46 0 1.2
47 0 1.3
48 0 1.4
49 0 1.5
50 0 1.6