Annotations are the way we can add metadata to class declaration, variable declaration, and methods. We can tag our code with annotations to provide extra information.

@Override
public void run() {
System.out.println("running..");
}

That’s how the annotation looks like. We put annotation name after character.

@Author(
name = "John Doe",
date = "09/14/2021"
)
public class HelloWorld {
}

Some annotations can have elements. and are the elements of annotation.

We will discuss these two main topics related to annotations

  1. Built-in annotations in Java.
  2. Creating own custom annotations.

Built-in annotations in Java

There are seven built-in annotations we can use…


Today we will talk about reflection in Java. The main credit and source used for this article is an official oracle article.

Reflection is when code can reflect a source code or we can say when code can read itself. By using reflection we can find out about members of the specific class during the code execution. We also can call a method of a specific class without knowing its name before running and so on.

  1. Finding out about class members.
  2. Using class members.
  3. Reading annotations.

Finding out about class members

Let’s say we have this class and we want to find out more…


In this article, we will discuss how to run terminal commands from Java code. We can execute specific commands from the terminal to execute processes in an operating system.

The most used ones are in Linux-based operating systems. We literally do everything from the terminal in Linux to work on the server and sometimes we need to do it from the code.

ProcessBuidler

We are going to discuss and files.

Ok, let’s see one code that can execute commands from the terminal:

  • The above code executes commands to list files and directories on my desktop. You can…


In this article, I want to discuss in great detail how to work with files by using Java.

  1. File
  2. Reading and writing content

File

Well, let’s start first with understanding what is it file and file system.

File System


In this article, we will go over how to work with dates and times in Java by using local date & time classes. These classes are available from Java 8.

We are going to discuss:

  1. LocalDate represents just a date(year, month, day) — not time.
  2. LocalTime represents only a time(hours, minutes, seconds, nanoseconds).
  3. LocalDateTime represents date and time.

LocalDate

We can use to represent a date in our program as an object. In addition, it has many useful methods to manipulate its value.

import java.time.LocalDate;

public class Main {
public static void main(String[] args) {…


In this article, we will go over the ArrayList in great detail.


Sometimes in our programs we need to deal with collection of data that connected with some logic together. It would be great to put them all in one box and carry them all together. The array is data type for that exact purpose, It can hold collection of data.

The array is a collection of data of the same type.

  • The array is a fixed-size collection of data. We need to specify the size of the array while creating it, and the size cannot be changed.
  • We have random access to each element in the array by using its index…


  1. Method Overloading
  2. Method Overriding

Method Overloading

  1. Method overloading is when more than one method with the same name but a different number or type of arguments defined in the same class.
  2. The return type of the method can be different.
public class CalculatorUtil {   public static int sum(int i, int i2) {
return i + i2;
}
public static int sum(int i, int i2, int i3) {
return i + i2 + i3;
}

public static double sum(double i, double i2) {
return i +…


The ability of an object to take many forms.

Photo by Nitty Ditty on Unsplash

We can create polymorphic objects when we have a parent-child relationship between classes or interfaces and their implementations.

Let’s say we have these classes


The main method has a mechanism to accept input when run from the terminal.

terminal

Run from terminal

Let’s say I have this class

public class Main {
public static void main(String[] args) {
System.out.println("hello, world!");
}
}

This code is saved in file under my desktop. In order to run it from the terminal, I will need to navigate with my terminal to my desktop and execute these commands:

— to compile the source code into java byte code.

— to run without any arguments.

Run from the terminal with arguments

public class Main {
public static void main(String[] args) {…

Beknazar

Software Developer, Java Instructor https://www.techleadacademy.io/

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store