IntroductionHere you will learn java in simple steps like a beginner.So let’s start java… with live example for creating simple and interesting games… For running java you have to install small software named JAVA SDK.you know java is platform independent … What is JDK (Java Development Kit)?JDK is a software development program provided by sun Microsystems. Java Development Kit or JDK comes in various versions and can be downloaded free from the sun Microsystems. JVM compiler, debugger and other tools are used with JDK for developing java based application & java applets. So make sure that your JVM compiler & JDK versions are same. JDK also known as Java 2 Platform That comes in three editions J2ME, J2SE & J2EE. If you are beginner or learning Java then start by downloading J2SE. Acronyms: JDK Java Development Kit JVM Java virtual machine Download JDK you can download JDK from www.javasoft.com/j2se
Latest version of JDK 1. JDK 5.0 Update 6 the full internal version number for this update release is 1.5.0_06-b05 (where "b" means "build"). The external version number is 5.0u6. Java Version 1.5.0_06 introduces various security enhancements in Java Plug-in and Java Web Start to better protect users and enterprises. For more information please visit: http://java.sun.com/j2se/1.5.0/ReleaseNotes.html SO let’s start learning java particles… The first program we are going to learn is a simple java application “Hello Java” in which you create a program and run it then it will show a message …
So The first step is Open your notepad and type this program,
public class Hellojava
{
public static void main (String [] args)
{
System.out.println("Hello ! Java");
}
}I suggest you to type this program by your own without seeing this…
Now save this notepad file as “Hellojava.java” ,The point is, you have to save this file by the class name which you have given in the program and you have to use the .java extension
Setting the path
Now you have to do an important task is to set the path for java ,So let’s start . First StepGo to run type sysedit Now type this in the AUTOEXEC.BAT file
SET PATH=C:\WINDOWS\COMMAND;C:\JDK1.3.1\BIN
Or if you install jdk in another drive then give that path,now save and exit Running Application
Open command prompt go in the drive (where you save your notepad file)
Then type__ javac Hellojava.java now run your application__ java Hellojava a message will seem “Hello ! Java” What you did Line of code is a blank line, which as you might imagine, does nothing. Following that is the beginning of your program class definition:
public class HelloWorld { You must define a class in every Java program. Basically, a class is a group of functions and characteristics in Java code that can be reused. The public keyword, used as a modifier that describes other classes’ access to this class, is not required, but it is a good idea to use it anyway. This way you will start off with good coding habits. It is not necessary at this point to fully understand the public keyword. The same goes for the class keyword. It is used to identify Hellojava as a class. The open brace denotes the beginning of the contents of your class definition and the corresponding closing brace (the last line of the program) denotes the end of the class definition. To sum it up, this line of code starts a Java program called Hellojava, and all the code within the braces makes up its guts.
The next line of code starts the main() method definition.
public static void main(String args[]) {
} Methods are groups of statements that are executed by your computer when instructed to do so. You learn about methods in Chapter 5. For now, it is important that you know that the main() method actually drives Java applications. It is the first place the Java VM looks when you run your application. The group of statements within this method, collectively called a block statement, is defined within its own set of braces. Within the braces of this method, you define a list of steps you want the computer to do when running your program. The one statement inside the main() method, which is your next line of code, instructs your computer to say hello to the world.
System.out.println("Hello, world!"); This is actually a call to a method that handles your system’s standard output. It prints one line to the screen and adds a carriage return. You can refer to the Java API documentation for classes System and PrintStream for more detailed information .
Congrats ! now you know the syntax and knowledge about JAVA.
|