First download and install tha Java development Kit from here : http://java.sun.com/javase/downloads/index.jsp
Make sure you installed it right like this :Click Start->run
Then write "cmd" and press enter. In the console window write "java -version" and press enter again. If you don't get an error then you made the first step :).
Download and install an IDE(Integrated Development Environment) or simpler : "the program where you write the code".Here are some choices :
Eclipse (big IDE written in java)-it's great but it's pretty big so you need a strong computer for it. Take it from here :http://www.eclipse.org/
Netbeans(big IDE written in java)-same as at Eclipse. You might have installed the JDK with bounded with this one. If not get it from here : http://www.netbeans.org/
JCreator(written in C++)-small and fast.It's a commercial software but you can install the free version of it. It's more than enough for beginning.Here it is : http://jcreator.com/
Now create a file called HelloWorld.java ,open it from the IDE and copy this code there :
public class HelloWorld{
public static void main( String[] args ){
System.out.println( "Hello world" );
}
} Save it. Now you might be able to compile and run it. If you are not then you might need to configure your IDE or just use the command line mode of compiling.
Place your file in a directory (lets say c:\java\source\).
Open a command prompt (Start->run+"cmd" +Enter,remember ? :) )
Write :
cd c:\java\source
"c:\Program Files\jdk1.6.0_03\bin\javac" HelloWorld.java
You might need to change the your path ( c:\Program Files\jdk1.6.0_03\ ) to where the jdk is installed.
Now you just compiled your first java program. All you have to do now is run it .In the same console window write :
java HelloWorld
(must be HelloWorld not HelloWorld.java)
This will output Hello World !
Congratulations you just finished your first java program.
Now try to change your source code then save,compile and run to see what happens.
Change this
System.out.println( "Hello world" );to
System.out.println( "The text changed :) " );run it.
Try this then.
System.out.println( "Hello "+"World !"); Then change it to this
System.out.println( "1+3="+(1+3) ); That's all. Hope you enjoyed it !
No comments:
Post a Comment