There isn’t a class that extends List for which you can set a limit on its size and that it behaves like a Queue object if you add an item beyond its fixed size. Continue reading “A List with a fixed size”
Starting a thread is very easy in java, after you create it you need to call the method start(), for example:
Thread myThread = new Thread(new MyRunnable());
where MyRunnable is a class implementing the Runnable interface overidden the method run().
Continue reading “Stopping the threads”
In this post I show some ways to copy arrays of primitive data and objects to another array.
Continue reading “Copying an array in java”
In this post I write an example about how to launch a fortran executable form a java program passing some arguments and getting back a result.
The chosen example uses code written in fortran to get primes, it is from Sieve of Eratosthenes.
Continue reading “Running a fortran program from java”
The inner classes, and then not static, can access even if with some limitation to the variables of the outer class.
Continue reading “Getting the variables of the outer class from an inner class”
In the post Executing code on the creation or destruction of a bean in Spring I explain three ways to execute code on the creation or destruction of a Bean in Spring.
With two of these ways you can set the execution of a specific custom method:
- with the annotations @PostConstruct and @PreDestroy
- configuring the properties init-method and destroy-method
There is a very convenient way in the case that more beans have methods with the same name to be executed on their creation and destruction, i.e. you can specify a default method for all the beans.
Continue reading “How to set a default method to running code on the creation or destruction of a bean”
From version 5 of Java you can call a method passing a variable number of arguments.
A variable of this type is called varargs, you can only use in a method signature and its syntax is the primitive type or object type followed by 3 dots (ellipsis). Continue reading “Varargs: passing a variable number of arguments to a method”
In this post I explain how to create only one object of a java class, then a single instance is available in the application.
An object of this type is called singleton and a starting class can be the following:
Continue reading “Creating a singleton in java”
The @Autowired annotation is used to configure the dependency injection in Spring and is associated with a setter method, or a field or a constructor of a class.
In the case of a setter method or a field the bean used for dependency injection is chosen depending on the type. Continue reading “@Autowired and @Resource in Spring”