a thoughtful web.
Good ideas and conversation. No ads, no tracking.   Login or Take a Tour!
comment
caelum19  ·  3312 days ago  ·  link  ·    ·  parent  ·  post: Pubski: November 18, 2015

Assuming I understand what you mean, here's how you'd do it in C:

    #include <windows.h>

    #include <stdio.h>

    int main() {

        printf( "starting to sleep...\n" );

    Sleep( 3000 ); // sleep three seconds

    printf( "sleep ended\n" );

    }

And this is how you would do it in Java

    package ...

    public class SleepExample{

      public static void main(String[] args){

    System.out.println("Starting to sleep");

    try{

    Thread.sleep(1000); // Sleep 3 seconds

    }catch(InterruptedException e){

    e.printStackTrace();

    }

    System.out.println("Sleep ended");

    }

As you can see, Java's is bigger, but I've made a shitty gifv to demonstrate that it's not really a problem when you're using an IDE like IntelliJ IDEA http://i.imgur.com/XUPWXeb.gifv

Edit: The program actually sleeps 1 second because I'm an idiot

Another thing to note is

    #include <windows.h>
in the C version, this code would only work on Windows(Someone correct me if I'm wrong) and you'd need different implementations for different operating systems, optimized for different CPUs...

If you want to make an alarm that's actually useful, with a GUI etc. Java is defintely the way to go out of the two languages, there's no argument. C is pretty old, it's very fast and very low-level, which will mean you will need to reinvent the wheel pretty often, but also you're not limited(Very rarely a concern, but you will know when it will be). C is better for a few very specific tasks, but that's about it.

However, the answer to that question when it isn't limited to just Java and C will depend on who you ask. Personally, I'm conflicted on Java or C# (Leaning slightly toward Java because the JVM is full of potential and mono is pretty slow)

Brackets sounds cool. It's always good to look out for better things though, I was happy using Eclipse and so regret being lazy and not checking out IntelliJ IDEA sooner. Plus, if you're looking for a job, it's good to at least know the basics of an IDE you're likely to use if you get hired.