Tag: java

  • Ternary Operator in Java

    Ternary Operator in Java

    In this article, we’ll go through what the Ternary Operator is in Java and how it works. 1. What is Ternary Operator in Java? The ternary operator is the ? followed by 2 : and it can be used to assign a value to a variable based on the truthiness of a condition. The syntax…

  • Java String Replace Methods

    Java String Replace Methods

    In this article, we’ll go through how you can replace either a character or a string inside a String in Java. 1. Java String Replace without Regex. In this section, we’ll go through the two methods String class provides us for replacing either a character or a string. 1.1. Replace a Character Using replace(Character oldChar,…

  • Java String

    Java String

    In this article, we’ll talk about one of the most important classes in Java, the String class. 1. What Is String in Java? A Java String is basically an array of characters. Additionally, all Strings are immutable so you cannot really change the value of a String, the only way to “change” it, is to…

  • Java Interface

    Java Interface

    In this article, we’ll go through what an interface is in Java, why you should use it and when you should use an interface. 1. What Is a Java Interface? An interface in Java is like an abstract class, but it provides full abstraction as you mainly do not implement methods (although since Java 8…

  • Java Constructor

    Java Constructor

    In this article, we’ll go through what a Java constructor is and it works. 1. What Is a Java Constructor? A constructor is a block of code, which might seem similar to methods at first, but has some fundamental differences compared to them. You can utilize a constructor for the creation of a new object.…

  • Java Operators

    Java Operators

    In this tutorial, we will go through all operators that exist in Java and explain when, how, and why you should use them. 1. Java Operators Overview Operators in Java are symbols that are used in combination with variables, in order to perform specific actions. You have used operators many times in your math classes,…

  • How to Install Java on Linux

    How to Install Java on Linux

    Today we will see how to install Java 19.0.2 (this is the last version of Java, as of the time of writing this article) on Linux. Specifically, Ubuntu 20.04.2 LTS Distribution, meaning the Java Development Kit (JDK). 1. Find the Download Link The question “How to install Java on Linux”, is asked by every Java…

  • Access Modifiers in Java

    Access Modifiers in Java

    In this article, we’ll explain what access modifiers are in Java and how they work. 1. What Are Access Modifiers? Access modifiers are keywords that define which classes can access specific classes, members, or methods. The available keywords are: public: This class, member, or method can be accessed from everywhere. protected: The class, member, or…

  • HashMap in Java

    HashMap in Java

    In this article, we will explain what a HashMap is, analyze the constructors and methods of HashMap class in Java, and then go through a real-world use case of HashMap. 1. What is a HashMap and how it works HashMap in Java is a Key-Value Data Structure. The HashMap class in Java inherits from AbstractMap…

  • Math.random in Java

    Math.random in Java

    1. What is java.lang.Math.random() in java? Today we’ll analyze how the Math.random() method works in Java. The Math.random() method is a function of the Math class that accepts zero arguments and returns a pseudorandom number between 0(inclusive) and 1(exclusive). 2. Simple Math.random() example Below you can find a simple example of using this method: The…