My top recomentations for new programmers

February 7th, 2010

Unsorted list:

  • If you use a versioning control system, spend some time learning its basic usage (checkout, checkin, update, diff, merge, …). If you don’t use it, go quickly to get one. Im currently using svn and git.
  • Write your own documentation. Document your work for your personal profit. While you are documenting and organizing you are thinking in your job by looking it from a different point of view. Think in documentation like in a software-piece, it must be useful and reusable.
  • Constantly, try to improve your knowledge about every day tools usage by knowing its internals (keyboard shorcuts or processes) or just learning from your colleages (or Internet users) usage.
  • Don’t be IDE-dependent for your compilation, use scripts or tools specifically designed for this task. Actually Maven will be my first choice because Java is my main plattform.
  • Get feedback about your code. Show them into colleagues or use communities like StackOverflow.
  • Don’t try to write your own framework or libraries for later use. Learn writing it, if you can but use well-known community libraries or frameworks. I personally work mainly with Spring Framework and Apache commons.
  • Backup your data. Use your own/preferred method. I personally like dropbox.
  • Most important. Don’t try to acomplish all of this at same time. Just be patient and :-)

Please, feedback :-)

Edu Best-Practices, Code, HowTo, Java, Tools , ,

Spring Annotations Inject properties / Anotaciones Spring Inyectar properties

December 4th, 2009

applicationContext.xml:

File parameters.properties / Fichero parameters.properties:

MyComponent.path=/some/path

Spring component / Componente gestionado por Spring:

import javax.annotation.PostConstruct;
import org.springframework.stereotype.Component;
 
@Component("MyComponent")
public class MyComponent {
 
    private String path;
 
    @PostConstruct
    public void loadPath() {
 
        System.out.println("Loading from " + this.path);
    }
 
    public String getPath() {
        return path;
    }
 
    public void setPath(String path) {
        this.path = path;
    }
}

Edu HowTo, Java, Spring , ,

Simple Javascript call from Java / Llamada simple a Javascript desde Java

December 4th, 2009

Simple call / Llamada simple:

1
2
3
4
5
6
7
8
9
10
11
try {
	ScriptEngineManager factory = new ScriptEngineManager();
	ScriptEngine engine = factory.getEngineByName("JavaScript");
 
	//Simple call to println javascript function 
	engine.eval("println('Texto JavaScript')");
 
} catch (ScriptException ex) {
 
	//Do something
}

Calling a function / Llamando a una función:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
try {
 
	ScriptEngineManager factory = new ScriptEngineManager();
	ScriptEngine engine = factory.getEngineByName("JavaScript");
	engine.eval("function amessagefunction(atext){ return 'The secret message is ' + atext;}");
	Invocable invocable = (Invocable) engine;
	Object object = invocable.invokeFunction("amessagefunction", "abc");
	System.out.println(object);
 
} catch (NoSuchMethodException ex) {
 
	//Do something
 
} catch (ScriptException ex) {
 
	//Something is wrong, perhaps
}

Edu Java, Javascript, Scripting , ,