Introduction to
Java Programming
·
Object-oriented
programming
·
Multi-threaded Programming
·
Developed by Sun
Microsystems
Java authorà James Gosling, found java in 1991.
Java first
names "Oak" but the copyright
problem to Oak was renamed as "java"in
1995.
Features of Java:
*Simple *Portable
*Object
oriented *Interpreted
*Network-savvy *High performance
*Robust *Multithreaded
*Secure *Dynamic
*Architecture
Neutral
Difference
between JDK, JRE, and JVM
JVM
JVM (Java Virtual
Machine) is an abstract machine. It is called a virtual machine because it
doesn't physically exist. It is a specification that provides a runtime
environment in which Java bytecode can be executed. It can also run those
programs which are written in other languages and compiled to Java bytecode.
The JVM performs the
following main tasks:
- Loads code
- Verifies code
- Executes code
- Provides runtime environment
JRE
JRE is an acronym for
Java Runtime Environment. It is also written as Java RTE. The Java Runtime
Environment is a set of software tools which are used for developing Java
applications. It is used to provide the runtime environment. It is the
implementation of JVM. It physically exists. It contains a set of libraries +
other files that JVM uses at runtime.
The implementation of JVM
is also actively released by other companies besides Sun Micro Systems.
JDK
JDK is an acronym for
Java Development Kit. The Java Development Kit (JDK) is a software development
environment which is used to develop Java applications and applet
. It physically exists. It contains JRE
+ development tools.
JDK is an implementation
of any one of the below given Java Platforms released by Oracle Corporation:
- Standard Edition Java Platform
- Enterprise Edition Java Platform
- Micro Edition Java Platform
The JDK contains a
private Java Virtual Machine (JVM) and a few other resources such as an
interpreter/loader (java), a compiler (javac), an archiver (jar), a
documentation generator (Javadoc), etc. to complete the development of a Java
Application.
Creating a java Application
/*
This is a
simple java program. Call this file Hello World. java.
*/
class HelloWorld{
//Your program begins with a call to main().
public static void main (String args[]){
System.out.println("Hello World!");
}
}
Output
To compile java Program
>javac
filename.java
After
compilation there is no error filename.class file will be created.
To Run java Program
>java
filename.java
Example
>javac
HelloWorld.java
>java
HelloWorld
Comment
line hiding
//-Single
Line Comment - To hide a single line single line comment used
/*......*/-Multi
Line Comment - To hide a multiline multiline comment used
Character
escapes codes,
Escape Meaning
\n New line
\t Tab
\b
Backspace
Variable
Value Storage
Types
of Variables
There are three types of variables in Java:
- local
variable
- instance
variable
- static
variable
1) Local Variable
A variable declared inside the body of the method is called
local variable. You can use this variable only within that method and the other
methods in the class aren't even aware that the variable exists.
A local variable cannot be defined with "static"
keyword.
2) Instance Variable
A variable declared inside the class but outside the body of the
method, is called an instance variable. It is not declared as static.
It is called an instance variable because its value is
instance-specific and is not shared among instances.
3) Static variable
A variable that is declared as static is called a static
variable. It cannot be local. You can create a single copy of the static
variable and share it among all the instances of the class. Memory allocation
for static variables happens only once when the class is loaded in the memory.
0 comments:
Post a Comment