A Java Beginner Guide

As with any application,you need to be sure that Java is properly installed on your computer. It comes preloaded on many computers, or you can download it easily.

Creating a Java program : To create a java program, You can use any text editor for this task, or you can use one of the more sophisticated program development environments more popularly known as the Integrated Development environment ( IDE). Some of the popular IDE s are Eclipse, Netbeans, IBM rational application development ( RAD ), Weblogic workshop and many more.

Compiling a program: A compiler is an application that translates a program from the Java language to a language more suitable for executing on the computer. The compiler takes a file with a .java extension as input (your program) and produces a file with the same name but with a .class extension (the computer-language version).

Executing a program: It is even more accurate to say that a part of the Java system known as the Java Virtual Machine (the JVM, for short) directs your computer to follow your instructions. To use the JVM to execute your program, type the java command followed by the program name in a terminal window.

Conditionals and Loops


We use the term control flow to refer to statement sequencing in a program. In this section, we introduce statements that allow us to change the control flow, using logic about the values of program variables. This feature is an essential component of programming.


If statements Most computations require different actions for different inputs. One way to express these differences in Java is the if statement:

if (<boolean expression>)

{ <statements> }

This description introduces a formal notation known as a template that we will use to specify the format of Java constructs. We put within angle brackets (< >) a
construct that we have already defined, to indicate that we can use any instance of that construct where specified.

While loops Many computations are inherently repetitive. The basic Java construct for handling such computations has the following format:

while (<boolean expression>)

{ <statements> }

The while statement has the same form as the if statement (the only difference being the use of the keyword while instead of if), but the meaning is quite different.
It is an instruction to the computer to behave as follows: if the expression is false, do nothing; if the expression is true, execute the sequence of statements (just as
with if) but then check the expression again, execute the sequence of statements again if the expression is true, and continue as long as the expression is true.

For loops As you will see, the while loop allows us to write programs for all manner of applications. Before considering more examples, we will look at an alternate
Java construct that allows us even more flexibility when writing programs with loops. This alternate notation is not fundamentally different from the basic
while loop, but it is widely used because it often allows us to write more compact and more readable programs than if we used only while statements.

Input and Output

A Java program takes input values from the command line and prints a string of characters as output. By default, both command-line input and standard output
are associated with the application that takes commands (the one in which you have been typing the java and javac commands). We use the generic term terminal
window to refer to this application. This model has proven to be a convenient and direct way for us to interact with our programs and data. Command-line input. This mechanism, which we have been using to provide input values to our programs, is a standard part of Java programming. All classes have a main() method that takes a String array args[] as its argument. That array is the sequence of command-line arguments that we type, provided to Java by the operating system. By convention, both Java and the operating system process the arguments as strings, so if we intend for an argument to be a number, we use a method such as Integer.parseInt() or Double.parseDouble() to convert it from String to the appropriate type.

Standard output. To print output values in our programs, we have been using the system methods System.out.println() and System.out.print(). Java puts the results of a programís sequence of calls on these methods into the form of an abstract stream of characters known as standard output. By default, the operating system connects standard output to the terminal window. All of the output in our programs so far has been appearing in the terminal window.

                                                                                                                Next>>




Sandeep Joshi
Mathematics, Technology and Programming are my passion. I am a part of Java Ecosystem and through this blog, I contribute to it. I am here to blog about my interests, views and experiences.
I am on Google+ and Facebook.
I feel proud to be listed as a "National Memory Record Holder" in the Limca Book of Records, 2009 and have attempted for an International Memory record in the Guiness Book of Records. I can remember the value of PI upto 10,000 digits after the decimal (3.1415.....). You can contact me on javagenious.com(At)gmal.com ; I would like to hear from you :)