Limiting the fps of a game using no external libraries

I have been searching the web and seen different ways of making fps limitations but i cannot quite find the best way to do it and an explanation following with it.

Could someone please tell me how to make an fps limiter and explain how it works?
I did create a game before using LWJGL but it synced the fps for me :stuck_out_tongue:

My current code:



public void run(){

        long beforeTime, timeDiff, sleepTime;
        int period;
        period = 1000/60;
        beforeTime = System.currentTimeMillis();

        while(Running == true){
            Update();
            Draw();

            timeDiff = System.currentTimeMillis() - beforeTime;
            sleepTime = period - timeDiff;
            if(sleepTime <= 0)
                sleepTime = 5;

            try{
                Thread.sleep(sleepTime);
            }
            catch(InterruptedException ex){}

            beforeTime = System.currentTimeMillis();
        }

    }

Here´s the classic Java gaming text on game loops: http://www.java-gaming.org/index.php?topic=24220.0

Greatly appreciated!