Brief History of Java
Brief History of Java
Brief History of Java
a. Portability: Java is a highly portable programming language because it is not designed for any
specific hardware or software platform. Java programs once written are translated into an
intermediate form called bytecode. The bytecode is then translated by the Java Virtual Machine (JVM)
into the native object code of the processor that the program is been executed on. JVMs exist for
several computer platforms; hence the term Write Once Run Anywhere (WORA).
b. Memory Management: Java is very conservative with memory; once a resource is no longer
referenced the garbage collector is called to reclaim the resource. This is one of the elegant features
that distinguishes Java from C/C++ where the programmer has to “manually” reclaim memory.
c. Extensibility: The basic unit of Java programs is the class. Every program written in Java is a class
that specifies the attributes and behaviors of objects of that class. Java APIs (Application Programmers
Interface) contains a rich set reusable classes that is made available to the programmers. These
classes are grouped together as packages from which the programmer can build new enhanced
classes. One of the key terms of object oriented programming is reuse.
d. Secure: Java is a very secure programming language. Java codes (applets) may not access the
memory on the local computer that they are downloaded upon. Thus it provides a secure means of
developing internet applications.
e. Simple: Java’s feature makes it a concise programming language that is easy to learn and
understand. It is a serious programming language that easily depicts the skill of the programmer.
f. Robustness: Java is a strongly typed programming language and encourages the development of
error free applications.
COMMENT
The next part of the program is the declaration of the main method. Methods are used for carrying
out the desired tasks in a Java program, they are akin to functions used in C/C++ programming
languages. The listing:
public static void main( String[] args )
{
}
is the main method definition header. It starts with the access modifier public, followed by the
keyword static which implies that the method main ( ) may be called before an object of the class
has been created. The keyword void implies that the method will not return any value on completion
of its task. These keywords public, static, and void should always be placed in the sequenced shown.
THE BASIC STEPS FOR COMPILING AND EXECUTING A JAVA PROGRAM ARE:
a) Enter the source code using a text editor. The file must be saved using the file extension .java.
b) Use the Java compiler to convert the source code to its bytecode equivalent. The byte code will
be saved in a file having the same name as the program file with an extension .class. To
compile our HelloWorld.java program, type the following instructions at the Windows command
prompt (c:\>): javac HelloWorld.java The bytecodes (.class file) will be created only if there are
no compilation errors.
c) Finally use the Java interpreter to execute the application, to do this at the Windows command
prompt (c:\>) type: java HelloWorld. (You need not type the .class extension)
2
Using Simple Graphical User Interface Apply Graphical Classes
import javax.swing.JOptionPane;
public class HelloWorldGUI {
public static void main(String[] args) {
String msg = “WELLCOME";
String ans ="";
JOptionPane.showMessageDialog(null, msg );
ans = JOptionPane.showInputDialog( null, "Enter your Name Please");
JOptionPane.showMessageDialog(null, "Hello " + ans );
} // end method main
} // end of class HelloWorldGUI
PSEUDOCODE
Pseudocode is an informal language that helps programmers develop algorithms without having to
worry about the strict details of Java language syntax. The pseudocode we present is particularly
useful for developing algorithms that will be converted to structured portions of Java programs.
Pseudocode is similar to everyday Englishit is convenient and user friendly, but it is not an actual
computer programming language.
TYPES OF ERROR
• Syntax errors (e.g., when one brace in a block is left out of the program) are caught by the
compiler.
• logic error (e.g., when both braces in a block are left out of the program) has its effect at
execution time.
• fatal logic error causes a program to fail and terminate prematurely.
• Nonfatal logic error allows a program to continue executing, but causes the program to
produce incorrect results.
PSEUDOCODE: GENERATE AND CALCULATE THE SUM OF THE FIRST TEN NUMBERS FROM
1 TO 10
FIRST PSEUDOCODE:
Step1: Initialize variables
Step2: Generate numbers from 1 to 10
Step3: Calculate sum of the numbers
Step4: Display numbers and sum
Step5: Stop.
The order in which the expressions are evaluated is referred to as their association. Now let us
consider some examples in the light of the rules of operator precedence; we will list both the
algebraic expression and the equivalent java expression.