Write a java program to reverse the nodes in a singly linked list

Write a java program to reverse the nodes in a singly linked list. In this program, it will print the node elements in the reverse order using singly linked list. 

public class Main 
{
class Node
{
int data;
Node next;
public Node(int data)
{
this.data = data;
this.next = null;
}
}
public Node first = null;
public Node last = null;
public void addNode(int data)
{
Node newNode = new Node(data);
if(first == null)
{
first = newNode;
last = newNode;
}
else
{
last.next = newNode;
last = newNode;
}
}
public void reverse(Node current)
{
if(first == null)
{
System.out.println("list is empty");
return;
}
else
{

if(current.next == null)
{
System.out.print(current.data + " ");
return;
}
reverse(current.next);
System.out.print(current.data + " ");
}
}
public void display()
{
Node current = first;
if(first == null)
{
System.out.println("list is empty");
return;
}
while(current != null)
{
System.out.print(current.data + " ");
current = current.next;
}
System.out.println();
}

public static void main(String[] args)
{
Main sList = new Main();
sList.addNode(2);
sList.addNode(4);
sList.addNode(6);
sList.addNode(8);
sList.display();
System.out.println("Reversed List");
sList.reverse(sList.first);
}
}

Output:

2 4 6 8
Reversed List
8 6 4 2