"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)
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, ...
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:
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:\".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 main( String args[] )
{
// Make a string prompting the user to type something
String greeting = "Say Something:";
// Print the string "greeting" above
System.out.println( greeting );
// Take some input
Scanner in = new Scanner( System.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 );
}
}
Once you're in the directory with "hello_world.java", simply type (on the console):Code:Example: cd /home/john_doe/Desktop/java dir hello_world.java
That will compile your java program or present you with an error message if something prevents it from compiling properly.Code:javac hello_world.java
To run your java program, simply type:
And the program will run.Code:java hello_world
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:
Trying the above without the "static" keyword for the String input, and the methods "input()" / "output()" will need some tinkering.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 main( String args[] )
{
// Make a string prompting the user to type something
String greeting = "Say Something:";
// Print the string "greeting" above
output( greeting );
// 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 Scanner( System.in );
// Fill input String with a line of data from Input Scanner
input = in.nextLine();
}
public static void output( String out )
{
// Print a line of output to console
System.out.println( out );
}
}
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:
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.
"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...
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.
I clean my dishes with...wubs...
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
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...
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
Java does kinda suck.. I code everything I need in EcmaScript5 these days....
If you want to create games, I recommend learning RGSS.
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
Spoiler: