Programming a clock in Java from the command line.

Advertisement

Java is a widely used programming language for coding web applications. It has been a popular choice among developers for over two decades, with millions of Java applications in use today. Java is a cross-platform, object-oriented, web-centric language that can be used as a platform in itself. It is a fast, secure, and reliable programming language for coding everything from mobile apps and enterprise software to big data applications and server technologies.

Java is a widely used object-oriented programming language and software platform that runs on billions of devices, including laptops, mobile devices, video game consoles, medical devices, and many others. Java's rules and syntax are based on C and C++.

One of the main advantages of developing software with Java is its portability. Once you've written Java program code on a laptop, it's very easy to transfer it to a mobile device. When James Gosling of Sun Microsystems (later acquired by Oracle) invented this language in 1991, his main goal was to be able to "write once, run anywhere."

It's important to understand that Java has almost nothing to do with JavaScript. Compiling isn't required for Javascript, whereas Java code is. Furthermore, Javascript only runs in web browsers, while Java can run anywhere.

New and improved software development tools are appearing on the market at a remarkable pace, displacing products once considered indispensable. Despite this constant churn, Java's longevity is impressive: more than two decades after its creation, Java remains the most popular language for application software development and the preferred choice for developers over other languages such as Python, Ruby, PHP, Swift, C++, and others. As a result, Java remains an important requirement for competing in the job market.

Advertisement

Developer on Linux: gnulinux system clock in Java SE in Shell.

// Mostrar un reloj del sistema gnulinux en Java SE.
// En caso de no tener un entorno GUI, este monitorizador de tiempo del Sistema realizara
// Perfectamente su función, su mejora es las milésimas de segundo para exactitud perfecta.
// Autor: OjosDeGato
// Realizado en GNU-Linux con licencia GNU.
// Realizado en Vim por Shell Linux.
  
import java.util.*;
  
public class Reloj {
    public static void main(String[] arg){
       //Obtener la hora y fechas actuales
       //Creo el objeto calendario de la clase Calendar del paquete java.util.*
        Calendar calendario = Calendar.getInstance();
        int hora = calendario.get(Calendar.HOUR_OF_DAY);
        int minutos = calendario.get(Calendar.MINUTE);
        int mes = calendario.get(Calendar.MONTH) + 1;
        int dia = calendario.get(Calendar.DAY_OF_MONTH);
        int nombre_dia = calendario.get(Calendar.DAY_OF_WEEK) -1;
        int year = calendario.get(Calendar.YEAR);
        int segundos = calendario.get(Calendar.SECOND);
        int milisegundos = calendario.get(Calendar.MILLISECOND);
         
        //mostrar un saludo
        if (hora < 12){
          System.out.println("Buenos dias por la mañana!!!\n");
        }
        else if (hora < 17) {
          System.out.println("Buenas tardes!!!\n");  
        }
        else {
          System.out.println("Buenas noches!!!\n");
        }
  
       // Mostrar Fecha local
        System.out.println("Hoy es " + calendario.getTime());
  
       //Mostrar hora
        System.out.print("Son las ");
        System.out.print( (hora > 24) ? (hora -24) : hora );
        System.out.print(" horas ");
         
       //Iniciar mensaje de hora mostrando los minutos
        System.out.print("y");
        if (minutos != 0 ){
          System.out.print(" " + minutos + " ");
          System.out.print( ( minutos != 1) ? "minutos" : "minutos");
        }
           
          //Mostrar segundos
          System.out.print(" con");
        if (segundos != 0 ){
          System.out.print(" " + segundos + " ");
          System.out.print( ( segundos != 1) ? "segundos" : "segundos");
          System.out.print(" ");
        }
          // Mostrar Milisegundos
            
          System.out.print("y");
        if (milisegundos != 0 ){
          System.out.print(" " + milisegundos + " ");
          System.out.print( (milisegundos != 1) ? "milisegundos" : "milisegundos");
          System.out.print(" del dia");
          System.out.print(" " + dia );
          System.out.print(" ");
         } 
         //Iniciar nombre del dia
         
           switch (nombre_dia){
            case 1:
                System.out.print("Lunes");
                break;
            case 2:
                System.out.print("Martes");
                break;
            case 3:
                System.out.print("Miercoles");
                break;
            case 4:
                System.out.print("Jueves");
                break;
            case 5:
                System.out.print("Viernes");
                break;
            case 6:
                System.out.print("Sabado");
                break;
            case 7:
                System.out.print("Domingo");
                 
        }
           
         System.out.print(" ");
         
        //Mostrar nombre del mes
        switch (mes){
            case 1:
                System.out.print("Enero");
                break;
            case 2:
                System.out.print("Febrero");
                break;
            case 3:
                System.out.print("Marzo");
                break;
            case 4:
                System.out.print("Abril");
                break;
            case 5:
                System.out.print("Mayo");
                break;
            case 6:
                System.out.print("Junio");
                break;
            case 7:
                System.out.print("Julio");
                break;
            case 8:
                System.out.print("Agosto");
                break;
            case 9:
                System.out.print("Septiembre");
                break;
            case 10:
                System.out.print("Octubre");
                break;
            case 11:
                System.out.print("Noviembre");
                break;
            case 12:
                System.out.print("Diciembre");        
        }
         
        //Mostrar la fecha y año
        System.out.print(" fecha:");
        System.out.print(" " + dia );
        System.out.print("/" + mes );
        System.out.println("/" + year );
  
    }
        
  }
  

Let's compile and run the clock command made in Java that calculates down to the thousandths of a second. Here's the result after spending 2 days messing with the GPL3 licensed source code that you can all see and download, improving it without problems with proprietary licenses for closed source software:

ojosdegato@FedoraLinux:~$ javac Reloj.java
ojosdegato@FedoraLinux:~$ java Reloj
Buenas tardes!!!

Hoy es Wed Jan 03 16:09:18 CET 2024
Son las 16 horas y 9 minutos con 18 segundos y 368 milisegundos del dia 3 Miercoles Enero fecha: 3/1/2024

Compilation and Result in OK:

$ echo hola ojosdegato
hola ojosdegato

The digital clock is finished, it compiles and runs in Shell perfectly. All Linuxers can improve and perfect my open source code, licensed under the GNU GPL-AGPL. Remember that the Digital Clock is not commercial.

Our score
Click to rate this post!
(Votes: 0 Average: 0)
Advertisement
Share on social media...

Deja un comentario

Your email address will not be published. Required fields are marked *

Basic information on data protection
ResponsibleJavier Cachón Garrido +info...
PurposeManage and moderate your comments. +info...
LegitimationConsent of the concerned party. +info...
RecipientsAutomattic Inc., USA to spam filtering. +info...
RightsAccess, rectify and cancel data, as well as some other rights. +info...
Additional informationYou can read additional and detailed information on data protection on our page política de privacidad.

Este sitio usa Akismet para reducir el spam. Aprende cómo se procesan los datos de tus comentarios.

Scroll al inicio

Descubre más desde javiercachon.com

Suscríbete ahora para seguir leyendo y obtener acceso al archivo completo.

Seguir leyendo