An Introduction to Java
Before Java
The programmer’s realm prior to Java was dominated by C/C++. C being the first of the duo gained tremendous popularity among programmers. It was a beautiful and a powerful blend of Low level Assembly language and High level capabilities. Almost anything could be done with C as could be imagined doing with a computer. The situations have however changed over time. Today, C is majorly used in writing code for Device Drivers and other hardware related programs. C though very powerful had its drawbacks. C was a POP (Process Oriented Programming) Language, which means, its programs were mainly centered on the code. This made things difficult when writing huge programs. The programs could not be broken down into chunks and all of the code was vulnerable to external/internal influence. This meant that the first line of the code might interfere with any other portions of the code even though it was not intended for. Thus, the programmer had to keep the complete code in mind while writing it down, a negative point in code manageability.
Things became a little simpler with the advent of C++. The ++ operator is called the increment operator and adds to the meaning of the language: An incremented version of C. C++ basically inherits all the capabilities of C and adds the OOP (Object Oriented Programming) model to it. Thus using C++ one could write the old fashioned C style programs as well as the native C++ (OOP) style programs. Yet, C++ is not a true Object Oriented Language. It is merely a blend of both POP and OOP. One of the many advantages of OOP is that code can be reused. This meant manufacturers or vendors could provide you with numerous pre-written codes in the form of classes ready for use. A class is generally a template or a blueprint of an object. A single class can be used to produce numerous objects each having their own property and behavior. A Class-Object relation is like that of the blueprint/template of BMW M3 GTR and many real BMW M3 GTRs made out of it. C++ soon rose to popularity and became the foremost used language for Software development.
Java
Java was conceived and born at Sun Microsystems (now a property of OracleTM). It was created by James Gosling and was originally called Oak in 1991. The incentive behind Oak was to create a platform-independent, object-oriented language that could run in any popular Operating System and virtually under any hardware configuration. All that was needed was just a JVM (Java Virtual Machine) for the respective OS. The JVM itself would occupy a memory in the RAM and act as a mini-OS.
Oak was renamed Java in 1995, when it was released for the Public. Due to its platform-independent, bytecode model, it was soon popularized as an Internet language. Due to such capabilities of Java, some of the corporations are adopting it internally instead of C++, such as Microsoft’s C#, which is now being modeled after Java.
Let’s get started…
Prerequisites
Before being able to start writing Java programs, there are some petty things to be taken care of first.
- · Download and install the latest (Java SE 6 or later) Java SDK (Software Development Kit) from http://java.sun.com/javase/downloads/index.jsp
- · You can actually start writing programs now. Just launch any Plain-text editor such as Notepad in Windows, then write the program and save the file with .java as extension. (E.g. <myfilename>.java)
- · Before compiling or running the .java file on your computer, make sure your machine can find the Java tools, including the Java compiler itself. To do this you need to set the path to your Java’s bin directory. If you've installed your JDK in the C drive, then the path might look like this: C:\JDK1.6\bin. Here are steps to follow to set up the path.
- · Follow these steps for Windows 2000/Windows XP:
- · Click on Start button and select Settings > Control Panel. Double-click the System icon.
- · In the System properties dialog box, click the Advanced tab and then the Environment Variables button.
- · A new dialog appears. Now click the PATH variable, and then add the Java bin directory to the path. Click OK. Now you’ll be able to use the Java tools directly from the command line.
- · You can also use a Java IDE (Integrated Development Environment) like BlueJ for starters or NetBeans for advanced programmers.
The Language
Java keywords
Keyword
|
Description
|
abstract
|
It specifies that a class or method will be implemented later, in a subclass.
|
boolean
|
Data type that can hold True and False values only
|
break
|
Control statement to break out of loops
|
byte
|
Data type that can hold 8-bit numerical values.
Range: -128 to +127
|
byvalue
|
Not yet implemented
|
case
|
Used in switch-case statements to mark blocks of text
|
cast
|
Not yet implemented
|
catch
|
Catches exceptions cast by try statements
|
char
|
Data type to hold unsigned 16-bit Unicode characters.
Range: 0 to 65,536
|
class
|
Used to declare a new class
|
const
|
Not yet implemented
|
continue
|
Control statement to send control back to the loop
|
default
|
The default block of code in a switch-case statement
|
do
|
Marks the starting of the do-while loop
|
double
|
Data type that can hold 64-bit floating-point numbers.
Range: -1.7E + 308 to 1.7E + 308
|
else
|
An alternative branch of the if-else block
|
extends
|
Indicates that a class or interface is derived from another class or interface respectively
|
final
|
Indicates that the variable is a constant or a method cannot be overridden
|
finally
|
Indicates a block of code in try-catch structure that’ll always be executed
|
float
|
Data type that holds 32-bit floating-point numbers.
Range: -3.4E + 38 to 3.4E + 38
|
for
|
Used to start a for loop
|
future
|
Not yet implemented
|
generic
|
Not yet implemented
|
goto
|
Not yet implemented
|
if
|
A branch of the if-else structure. It tests a true/false expression and branches accordingly
|
implements
|
Specifies that a class implements an interface
|
import
|
References other classes by importing them
|
inner
|
Not yet implemented
|
instanceof
|
Indicates whether an object is an instance of a specific class or implements a specific interface
|
int
|
Data type that can hold 32-bit signed Integer.
Range: -231 to 231 – 1
|
interface
|
Used to declare an Interface
|
long
|
Data type that holds 64-bit Integer.
Range: -263 to 263 – 1
|
native
|
Specifies that a method is implemented with platform-specific code
|
new
|
Used to create new objects
|
null
|
Indicates that a reference does not refer to anything
|
operator
|
Not yet implemented
|
outer
|
Not yet implemented
|
package
|
Used to declare a Java package
|
private
|
An access specifier indicating that a method or variable may be accessed from only within the class it is declared in
|
protected
|
An access specifier indicating that a method or variable may be accessed from only within the class it is declared in or a subclass within the class it is declared in or within other classes in the same package
|
public
|
An access specifier indicating that a method or variable or interfaces etc. may be accessed throughout the application without any restrictions
|
rest
|
Not yet implemented
|
return
|
Sends control or a return value back from a called method
|
short
|
Data type that can hold 16-bit Integer.
Range: -32,768 to 32,767
|
static
|
Indicates that a variable or method is a class variable or class method. Such variables or methods can be accessed directly without creating any objects
|
super
|
Refers to class’s base class
|
switch
|
Statement that executes code based on a test value
|
synchronized
|
Specifies critical sections or methods in multithreaded code. Used when we want a method to work in coordination with other synchronized methods
|
this
|
Refers to the current object in a method or a constructor
|
throw
|
Used to create an exception
|
throws
|
Indicates the type of exception that might be thrown by a method
|
transient
|
Specifies that a variable is not part of an object’s persistent state
|
try
|
Starts the try-catch block to test exception prone statements
|
var
|
Not yet implemented
|
void
|
Specifies that a method does not have a return value
|
volatile
|
Indicates that a variable might change asynchronously
|
while
|
Starts a while loop
|
Comments
Post a Comment