Welcome to the RaGEZONE - MMORPG development forums.

[Java] A Console Application.. (#1)

This is a discussion on [Java] A Console Application.. (#1) within the Coders' Paradise forums, part of the Evolution : RaGEZONE category; Next: [Java] An IO Class (#2) Java isn't recommended as a first programming language. So if you've never programmed before, ...

Results 1 to 12 of 12
  1. #1
    :-)
    Rank
    Alpha Member
    Join Date
    Jun 2007
    Location
    Next Door
    Posts
    2,039
    Liked
    388

    [Java] A Console Application.. (#1)

    Click
    Next: [Java] An IO Class (#2)

    Java isn't recommended as a first programming language. So if you've never programmed before, Java probably isn't for you.

    I'd suggest starting with a scripting language, or one with an easier flow and syntax- like Python.

    For beginner programmers, complicated syntax and a bunch of vocabulary isn't a good thing- it means months and months of bookwork about shit you don't even know yet.

    So, I'm not going to explain all that "shit you don't even know yet", since Java, is not good for beginner programmers, IMHO.



    So here's your console application. I'm assuming you have the JDK, and some "JDE", (Java IDE)- like Eclipse or Netbeans. As far as I know, they work on all stable operating systems- even Minix. (Yeah, I went there). And that's one of the great things about Java- it just works, and doesn't take too kindly to system-dependent crap. That's what (helps) keep it working on almost all systems.


    Create a file called "hello_world.java" with the following code inside it:

    PHP Code:
    // use the scanner library
    import java.util.Scanner;

    // Create a class with a descriptive name
    class hello_world 
    {
        
    // Create a method named "main" of type" void"
        // with that special argument that can take console
        // commands
        
    public static void mainString args[] )
        {
            
    // Make a string prompting the user to type something
            
    String greeting "Say Something:";
            
            
    // Print the string "greeting" above
            
    System.out.printlngreeting );
            
            
    // Take some input
            
    Scanner in = new ScannerSystem.in );
            
            
    // Add the first line of input to a string
            // named "something"
            
    String something in.nextLine();
            
            
    // Print the string "something"
            
    System.out.println"You Said: " something );
        }

    Then open up a terminal or a command prompt. 'cd' means Change Directory. Use cd to navigate to your file in your filesystem. If you saved it in a folder called "java" on your Desktop, for example, you can type (assuming your Desktop directory is inside "/home/john_doe/Desktop"). If you need to do some browsing, the "dir" command will show you all the files/folders in whatever directory you're in. So if you're in "C:\", typing "dir" would show you "windows", "Documents and Settings", or whatever you have in "C:\".
    Code:
    Example:
    cd /home/john_doe/Desktop/java
    dir
    hello_world.java
    Once you're in the directory with "hello_world.java", simply type (on the console):
    Code:
    javac hello_world.java
    That will compile your java program or present you with an error message if something prevents it from compiling properly.

    To run your java program, simply type:
    Code:
    java hello_world
    And the program will run.


    If you haven't noticed, Java requires instant knowledge of Object Oriented Programming. So you need to know that before learning Java.

    The syntax is fairly easy for any OOP-competent programmer/scripter, so, have at it.



    Static methods/variables in Java are basically, easier to use, because you don't have to include the class name in order to call the method/variable.

    Notice this example:
    PHP Code:
    // use the scanner library
    import java.util.Scanner;

    // Create a class with a descriptive name
    class hello_world 
    {
        
    // Reserve this string for input
        
    public static String input;
        
        
        
    // Create a method named "main" of type" void"
        // with that special argument that can take console
        // commands
        
    public static void mainString args[] )
        {
            
    // Make a string prompting the user to type something
            
    String greeting "Say Something:";
            
            
    // Print the string "greeting" above
            
    outputgreeting );
            
            
    // Take some input
            
    input();
            
            
    // Print the string "input" which was defined in the.. 
            // (for lack of better word..) "main" scope of the class.. 
            // Not to be confused with this "main" method in this class.
            
    output"You Said: " input );
        }
        
        
        public static 
    void input()
        {
            
    // Create Scanner for Input
            
    Scanner in = new ScannerSystem.in );
            
            
    // Fill input String with a line of data from Input Scanner
            
    input in.nextLine();
        }
        
        
        public static 
    void outputString out )
        {
            
    // Print a line of output to console
            
    System.out.printlnout );
        }

    Trying the above without the "static" keyword for the String input, and the methods "input()" / "output()" will need some tinkering.


    Exercise 1.1:
    As an exercise, figure out what tinkering needs to be done for the three static elements I noted in this paragraph.

    Answer:
    ( Did you research (search google) first, before clicking this button? )
    Spoiler:

    PHP Code:
    // use the scanner library
    import java.util.Scanner;

    // Create a class with a descriptive name
    class hello_world 
    {
        
    // Reserve this string for input
        
    public String input;
        
        
        
    // Create a method named "main" of type" void"
        // with that special argument that can take console
        // commands
        
    public static void mainString args[] )
        {
            
    hello_world hello = new hello_world();
            
            
    // Make a string prompting the user to type something
            
    String greeting "Say Something:";
            
            
    // Print the string "greeting" above
            
    hello.outputgreeting );
            
            
    // Take some input
            
    hello.input();
            
            
    // Print the string "something"
            
    hello.output"You Said: " hello.input );
        }
        
        
        public 
    void input()
        {
            
    // Create Scanner for Input
            
    Scanner in = new ScannerSystem.in );
            
            
    // Fill input String with a line of data from Input Scanner
            
    this.input in.nextLine();
        }
        
        
        public 
    void outputString out )
        {
            
    // Print a line of output to console
            
    System.out.printlnout );
        }



    And there you have it, a very simple console application written in Java that you can all play with until I come back and make more.

    (Feel like this, , still?
    Told you it wasn't for beginner programmers.)



    Next: [Java] An IO Class (#2)
    Last edited by s-p-n; 22-05-11 at 11:09 AM.

  2. #2
    Newbie
    Rank
    Member
    Join Date
    Jul 2012
    Location
    Kailua, Hawaii
    Posts
    4
    Liked
    1
    Gamertag: Scoin0

    Re: [Java] A Console Application.. (#1)

    "Java isn't recommended as a first programming language. So if you've never programmed before, Java probably isn't for you."

    Then what is? Java is my first language and I'm starting to learn it very well. (Thank you Minecraft)
    I clean my dishes with...wubs...


  3. #3
    Trust your senses
    Rank
    Subscriber
    Join Date
    Sep 2009
    Location
    Netherlands
    Posts
    709
    Liked
    206
    Steam ID: Gravious_
    Quote Originally Posted by Scoin0 View Post
    "Java isn't recommended as a first programming language. So if you've never programmed before, Java probably isn't for you."

    Then what is? Java is my first language and I'm starting to learn it very well. (Thank you Minecraft)
    Isn't recommended. There are tons of tutorials for Minecraft-based Java projects so that's why you may get it fairly well.

    I believe I started with Visual Basic because it was simple English in which you programmed. After PHP and Python I learned C# which looks similar to Java on some subjects so in the end Java was cake.

    Edit: Wew. Necro'd
    Last edited by Gravious; 20-07-12 at 10:06 AM.
    Let us never negotiate out of fear. But let us never fear to negotiate.

  4. #4
    Newbie
    Rank
    Member
    Join Date
    Jul 2012
    Location
    Kailua, Hawaii
    Posts
    4
    Liked
    1
    Gamertag: Scoin0

    Re: [Java] A Console Application.. (#1)

    Quote Originally Posted by Gravious View Post
    Isn't recommended. There are tons of tutorials for Minecraft-based Java projects so that's why you may get it fairly well.

    I believe I started with Visual Basic because it was simple English in which you programmed. After PHP and Python I learned C# which looks similar to Java on some subjects so in the end Java was cake.
    I started with Java because I wanted to create my own games. Learning that Minecraft was created with Java I chose it. But now I'm learning C++, HTML, and CSS. But being that C# is closer to Java I think it might be good for me.
    I clean my dishes with...wubs...


  5. #5
    Psychedelic & Dubstep <3
    Rank
    Member +
    Join Date
    Mar 2012
    Location
    Germany
    Posts
    422
    Liked
    58

    Re: [Java] A Console Application.. (#1)

    Quote Originally Posted by Scoin0 View Post
    I started with Java because I wanted to create my own games.
    infact, java is a bad choice for games, its very slow. however, notch proved its possible, still, saying to learn java for games is ridiculous.

  6. #6
    Admnistrator
    Rank
    Member +
    Join Date
    Aug 2010
    Posts
    640
    Liked
    197

    Re: [Java] A Console Application.. (#1)

    Quote Originally Posted by VibeTribe View Post
    infact, java is a bad choice for games, its very slow. however, notch proved its possible, still, saying to learn java for games is ridiculous.
    Look at RuneScape, it's running on Java.
    C/C++/PHP,OOP/MySQL/Java/JS/HTML/HTML5/CSS/AJAX

  7. #7
    Trust your senses
    Rank
    Subscriber
    Join Date
    Sep 2009
    Location
    Netherlands
    Posts
    709
    Liked
    206
    Steam ID: Gravious_

    Re: [Java] A Console Application.. (#1)

    Quote Originally Posted by WizCoder View Post
    Look at RuneScape, it's running on Java.
    RuneScape and Minecraft aren't the best graphical games though. The good thing about those games are that they don't really need those graphics.
    Let us never negotiate out of fear. But let us never fear to negotiate.

  8. #8
    Newbie
    Rank
    Member
    Join Date
    Jul 2012
    Location
    Kailua, Hawaii
    Posts
    4
    Liked
    1
    Gamertag: Scoin0

    Re: [Java] A Console Application.. (#1)

    Quote Originally Posted by VibeTribe View Post
    infact, java is a bad choice for games, its very slow. however, notch proved its possible, still, saying to learn java for games is ridiculous.
    I'm not gonna base all my games in Java. I just want to learn it. I have however been told that Java sucks and why am I choosing it to start creating games. T.T

    Quote Originally Posted by Gravious View Post
    RuneScape and Minecraft aren't the best graphical games though. The good thing about those games are that they don't really need those graphics.
    I'm sure Java can do some nice graphical games...I'm created a game that doesn't really need graphics so..I'm ok :D I would love to learn C++ though
    I clean my dishes with...wubs...


  9. #9
    Ginger by design.
    Rank
    Alpha Member
    Join Date
    Feb 2007
    Posts
    2,796
    Liked
    710

    Re: [Java] A Console Application.. (#1)

    Quote Originally Posted by WizCoder View Post
    Look at RuneScape, it's running on Java.
    Both RuneScape and Minecraft could be written more quickly JavaScript with better graphics and still run better. And they'd have support across almost every desktop and most phones/tablets.

    What an interesting world we live in, where Javascript takes the ubiquity crown, even though Java was born for it.
    jmerlin.MSN = "jmerlin[at]jmerlin[dot]net";

    var c = 1; c++ < c; // true

  10. #10
    :-)
    Rank
    Alpha Member
    Join Date
    Jun 2007
    Location
    Next Door
    Posts
    2,039
    Liked
    388

    Re: [Java] A Console Application.. (#1)

    Java does kinda suck.. I code everything I need in EcmaScript5 these days....

  11. #11
    Registered
    Rank
    Member
    Join Date
    Dec 2011
    Posts
    8
    Liked
    2

    Re: [Java] A Console Application.. (#1)

    If you want to create games, I recommend learning RGSS.

  12. #12
    ┌∩┐(◣_◢)┌∩
    Rank
    Alpha Member
    Join Date
    Jun 2008
    Location
    Quebec
    Posts
    2,124
    Liked
    176

    Re: [Java] A Console Application.. (#1)

    I think it's funny how people compare coding to graphical images. The graphic part has nothing to do with the codes, it has all to do with the artistic method one puts into it. This is like comparing Images to Videos, either one will look like shit if there's isn't any real artistic talent put behind it.

    I'm actually interested in learning java for multiple reasons, and one of them being cross platform.

    -o)
    /\\
    _\_V
    The Penguin is "ALWAYS WATCHING".. HEHE




 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •