Java is
a high level Programming language. Java program interpreted by a program called
Java Virtual Machine (JVM). Before it is interpreted by the JVM, the java compiler
compile java source codes contain in java file into class file. Java is a
platform independent language. Because of the JVM. And also it is an Object
Oriented Language.
You can use editor like Notepad or
Notepad++ or IDE like NetBeans or Eclipse.
In java source file there can be three
type of top level piece of codes. They are Package declaration, Import
statement and Class statement. In .java file there should be only one public
class declaration and that class name should be the name of the file. It is
legal to have many classes in a file but exactly only one public class.
Package is used to organize the file
into different directories according to their functionality, usability and
category. Same class name cannot use again in a package. But same name can use
in different package.
If you want access a class in
different package, you have to use the full qualified name for that class.
Eg:- public class exercise{
java.util.ArrayList
myArray = new java.util.ArrayList();
}
But once you import the package in to
your class no need to use full qualified name.
Eg:-import java.util.*;
public class exercise{
ArrayList myArray = new ArrayList();
public static void main(String[] arg){
}
}
Class is a temple (blue print) for
objects. It has class declaration which contain name of the class and some
other attributes such as access level and class body which contains methods,
variables and program logic.
An object is created from a class and
that process is called as instantiation.
Methods denote the behaviors of the object.
It also contains the method declaration and method body.
Method name and parameter list together
consider as method signature.
Main method is the entry point for the
program.
public static void main(String[] arg){
}
When program execute, it search for
main method. When you type some arguments in execute command, I’ll take for arg
string array.
Variable represent a value in the
memory and you can change the value without changing the variable’s name.It has
a declaration which contains the data type and variable name.
int count = 10;
String name = "Kamal";
There are two main data
types. They are primitive and non primitive data types. Non primitive data
types are infinity and they are user defined. Primitive variables contain the
primitive values while non primitive values hold non primitive values.
Each variable has a given
name by the programmer. That name is called as identifier. There some rules for identifier to became a
legal identifier. The first character of the identifier must be a letter, a dollar
sign($) or underscore(_) .A character other than first on, may be a letter, a
dollar sign, a underscore or a digit.
Key words are reserved words. You can
not use key words as identifiers. All the key words are lower cases. Followings
are key words.
abstract
|
continue
|
for
|
new
|
switch
|
assert
|
default
|
goto
|
package
|
synchronize
|
break
|
do
|
if
|
private
|
this
|
byte
|
double
|
implements
|
protected
|
throw
|
case
|
else
|
import
|
public
|
throws
|
catch
|
enum
|
instanceof
|
return
|
try
|
char
|
extends
|
int
|
short
|
transient
|
class
|
final
|
interface
|
static
|
void
|
const*
|
finally
|
long
|
strictfp
|
volatile
|
boolean
|
float
|
native
|
super
|
while
|
There are some important things you have to know before your hands get dirty with codes.