Tag Archives: java

Kotlin vs Java. what should i pick for my new android project?

Unlike iOS, where Swift is overtaking Objective-C rapidly and the momentum is clear. In the Android world, presently, the language option is not that clear.

Yes, Kotlin is there, new, coming forward, garden-fresh, 21-century ready but it isn’t ultimately taking off, not as expected.

Kotlin was first introduced by JetBrains in 2011, which is the creator of IntelliJ IDEA, PyCharm, and many other top IDEs. It got its name from ‘Kotlin Island’ in St. Petersburg, Russia. Made to strike Java.

That said, the dominance of Java is still immense, the number of libraries, APIs, code generally speaking is humongous. Not to mention the readability of it, the many algorithms and things done or thought already in Java, yeah… Simple as it sounds, it’s hard to break a solid present for a “uncertain” bright future.

Continue reading Kotlin vs Java. what should i pick for my new android project?

Create executable files from Java .jar in Windows

JSmooth is a tool for wrapping Java JAR files into Windows Portable Executable EXE files. It allows specifying various details on how the program should be invoked, such as:

  • Executable icon
  • Program arguments
  • Type of wrapper application (console or Windows GUI)
  • Whether to launch the Java VM in the same process as the EXE or a separate process
  • Maximum and initial memory allocation
  • System properties available to the application via the System.getProperty function

JSmooth is distributed under the GNU General Public License, and is written in Java using Swing. Generated executables are built on MinGW, and as such there is no dependency on proprietary software.
Unlike other exe wrappers, JSmooth is 100%-Java, and can be used to create the Windows executable from a Linux compilation-chain (an ANT task is provided).

Download page:

http://sourceforge.net/projects/jsmooth/files/

 

In software, JAR (Java ARchive) is a package file format typically used to aggregate many Java class files and associated metadata and resources (text, images, etc.) into one file to distribute application software or libraries on the Java platform.

JAR files are fundamental archive files, built on the ZIP file format and have the .jar file extension. Computer users can create or extract JAR files using the jar command that comes with a JDK. They can also use zip tools to do so; however, the order of entries in the zip file headers is important when compressing, as the manifest often needs to be first. Inside a JAR, file names are unicode text.

To create .jar files with netbeans follow these steps:

1 Click on Properties
2 Click on Packaging
3 Click on Compress JAR File
4 Accept changes, click ok
5 Click the button in the ribbon tab with the hammer/broom. (clean and build project)
6 Go to the directory where your project is stored
7 Look in the dist folder for your .jar file

Javadocs

Javadoc es una utilidad de Oracle para la generación de documentación de APIs en formato HTML a partir de código fuente Java. Javadoc es el estándar de la industria para documentar clases de Java. La mayoría de los IDEs los generan automáticamente.


Javadoc también proporciona una API para crear doclets y taglets, que le permite analizar la estructura de una aplicación Java. Así es como JDiff puede generar informes de lo que ha cambiado entre dos versiones de una API.


Para generar APIs con Javadoc han de usarse etiquetas (tags) de HTML o ciertas palabras reservadas precedidas por el carácter “@”. Estas etiquetas se escriben al principio de cada clase, miembro o método, dependiendo de qué objeto se desee describir, mediante un comentario iniciado con “/**” y acabado con “*/”.


Netbeans ayuda en la generación de Javadocs de modo automático.


Las etiquetas en Javadocs son:

Tag Descripción
@author Nombre del desarrollador.
@deprecated Indica que el método o clase es antigua y que no se recomienda su uso porque posiblemente desaparecerá en versiones posteriores.
@param Definición de un parámetro de un método, es requerido para todos los parámetros del método.
@return Informa de lo que devuelve el método, no se puede usar en constructores o métodos “void”.
@see Asocia con otro método o clase.
@throws Excepción lanzada por el método
@version Versión del método o clase.



Un ejemplo de un Javadoc de un método:

/**
  * Inserta un título en la clase descripción.
  * Al ser el título obligatorio, si es nulo o vacío se lanzará
  * una excepción.
  *
  * @param titulo El nuevo título de la descripción.
  * @throws IllegalArgumentException Si titulo es null, está vacío o contiene sólo espacios.
  */
 public void setTitulo (String titulo) throws IllegalArgumentException
 {
   if (titulo == null || titulo.trim().equals(""))
   {
       throw new IllegalArgumentException("El título no puede ser nulo o vacío");
   }
   else
   {
       this.titulo = titulo;
   }
 }

Easy reading from Keyboard in Java

We can use Scanner class

Import first:

import java.util.Scanner;

Then we go this way for integers.

Scanner keyboard = new Scanner(System.in);
System.out.println("enter an integer");
int myint = keyboard.nextInt();

If we rather a string line:

String text= scan.nextLine();

Easy piece!

Note: If you are using nextInt() with nextLine() it may probably could have some trouble cause nextInt() does not read the last newline character of input and so nextLine().