Languages
[Edit]
EN

Dirask - variable naming convention (Java)

0 points
Created by:
Tomeriko
263

This article presents variable naming convention in Java.

Class formatting

  • new line before main method,
  • new line before if statements / loops

Array of integers example

import java.util.Arrays;

public class Example {

    public static void main(String[] args) {
        int[] numbers = {1, 2, 3};
        System.out.println(Arrays.toString(numbers));
    }
}

Array of Strings example

import java.util.Arrays;

public class Example {

    public static void main(String[] args) {
        String[] letters = {"a", "b", "c"};
        System.out.println(Arrays.toString(letters));
    }
}

Array of Objects example

Example user object:

public class User {
    private final String name;
    private final int age;

    public User(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }

    @Override
    public String toString() {
        return "User{ " +
                "name='" + name + '\'' +
                ", age=" + age +
                " }";
    }
}

 Array of objects:

import java.util.Arrays;

public class Example {

    private static int[] myArray = {1, 2, 3};

    public static void main(String[] args) {
        User[] users = {new User("Tom", 19), new User("Kate", 21)};

        System.out.println(Arrays.toString(users));
    }
}

 

Dirask - content writing

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join