Test

Advantages of Programming with Java

Arteco - Information Technologies
  • :)
  • :0
  • :D
  • ;)
  • :]
foto Ramón Arnau

Ramón Arnau

Gerente de Arteco Consulting SL

Java is the most widely used Programming language in Enterprise. Why? It's Compiled and Statically Typed, ideal for large projects

Java is the most used programming language in companies that develop their own software. We analyze the main features and describe why it is the best programming language to learn programming or to develop any web project.

What is Java

Java is an object-oriented programming language that involves processing text files with the extension .java written by people with a compiler, producing efficient binaries and portable across different architectures that are processed by the Java Virtual Machine JVM.

The JVM is software that must be installed on all computers that wish to execute programs written with Java. The JVM provides a unified and independent layer between the different operating systems so that programmers only need to learn a single programming interface.

On the other hand, both Java and the JVM are highly efficient software since both in the compilation and in the execution of programs with Java, numerous optimizations are made on the resulting code, such as Just In Time Compilation (JIT). Basically, the JIT compiles the cross-platform code generated by the compiler into platform-specific native code where it is being executed to take advantage of the particularities of the architecture supporting the execution.

Why learn to program with Java

Java enjoys great popularity in the world of software development and especially in those applications oriented to the Internet. There are many important companies that support it and finance the evolutions of the language.

As a conclusion, we can indicate that Java is the most used programming language in the business world and especially in those companies that develop software based on the Http protocol. This fact translates into many more job offers for Java programmers in the job market than in any other programming language.

Java is free

Since its creation in 1995, by Sun Microsystems, the Java programming language has been oriented mainly to solve problems related to software development, from the business point of view, providing a more productive framework and allowing to generate more maintainable and scalable software.

In 2010, the company that created Java was acquired by Oracle in a series of negotiations that required the new owner to continue with the process of liberalization of the technology under the GNU GPL license gradually, in actions that began earlier and very timidly from 2007.

Today, the OpenJDK platform is responsible for publishing the latest versions of both the Java language and the JVM virtual machine necessary to run programs written in this language, following the guidelines set by the Java Community Process with more than 1200 members, among which are Google, Adobe, Boeing, Oracle, Twitter, and others. why-use-java Java has static typing.


To ensure that the written software is robust, Java provides static typing of variables. That is, variables are only of one type and this cannot vary over time. This apparent limitation is a lifesaver for large-scale enterprise applications where groups of programmers write thousands of lines of code. Code analysis activities, such as those performed by the compiler, allow detecting a large number of errors at compile time, always preferable to finding them during execution. Especially when the application is running on embedded systems or small devices.

Java is portable

Java is the programming language, it is object-oriented, and it has static typing. Without However, its compilation does not generate native code, but it generates code to be executed in a Java Virtual Machine, JVM. The Java Virtual Machine is a player capable of executing programs compiled in Java (and other languages) abstracting from the particularities of each platform, offering the programmer a single programming interface. This causes programs written in Java to be independent and therefore portable. The binaries resulting from the compilation can be executed as is on a Windows system as well as on Mac or Linux without the need to modify a single comma.

As a consequence of its portability, the JVM must be installed on all systems that want to run programs written in Java. The OpenJDK community is responsible for maintaining all JVM implementations for each of the most common platforms.

Java is fast

It is a myth that Java is slow. Originally justified because the JVM must interpret the programs written in Java and it initially lacked powerful optimizations like today. However, and planned, from version 6 of Java, the JVM includes a compiler that generates native code at runtime transparently to the programmer and the user. In addition, during that compilation, the most advanced optimization techniques in the industry are applied, and not only based on how the code is written, but also on how the recent execution has been and how it is statistically believed that the following iterations will be. This set of optimizations causes Java to have times similar to similar programs written in C/C++.

Today, in more modern versions like Java 13, the number of code optimizations, level of parallelism, and the great work of research groups can be affirmed with certainty that Java is one of the languages with the best performance in the general-purpose software landscape, much superior to that of other dynamic or weakly typed languages.

Java has a large ecosystem

Since its inception, Java has had a great penetration in the software development market at the business level. Its maturity and reliability have caused many companies to bet on this language when facing large investments in the development of their own information platforms. As a result of this adoption, both programmers and companies and organizations actively participate in the development of useful tools and libraries (many of them Open Source) to solve the common problems that programmers must face.

As a special mention, organizations like Apache Foundation and Eclipse Foundation, among others like Google and Netflix, have contributed many of the libraries and utilities used daily in software development, all of them Open Source with very permissive licenses.

Java has a large number of programmers

It is difficult to know if thanks to the large number of programmers there is a large ecosystem, or vice versa. But what is known is that finding programmers knowledgeable in Java is an easier task than finding those who master less deployed languages.

It is also known that Java is one of the languages that has positioned itself between the second and first place as the most used programming language in the world in the last almost 20 years, rivaling with C/C++ according to the traditional TIOBE index.

Java has the most advanced IDEs

Traditionally Java has always had the benefit of incorporating the most advanced IDEs or programming editors on the market, practically all of them without cost of use helping their implementation in companies. These editors allow incremental compilation, code writing assistance, refactoring, API documentation search, and many other functions.

From Netbeans IDE, to Eclipse IDE and more recently Intellij are the most used programming editors, even for other languages, full of integrations with typical tools like Git for version control or Maven and Gradle for application building.

What is a Java IDE

The acronym IDE stands for Integrated Development Environment or in other words Integrated Programming Environment. Basically, it is a term that is attributed to text editors that have added many functionalities and quick accesses to perform typical tasks of the programmer. They are also somewhat intelligent and index the content of source files, allow step-by-step execution of programs showing the detail of the progress in execution, and have integrations with other common tools such as version control systems like git, or even issue trackers to process error tickets or change requests made by users.

Although it is not totally mandatory, its use is more than advisable to use one that incorporates native support with the programming language that will be used to develop programs, web pages, or mobile applications that you want.

Fortunately, all proposed are free and they are also Open Source contrary to what may seem. There are thousands of companies and programmers who keep these editors updated by adding innovations due to their great implementation in all sectors, avoiding dominant positions in the market or manufacturers that apply licenses or royalties when considering them as critical or more critical than the programming language itself, due to the cost of development when having to hire specialized personnel with well-paid salaries.

Which programming editor to choose

Within the set of free IDEs, most of them Open Source, they are divided into two large families. The generic ones that allow editing files in general, without being specialized in any language, but highly configurable and adaptable. These include access to small programs that complete them called plugins that adjust behavior to the language or tools used.

With any of the generic editors, the user can perform programming activities, but you should know that you will have a considerable performance penalty in terms of the time invested, regarding another that uses a good editor with all the batteries included. In addition, these advanced IDEs are also free, why not learn to use one?

In the list of generic programming editors the following appear:

However, we recommend an IDE specialized in Java projects, which has native integration with Maven to simplify the activities that we will have to perform as programmers.

If we focus on IDEs specialized in Java the recommended list is as follows:

Any of the three editors mentioned will be sufficient to make applications in Java, all of them include Maven and Git support natively. No plugin or third-party software will be required to add the necessary functionality. This will not be the case if a generic editor is used such as: VSCODE, Sublime, Atom or Brackets.

Install a Java IDE on Ubuntu

Ubuntu repositories simplify installation tasks to the maximum and the main programming editors are hosted in them. For this, simply open the Ubuntu Software icon and search for Java IDE.

Next, we will see the different options corresponding to the main programming editors most used in Java: IDEA Community, Eclipse, and Apache NetBeans. Just select any of them and the system will automatically proceed to download and install the requested software.

Install an IDE for Java on Windows or Mac

Installing any of the indicated IDEs: Idea, Eclipse, or Netbeans, will be sufficient to access the page indicated in the list and download the corresponding installer for the operating system you have and the architecture of the PC. Most of them will require a relatively modern PC with a 64-bit processor.

It is advisable to have an SDD hard disk and at least 8GB of RAM for the system to respond with fluidity in compilation and program execution operations. If you do not have a suitable team, remember that a good professional needs good tools.

The installer for any of the editors will result in an icon on the desktop to quickly access the editor execution.

JVM is polyglot

The Java Virtual Machine has become in recent years a very advanced player capable of executing code from different programming languages, with Java being the most common. Users can opt for other languages with different characteristics or specialized in a particular scenario. Some examples are Groovy if you want the dynamism that scripting offers. Scala or Clojure if you are looking for a functional language, or Kotlin if you are oriented towards developing mobile applications for Android, among many other languages.

All of them benefit from the unique API provided by the JVM for any platform. It is even possible to integrate different languages into the same application to be executed by the JVM. Other languages also available are Javascript, Jython or JRuby which favor the reuse of existing libraries or frameworks.

Java has support from major companies

As mentioned earlier, Java enjoys the support of major technology companies since many of them have developed part of their platforms using this language. Members or not of the JCP, a large number of companies acknowledge internally using Java in some of their products or services. All of them are top-level companies like Google, Facebook, Twitter, Oracle, and many more. And they unanimously highlight the solidity and ease of maintenance of enterprise applications developed, especially in projects where a large number of programmers participate and therefore are subject to constant evolutions.

Java is in continuous evolution

Since OpenJDK has been in charge of Java and the JVM, the commitment of the collective that forms it is to release frequent versions that incorporate the improvements proposed by the community through the Java Community Reques (JCR) process, where requests for new features of Java or the virtual machine are proposed, evaluated, and implemented, in order to have a technological framework that adapts to new situations and hardware that may arise over time. The goal is for Java to be able to address the technological challenges as changing as recent web architectures in the cloud and based on virtualized containers without forgetting its origins in embedded and real-time systems.

How to install the Java JDK

To program in Java, the Java Development Kit (JDK) is necessary which contains the compilation tools and the basic libraries of the language. But it will be convenient for you to also have Apace Maven since it provides standardization of projects, takes care of compilation and construction of the application or library you want to generate, and also solves very efficiently the dependencies and the use of third-party libraries using public repositories with a wide range of these for free use, like Guava provided by Google, or Apache Commons provided by the Apache Foundation.

How to install Java on Ubuntu Linux

In the previous article, we taught you how to install Ubuntu, the Open Source alternative operating system to Windows preferred by programmers. If you already have it installed, you can follow the following steps to have the Java compiler and virtual machine on your computer.

Installing Java on Ubuntu is really simple, since the community prepares the OpenJdk packages with the necessary binaries and hosts them in public software repositories ready to be incorporated into our system via apt. For this, we open a command terminal and execute the following command:

sudo apt install openjdk-8-jdk

The process will download and configure the new package of Java program compilation and execution tools ready to be run by the user. It can be verified that the process has been completed successfully by running the following command again in the console:

java -version

Providing as output the correct execution and version of the Java Virtual Machine JVM:

openjdk version "11.0.6" 2020-01-14
OpenJDK Runtime Environment (build 11.0.6+10-post-Ubuntu-1ubuntu118.04.1)
OpenJDK 64-Bit Server VM (build 11.0.6+10-.., mixed mode, sharing)

At the time of writing this post, there are two available versions of Java in the official Ubuntu repositories, version 8 and version 11. By default, Ubuntu will use the most recent one, but you can force the use of a specific version such as version 8 systematically with:

sudo update-alternatives --config java

# O indicando una versión concreta con:
sudo update-java-alternatives --set /path/to/java/version

Downloading Java for Win/Mac

To install the Java programming tools, you need to download and run the Java Development Kit (JDK) installer. However, there are several distributions of the JDK, and you should choose one depending on the Java version you want. Versions published before April 16, 2019, are available for free via the Oracle website, requiring login to their system. After that date, the distributables offered by Oracle have a cost. So to avoid costs, you should turn to OpenJDK distributables, unless you want a version earlier than April 16, 2019.

In summary, to obtain the Java compiler, you should go to:

Depending on the platform where you want to install it, you should download the corresponding binary. Modern computers use 64-bit processors, so they should download the installer with the "x64" suffix. For example, for Windows, it would be "jdk-8u241-windows-x64.exe," while for Mac, it should be "jdk-8u241-macosx-x64.dmg." However, if you have an older computer, you should select one ending in "i586," corresponding to 32-bit architectures.

Installing Java on Windows

Once the JDK is downloaded following the instructions from the previous step, we will run the installer, which will proceed to copy the files to the default location. Although it can be varied, by default the files will be located in c:\Program Files\Java\jdk…. Just leave the options as they are and continue the installation wizard until the process is completed.

There is only one last step left, which is to add an environment variable and edit another existing one so that we can invoke the compiler with javac or the Java Virtual Machine with java from any directory.

Therefore, in Windows, we will leave the following environment variables as indicated below:

  • Create the JAVA_HOME variable:
    JAVA_HOME=c:\Program Files\Java\
  • Add JAVA_HOME to Path
    Path=%JAVA_HOME%\bin;%Path%;

From this moment on, every time we enter Java program compilation and execution instructions from the terminal or command prompt, Windows will know where to look for the corresponding executables.

Installing Java on Mac OSX

Once the JDK is downloaded following the instructions from the previous step, we will run the installer, which will proceed to copy the files to the default location. Although it can be varied, by default the files will be located in /Library/Java/JavaVirtualMachines/. Just leave the options as they are and continue the installation wizard until the process is completed.

There is only one last step left, which is to add an environment variable and edit another existing one so that we can invoke the compiler with javac or the Java Virtual Machine with java from any directory.

Therefore, on Mac, we will leave the following environment variables as indicated below through editing the ~/.profile file (remember that the tilde of the ñ means the user's home directory):

vi ~/.profile

Add the following lines:

export JAVA_HOME=/Library/Java/JavaVirtualMachines/<jdk_instalado>
export PATH=$JAVA_HOME/bin:$PATH

The content of these lines declares and exports the JAVA_HOME variable to make it available during the terminal session and adds the directory of Java binaries to the Path ahead of the rest of the directories it contains.

From this moment on, every time we enter Java program compilation and execution instructions from the terminal or command prompt, Windows will know where to look for the corresponding executables.

How to have multiple JDKs

To have multiple JDKs, you only need to consider the JAVA_HOME and Path (PATH in Unix/Linux) variables. After installing two or more JDKs and ensuring that there are no conflicts between them, it is enough to make sure that the Path always contains the expression pointing to the directory %JAVA_HOME%\bin in Windows, or $JAVA_HOME/bin in Linux/Mac. Therefore, when you want to switch from one JDK to another, all you have to do is adjust the JAVA_HOME variable to point to the desired JDK.

To adjust the values of the variable in Windows temporarily, the SET command can be used, and if you want the change to be permanent, you should go to the previously mentioned environment variable editing utility. Temporarily, we will do the following:

SET JAVA_HOME=c:\Archivos de Programa\Java\<jdk_alternativo>

The SET command can be executed as many times as desired to change the JDK; however, its scope is limited to the current session of the command terminal.

For Linux and Mac systems, we should use export to proceed with changing the value of the variables.

export JAVA_HOME=/opt/java/<jdk_alternativo>

In these same Unix-based systems, if you want the change to be permanent, you will edit the file located in the user's home directory named .profile. To edit this file, you can conveniently use vi.

vi ~/.profile

You can add the following line:

export JAVA_HOME=/opt/java/<jdk_alternativo>
export PATH=$JAVA_HOME/bin:$PATH

The symbol "~" represents the user's home directory in Unix systems. Note that in these systems, the directory separator is not a semicolon as in Windows, but a colon.

Your First Java Program

Once you have installed the JDK as explained in the article, you should be able to execute the compiler, javac command, from any directory, as well as the Java virtual machine with the java command. These commands are contained in a directory of the JDK called bin, which should be in the Path of your operating system. If you have done it correctly, you can verify it by executing:

java -version

If the installed version of Java is printed, the configuration is correct.

The next step is to navigate to an empty directory for the tests we are going to perform now. For example, \\Java if you're on Windows, or ~/Java if you're on Mac/Linux. Once there, we will create our first application.

In the directory created for this purpose, create the file App01.java with the following content:

public class App01 {
    public static void main(String[] args){
        System.out.println("Hola Mundo!");
    }
}

This is one of the smallest programs we can create with Java. Notice that the name of the file matches the name of the class. It must match in letter capitalization.

To generate the binary that the JVM can execute, we must invoke the compiler. It will generate the binary files, in this case App01.class, corresponding to the instructions contained in a format called byte code.

Compile the first program with:

javac App01.java

Aparentemente no ha ocurrido nada, pero si miras el directorio aparecerá un nuevo archivo App01.class. Éste ya puede ser ejecutado por la JVM:

java App01
Hola Mundo!

Congratulations! You've created your first Java program, and in a very manual way. Nowadays, programmers don't directly invoke java or javac; instead, they do it directly from the integrated development environment, which greatly aids in performing these types of tasks, especially when dealing with hundreds or thousands of Java files.

Code Organization into Packages

In a project with hundreds of classes, it becomes necessary to implement some mechanism for organizing Java files. The most natural way is to classify them into different directories. However, if one Java file references another file of this type, the compiler must know that it is located in another directory in order to find it. This is where the concept of package comes into play.

Packages allow organizing Java files into different directories, all of them sharing the same root, so that files can be used from one another. Java files, besides being located in one subdirectory or another, must have the complete folder path in the preamble of the file. For example, a file located at ./org/eadp/Utility.java should have the package declaration as follows:

package org.eadp;
public class Utilidad {
    public static void sayHello(){
        System.out.println("Hello World!");
    }
}

Thus, from our second application named App02.java and with the following content, we can invoke the use of Utility.java:

import org.eadp.Utilidad;

public class App02 {
    public static void sayHello(){
        Utilidad.sayHello();
    }
}

To make this second application work correctly, we have assumed that App01 and App02 are in the root directory of Java, while Utility.java is in Java/org/eadp. Whenever a file is used from another that is not in the same directory or package, it must be imported. To compile and execute the second application, we will enter:

javac App02.java
java App02

Java will automatically resort to compiling all the files used by App02, as long as it finds them within the project directory based on the specified imports.

All functions used here come with the static prefix, as they are class methods and not instance or object methods. We can easily convert the sayHello method in Utility to one that does not have this limitation:

// contenido de ./App03.java
import org.eadp.Utilidad2;

public class App03 {
    public static void sayHello(){
        Utilidad2 instancia = new Utilidad2();
        instancia.sayHello();
    }
}

// contenido de ./org/eadp/Utilidad2.java
public class Utilidad2 {
    public void sayHello(){
        System.out.println("Hello World!");
    }
}

To remove the static from the sayHello method in this third version, you must create an instance of the Utilidad2 class using new Utilidad2(). This reserves memory space to store an object of type Utilidad2. The memory address where it is located is stored in a variable (instance) which we can reference to invoke the sayHello method.

If you want to learn more about object-oriented programming, you can acquire the acquire the Javañol Guide, an extensive book of over 450 pages with all the necessary information to become a professional.

Definition and Use of Variables

In Java, there are two types of variables: those that store or rather point to an object, and primitive variables. The latter start with lowercase letters and instead of containing an address, they contain the data itself, as they store the data locally in the call stack.

The primitive types supported by Java are as follows:

Category Types Size (bits) Minimum Value Maximum Value Precision Example
Integer byte 8 -128 127 From +127 to -128 byte b = 65;
char 16 0 2^16-1 All Unicode characters char c = 'A'; <br>char c = 65;
short 16 -2^15 2^15-1 From +32,767 to -32,768 short s = 65;
int 32 -2^31 2^31-1 From +2,147,483,647
to -2,147,483,648
int i = 65;
long 64 -2^63 2^63-1 From +9,223,372,036,854,775,807
to -9,223,372,036,854,775,808
long l = 65L;
Floating-point float 32 2^-149 (2-2^-23)·2^127 From 3.402,823,5 E+38
to 1.4 E-45
float f = 65f;
double 64 2^-1074 (2-2^-52)·2^1023 From 1.797,693,134,862,315,7 E+308
to 4.9 E-324
double d = 65.55;
Other boolean false, true boolean b = true;
void

Whatever type of variable you want to create, first specify the type and then the variable name. Optionally, you can assign an initial value. See the following examples:

boolean b1 = true;
Utilidad util = new Utilidad();
int i = 365;
float f1 = i + 3.0f;

Notice that primitive types (those starting with lowercase letters) do not require the invocation of new. However, the variable util, being a pointer to an object, requires memory allocation. Java automatically takes care of freeing up allocations made (with new) thanks to its Garbage Collector.

Variables can be local, like those indicated in the previous code block, but they can also be object or class variables. Object variables are added just below the class definition as shown in the following example:

public class Coche {
    int numRuedas = 4;
}

If we create an object of this type with new, we will be able to access its number of wheels.

Coche c = new Coche();
System.out.println(c.numRuedas);

c.numRuedas = 8;
System.out.println(c.numRuedas);

However, when an attribute is of class type (static), it is not necessary to use new, since the variable is not associated with any object, but rather with the type or class to which it belongs.

public class Coche {
    static int numRuedas = 4;
}

Since numWheels is now static, access should be done using the class name followed by a dot:

int n = Coche.numRuedas;

The same behavior that is obtained with object attributes or variables occurs with methods if they are prefixed with the keyword static as seen at the beginning of the tutorial.

Java allows many data collections, but among the basics, we have arrays or chains of variables. They are defined as in C and in many other languages using the brackets '[' and ']' and between these symbols, the size of the array or the index of the data we want to refer to is introduced, depending on whether we are defining or using the array. The first position is 0. Examples:

// creación de un array de 10 enteros.
int[] arrayDeInts = new int[10];
arrayDeInts[0] = 1;
arrayDeInts[1] = 2;

int tmp = arrayDeInts\[2\];

// la siguiente asignación da ERROR!
// por salir de los límites
arrayDeInts[10] = 11;

Arrays can be defined for any primitive type or Java object. But it should be noted that when initializing an array with new, space is reserved to store the specified number of values, but that does not mean the data itself contains any values. Each array slot must be initialized.

Control Structures

Control structures in Java do not differ much from those in C and C++. The most basic ones are if for branching in execution, while and for for performing iterations while a condition holds true or for looping through all elements of a data collection. Below are some examples:

Example of using the if conditional, which can be chained with else if or define a general case with else.

int v1 = 3 + 5;
if ( v1 < 3 ){
    System.out.println("Número menor que 3");
} else if ( v1 < 5){
    System.out.println("Número menor que 5 y mayor o igual a 3");
} else {
    System.out.println("Número mayor o igual que 5");
}

Loops with while and for have some more options than those mentioned here, but we will show some simple examples for representation.

The while construct accepts an expression like the if statement that causes the enclosed statements between braces to be repeated as long as the expression returns true. No matter how complex the expression or condition is, as long as it evaluates to a boolean. For example:

int num = 0;
while (num < 10){
    System.out.println("Num es " + num);
    num = num + 1; // o num++;
}

On the other hand, Java provides the for construct in two modalities, the traditional one that accepts three expressions, and the relatively more modern one that accepts a collection.

In for Mode 1, the three expressions correspond to the initialization of the loop, the stop condition, and finally the update expression. Let's see an example:

for (int num = 0 ; num < 10 ; num++ ){ // i++ es quivalente a i = i + 1
    System.out.println("Num es " + num);
}

The for in this construction is somewhat more compact than while because the creation, initialization, and update of the loop variable are done in the same line, but all these steps are separated by semicolons ';'.

for Mode 2 simplifies the iteration of elements stored in a collection. Its syntax is reduced to the declaration of a local variable that will vary with each iteration pass, taking as value each of the elements of the collection, and the collection itself that you want to iterate over.

String[] array = new String[]{ "hola", "caracola" };
for (String palabra : array ){
    System.out.println("La palabra actual es: "+palabra);
}

All loops accept two keywords to alter the iteration behavior. The first one is continue, which, when executed, automatically moves to the next iteration of the loop containing it. The second one is break, which causes the opposite, i.e., when executed, it exits the loop containing it, even if there are elements left to process. A combined example of these would be the following, can you guess how many messages will be printed?:

for (int num = 0 ; num < 10 ; num++ ){
    if (i == 0){
        continue;
    } if (i >= 7){
        break;
    }
    System.out.println("Num es " + num);
}

Data Collections

Arrays are very useful but inflexible since their size cannot be changed once initialized; you must create a new array or use a more powerful data structure like Java data collections. Java provides hundreds of data collections, most of them generic, but many others specialized for particular uses to benefit from extra performance if the problem circumstance is known. Aside from the specific ones, among the general ones, the 3 most important are List, Set, and Map. All of them are interfaces that define methods but do not implement them. There are various different implementations like the aforementioned specialized ones or the generic ones.

  • java.util.List represents a variable list of elements, preserving the insertion order and allowing duplicates. Its most used implementation is java.util.ArrayList.
  • java.util.Set represents a variable set of elements, NOT preserving the insertion order, and in its most basic usage, NOT allowing duplicates. Its most used implementation is java.util.HashSet.
  • java.util.Map represents a variable dictionary of elements, NOT preserving the insertion order, and in its most basic usage, NOT allowing duplicates for the same key. Its most used implementation is java.util.HashMap.

Let's see an example of using the Java.util.List API through java.util.ArrayList:

import java.util.List;
import java.util.ArrayList;
...
List<Integer> lista = new ArrayList<Integer>();
lista.add(1);
lista.add(2);

//devuelve el elemento de la posición 0
int p0 = lista.get(0);

if ( ! lista.isEmpty()){ // ! = negación de un boolean
    lista.clear();
}

Let's see an example of using the Java.util.Set API through java.util.HashSet:

import java.util.Set;
import java.util.HashSet;
...
Set<String> set = new HashSet<String>();
set.add("hola");
set.add("hola");
set.add("abc");

// size == 2 al no permitir duplicados
int size = set.size();

// el recorrido no garantiza el orden de inserción
for (Integer i : set ){
    System.out.println(i);
}

Let's see an example of using the Java.util.Map API through java.util.HashMap:

import java.util.Map;
import java.util.HashMap;
...
Map<String,Integer> edades = new HashSet<String,Integer>();
edades.put("Pepito",25);
edades.put("Juanito",60);
edades.put("Pepito",26);

// size == 2 al no permitir duplicados
int size = set.size();

// acceso a un mapa por clave
int edadJuanito = edades.get("Juanito");

// el recorrido no garantiza el orden de inserción
for (Entry<String,Integer> entry : edades.entrySet() ){
    System.out.println(entry.getKey() + " -> " + entry.getValue());
}

JDK Documentation

Java and the JDK provide extensive and comprehensive documentation that is navigable via HTML and is automatically generated from the source code through comments hosted in Java files using the javadoc tool. This documentation is available online for each version of Java. Below are the most relevant links:

Useful Libraries

To be a good programmer, it is not only necessary to know the language well, but also to become familiar with the main libraries used in the Java ecosystem. Many are available, each focused on solving a particular issue. Depending on each case, it will be advisable to search the Internet and experiment with one or more options before introducing it into a project. But in general, the two most commonly used libraries that are definitely worth knowing are the following:

Your First Web Application

If you are already familiar with Java and the main commonly used libraries published on the internet, why not take the next step and learn the premier web framework in Java: Spring Boot.

Try creating your first Web application with Spring Boot using Spring Initializr.

Conclusions

As we have seen, Java offers a unique combination of features that make it ideal both for learning to program and for developing web projects of any scale. In summary, Java offers a unique combination of portability, ease of use, and performance, making it the perfect choice for a wide range of enterprise applications and web projects. If you want to learn more about Java and how it can benefit your projects, visit our website at Arteco Consulting. Start developing with Java today!

Stay Connected

Newsletter

Stay up to date with the latest in technology and business! Subscribe to our newsletter and receive exclusive updates directly to your inbox.

Online Meeting

Don't miss the opportunity to explore new possibilities. Schedule an online meeting with us today and let's start building the future of your business together!

  • :)
  • :0
  • :D
  • ;)
  • :]