Language Selection

English French German Italian Portuguese Spanish

Programming Leftovers

Filed under
Development

Java

  • Convert List to Array in Java

    A list differs from an array, in the sense that it can grow or shrink in length. It can also have elements inserted within its length, and so increasing the length. It can also have its elements deleted. If the aim of the list is not to make it grow or shrink or have any special function, then the array should be used. And so, it would be necessary to convert a list to an array.

    In Java, a list is not a class. It is an interface. An interface in Java is like an abstract class, but it is not meant to be subclassed. An interface is meant to have unrelated classes. The method declarations without body of the interface are defined in a class implemented from the interface. This should not be confused with instantiation. An object is instantiated from a class. A method is implemented from an abstract method, which may be a member of an interface, or an abstract class. With the interface, the “abstract” method declaration is not preceded by the reserved word, abstract. Note: a class created from an interface is said to have implemented the interface.

    Among classes of list already implemented in the Java compiler, are the ArrayList, LinkedList and Vector. These three classes will be used to show how a list can be converted into an array in this article, beginning with the ArrayList.

  • Java Thread Sleep

    A thread can be made to halt its execution for some time before it continues to operate. The thread is considered to sleep, in the period that it halts. But, what is a thread? A thread is a sub-program. It is possible to have more than one thread in one program, running concurrently. The main program itself is the main thread. A single threaded program is just the normal program. In Java, the normal program is the class that has the main() method. In a multi-threaded program, the main() method, can be considered as the main thread.

    A thread can be created by sub-classing the Thread class. The thread can be made to sleep. This article explains how to make a thread sleep, beginning with a summary of how to create a new thread in Java. The Thread class does not need to be imported in order to have a thread in the program.

  • Recursion in Java

    Recursion in Java is the calling of a method, by the method, from within the method. This action repeats itself until a condition is met. The method should be a method in a class, other than one in the main class. The main class is the class that has the main() method. The name of the Java file is that of the main class. A static method in the main class can still be made recursive, but that will not be addressed in this article. This article explains recursion in Java, with three good examples.

  • Java Thread Timer Usage

    In Java, a timer is a class from which timer objects can be instantiated. The timer schedules task for execution in the near future. A task is like a method (function). Java has the class, TimerTask from which task objects can be instantiated. Different tasks are scheduled to operate (execute) at different times. This tutorial explains how to instantiate and use the timer object in Java, beginning with the instantiation of the TimerTask object and its nature.

  • Java instanceof Operator

    The instanceof operator checks if its operand on the left is an object of its operand on the right. If yes, it returns true, otherwise it returns false, or issues an error message at compile time. The operand on the left should be an instantiated object of the operand on the right. The operand on the right is a type, e.g. a class.

  • 2D Array in Java

    In Java, a one-dimensional array is a consecutive set of values of the same type. The type of the values is the type of the array. A 1D array is an object from the Object superclass. A 1d array is a list. In this article, the list for the one-dimensional array is assumed to be displayed in a vertical column. A 1d array has the property length, which returns the number of elements in the array.

    A two-dimensional array is a table. A table is a vertical list of horizontal lists. In Java, a two-dimensional array is an array of arrays. That is, a 2d array is a vertical array of horizontal arrays. That is, a 2D array in Java is a vertical list of horizontal lists. The 2D array has rows and columns. The length of the 2D array is the number of rows, which is the length property of the 1D column array. All the values in all the cells of the table are of the same type; this is said to be the type of the 2D array.

    This article explains, what a 2D array in Java is, and how to create and access its elements. All code for this article takes place in the main() method.

  • && and & Operators in Java

    In Java, && is called the conditional-And operator. It is an example of a logical operator in Java. As another operator, & has two functions in Java. In one situation, it is called a logical-And operator. In the other situation, it is called the bitwise-AND operator. Each of these operators is a binary operator. This means that each has an operand on its left and on its right. The result of all that expression can be assigned to a variable. These operators work with primitive types, and so its class does not have to be imported by the programmer.

  • Absolute Value in Java

    A number can be an int, a long, a float, or a double. The difference between an int and a long variable is that the long variable can hold a bigger value than an int variable. A long variable can also hold a number that an int would hold. Each of these number types can be negative or positive. For example, an int can be -5 or +5. When it is +5, the plus sign in front of it can be omitted.

    So, a number can be negative or positive. Absolute value is simply the positive value of the pair. The positive value is still the number without a sign. Java has the math abs() method to return the absolute number. So, if the argument is -5, 5 will be returned. If the argument is +5 or 5, 5 will be returned. Java also has the absExact() method – see below.

    These methods are all of the Math class. The Math class does not have to be imported by the programmer to be used. This article explains the use of the abs() and absExact() methods of the math class.

C++

  • Beginner C++ Projects

    Students might find it challenging to get started with long and expert-level projects when learning a new language. Students used to derive help from books, online programming tutorials, and guides. However, these sources are not enough when you want to become an expert at a certain language. Hence, they try to search for projects which are less complicated, short, and simple to accomplish within the initial stage of practice. Within this guide, we will let you know about some C++ beginner projects along with their codes that are short and easy. Now, let’s start with Ubuntu 20.04 system.

  • Array as Parameter C++

    Functions in C++ can accept different types of arguments when they are called. In the same manner, an array can also be passed as a parameter to a function in C++. To figure out whether passing an array as a parameter to a function in C++ is the same as passing any other type of argument to a function or not, you will have to give a read to this article.

  • Argc and Argv C++

    While writing C++ programs, we all know that the “main()” function is considered very important since we cannot compile our program if the implementation of this function is missing. Just like all other functions in C++, the “main()” function is also capable of accepting arguments. However, the difference between passing arguments to the “main()” function from passing arguments to the other functions is that you have to pass the arguments through the command line in the former case. It is so because the “main()” function itself is the driver function which is why no other function is capable of calling it and passing arguments to it. In this article, we will be discussing the two parameters of the “main()” function, i.e., “argc” and “argv” in C++ in Ubuntu 20.04.

Misc.

More in Tux Machines

digiKam 7.7.0 is released

After three months of active maintenance and another bug triage, the digiKam team is proud to present version 7.7.0 of its open source digital photo manager. See below the list of most important features coming with this release. Read more

Dilution and Misuse of the "Linux" Brand

Samsung, Red Hat to Work on Linux Drivers for Future Tech

The metaverse is expected to uproot system design as we know it, and Samsung is one of many hardware vendors re-imagining data center infrastructure in preparation for a parallel 3D world. Samsung is working on new memory technologies that provide faster bandwidth inside hardware for data to travel between CPUs, storage and other computing resources. The company also announced it was partnering with Red Hat to ensure these technologies have Linux compatibility. Read more

today's howtos

  • How to install go1.19beta on Ubuntu 22.04 – NextGenTips

    In this tutorial, we are going to explore how to install go on Ubuntu 22.04 Golang is an open-source programming language that is easy to learn and use. It is built-in concurrency and has a robust standard library. It is reliable, builds fast, and efficient software that scales fast. Its concurrency mechanisms make it easy to write programs that get the most out of multicore and networked machines, while its novel-type systems enable flexible and modular program constructions. Go compiles quickly to machine code and has the convenience of garbage collection and the power of run-time reflection. In this guide, we are going to learn how to install golang 1.19beta on Ubuntu 22.04. Go 1.19beta1 is not yet released. There is so much work in progress with all the documentation.

  • molecule test: failed to connect to bus in systemd container - openQA bites

    Ansible Molecule is a project to help you test your ansible roles. I’m using molecule for automatically testing the ansible roles of geekoops.

  • How To Install MongoDB on AlmaLinux 9 - idroot

    In this tutorial, we will show you how to install MongoDB on AlmaLinux 9. For those of you who didn’t know, MongoDB is a high-performance, highly scalable document-oriented NoSQL database. Unlike in SQL databases where data is stored in rows and columns inside tables, in MongoDB, data is structured in JSON-like format inside records which are referred to as documents. The open-source attribute of MongoDB as a database software makes it an ideal candidate for almost any database-related project. This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the MongoDB NoSQL database on AlmaLinux 9. You can follow the same instructions for CentOS and Rocky Linux.

  • An introduction (and how-to) to Plugin Loader for the Steam Deck. - Invidious
  • Self-host a Ghost Blog With Traefik

    Ghost is a very popular open-source content management system. Started as an alternative to WordPress and it went on to become an alternative to Substack by focusing on membership and newsletter. The creators of Ghost offer managed Pro hosting but it may not fit everyone's budget. Alternatively, you can self-host it on your own cloud servers. On Linux handbook, we already have a guide on deploying Ghost with Docker in a reverse proxy setup. Instead of Ngnix reverse proxy, you can also use another software called Traefik with Docker. It is a popular open-source cloud-native application proxy, API Gateway, Edge-router, and more. I use Traefik to secure my websites using an SSL certificate obtained from Let's Encrypt. Once deployed, Traefik can automatically manage your certificates and their renewals. In this tutorial, I'll share the necessary steps for deploying a Ghost blog with Docker and Traefik.