A novice student record system I am an extreme novice in Java and thus trying to practise some online exercises. One of them involved creating a basic student record system.
This is what I've come up with but I think a lot of things are quite redundant in my code so any reviews are greatly appreciated.

Student.java

class Student {

    int rollno;
    String name;

    Student(int r, String n) {
        this.rollno = r;
        this.name = n;
    }
}


StudentDB.java

import java.util.Scanner;

class Main {

    public static void getStudents(Student ...students) {
        int i = 1;
        for (Student x : students) {
            System.out.println("Student Number : " + i);
            System.out.println("Name -&gt; "+ x.name);
            System.out.println("Roll Number -&gt; " + x.rollno + "\n");
            i++;
        }
    }

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        System.out.print("Number of students? ");
        int num = sc.nextInt();

        String[] name = new String[num];
        int[] rollno = new int[num];

        System.out.println("Enter those " + num + " students one by one");

        for (int i = 0; i &lt; num; i++) {
            System.out.println("Enter details for student no. " + (i + 1));
            System.out.print("Enter Name: ");
            name[i] = sc.next();
            System.out.print("Enter Roll Number: ");
            rollno[i] = sc.nextInt();
            System.out.println("\n");
        }

        Student[] students = new Student[num];

        for (int i = 0; i &lt; num; ++i) {
            students[i] = new Student(rollno[i], name[i]);
        }

        getStudents(students);
    }
}


I would really love it if someone could tell me as to how can I pass those name and rollno arrays directly to the vararg function getStudents without creating that Student[] object array.
Main:

import java.util.Scanner;

class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        Student[] students = StudentRoll.gatherStudents(scanner);
        StudentRoll.printStudents(students);

    }
}


Student:

class Student {

    private int rollNumber;
    private String name;

    Student(int rollNumber, String name) {
        this.rollNumber = rollNumber;
        this.name = name;
    }

    int getRollNumber() {
        return rollNumber;
    }
    void setRollNumber(int rollNumber) {
        this.rollNumber = rollNumber;
    }

    String getName() {
        return name;
    }
    void setName(String name) {
        this.name = name;
    }
}


StudentRoll:

class StudentRoll {

    static Student[] gatherStudents(Scanner scanner){

        System.out.print("Number of students? ");
        int numberOfStudents = scanner.nextInt();

        System.out.println("Enter those " + numberOfStudents + " students one by one");
        Student[] students = new Student[numberOfStudents];

        for (int index = 0; index &lt; numberOfStudents; index++) {
            System.out.println("Enter details for the next student no. ");
            System.out.print("Enter Name: ");
            String studentName = scanner.next();
            System.out.print("Enter Roll Number: ");
            int rollNumber = scanner.nextInt();
            students[index] = new Student(rollNumber, studentName);
            System.out.println("\n");
        }
        return students;
    }

    static void printStudents(Student[] students){
        int i = 1;
        for (Student x : students) {
            System.out.println("Student Number : " + i);
            System.out.println("Name -&gt; " + x.getName());
            System.out.println("Roll Number -&gt; " + x.getRollNumber() + "\n");
            i++;
        }
    }
}


I can't post many notes right now, but will as soon as I can. Think the main thing here is that your code isn't very object-oriented, but Java is an object-oriented language. It's also generally a good idea to name variables something other than num, so that when you're working on a method that has 5 different int variables, you aren't tempted to call them num1 , num2, etc., but what they actually represent. I'm also not a big fan of using a for-in when you reference an index, but it didn't seem like the worst thing in the world so I left it in there.