TWO approaches to calling methods from within a class that is executing

// example showing how to declare instance variables / arrays
// and not assign them a value at that time rather in methods
package untitled111;
import java.io.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Bubbles2
{
private int scores[];                       // declare instance array
private int ne;                                // declare instance variable
public Bubbles2()
{
getData(); // get the data
print(); // print the data
}
public void getData()
{
ne = Integer.parseInt(JOptionPane.showInputDialog("Enter numberof scores ?"));
scores = new int [ne]; // dynamically declaring an array
for (int a=0; a<ne; a++)
scores[a] = Integer.parseInt(JOptionPane.showInputDialog("Please enter exam score ?"));
}
public void print()
{
String out="";
for(int a=0;a<ne;a++)
out+=scores[a]+"\n";
JOptionPane.showMessageDialog(null,out);
}
public static void main(String[] args)
{
Bubbles2 bub=new Bubbles2();
System.exit(0);
}
}
****************************************************************************
// example showing how to declare instance variables / arrays
// and not assign them a value at that time rather in methods
package untitled111;
import java.io.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Bubbles3
{
private int scores[]; // declare instance array
private int ne; // declare instance variable
public Bubbles3()
{
// in this example, I did not put any code here
}
public void getData()
{
ne = Integer.parseInt(JOptionPane.showInputDialog("Enter numberof scores ?"));
scores = new int [ne]; // dynamically declaring an array
for (int a=0; a<ne; a++)
scores[a] = Integer.parseInt(JOptionPane.showInputDialog("Please enter exam score ?"));
}
public void print()
{
String out="";
for(int a=0;a<ne;a++)
out+=scores[a]+"\n";
JOptionPane.showMessageDialog(null,out);
}
public static void main(String[] args)
{
Bubbles3 bub=new Bubbles3();
bub.getData();                                    // calling the method getData on object bub
bub.print();                                         // calling the method print on object bub
System.exit(0);
}
}