Get initials from full name Going through a book, I encountered the following assignment:


  Write an application that asks for the user’s first, middle, and last names and
  replies with the user’s initials.


Are there any flaws you notice immediately? Is there any way this code can be improved? I'm not really interested in coding style (I guess someone is going to say that I should put those braces on the next line, but I like it this way).

import javax.swing.JOptionPane;

public class Program
{

private static String fullName;
private static String firstName;
private static String middleName;
private static String lastName;

private static char firstInitial;
private static char middleInitial;
private static char lastInitial;

public static void main(String[] args)
{
    start();
}

public static void start()
{
    greet();
    askInput();
    seperateFullName(fullName);
    getInitials(firstName, middleName, lastName);
    showResult();
}

// @formatter:off
private static void greet()
{
    int dialogResult = JOptionPane.showConfirmDialog(null,  "This program asks you for you first, middle and last name"
                            + " and gives back your initials.\nDo you want to continue?");

    if (dialogResult == JOptionPane.NO_OPTION)
    {
        JOptionPane.showMessageDialog(null, "Shutting down...", null, JOptionPane.WARNING_MESSAGE);
        System.exit(0);
    }

}

private static void askInput()
{
    fullName = JOptionPane.showInputDialog("Please enter your first, middle and last name.");
}

private static void seperateFullName(String fullName)
{
    try
    {
        int firstSpace = fullName.indexOf(" ");
        firstName = fullName.substring(0, firstSpace);
        int lastSpace = fullName.lastIndexOf(" ");
        middleName = fullName.substring(firstSpace + 1 , lastSpace);
        lastName = fullName.substring(lastSpace + 1, fullName.length());
    }
    catch (StringIndexOutOfBoundsException e)
    {
        JOptionPane.showMessageDialog(null, "Invalid input!", null,
                JOptionPane.WARNING_MESSAGE, null);
        start();
    }
}

private static void getInitials(String firstName, String middleName, String lastName)
{
    firstInitial = firstName.charAt(0);
    middleInitial = middleName.charAt(0);
    lastInitial = lastName.charAt(0);
}
// @formatter:on

private static void showResult()
{
    JOptionPane.showMessageDialog(null, "Your initials are: "
            + firstInitial + "." + middleInitial + "." + lastInitial + ".");
}
}
Other than the style (yeah, you mentioned it) I think that you can:

First a small change: replace this

    int firstSpace = fullName.indexOf(" ");
    firstName = fullName.substring(0, firstSpace);
    int lastSpace = fullName.lastIndexOf(" ");
    middleName = fullName.substring(firstSpace + 1 , lastSpace);
    lastName = fullName.substring(lastSpace + 1, fullName.length());


with this:

String[] parts = fullName.split(" ");


But the main change I would suggest is a design one: remove the need for instance variables, by making each function return the input for the next.

public static void start()
{
    greet();
    String fullName = askInput();
    String[] nameParts = seperateFullName(fullName);
    String[] initials = getInitials(nameParts);
    showResult(initials);
}


(and of course modifying each function to return the value they compute)

Why? 


It decouples each different part of the program, keeping them independent, specific, and therefore less prone to errors introduced somewhere else in the code. 
It helps also with testing, as you can easily test each function separately. 
It also helps with reusability as you could re-use each different part in other places.


Other than that, check the spelling in functions' names (For example: in seperateFullName separate is misspelt)