Java
It’s a programming language just like c and c++.But differs
in terms of OOP’s concepts ….java is completely object oriented…
Object oriented means you cannot use main () function
directly as you use in c/c++ ….c++ also follow OOP’s but partially that is why
you can use main () function as well as class both.
Java is most popular programming language used in almost
every thing.
HISTORY ABOUT JAVA:
DEVELOPED BY: James Gosling at Sun Microsystems in 1990.
OLD NAME: Oak.
RE-NAMED: Java in 1995.
HOW TO INSTALL AND USE:
You can download the latest version java from website of
java that you can search with the help of www.Google.com
.
Remember about your operating system if you are using Windows
Os like Windows Xp /Windows7/8 than download java for Windows . . .if you are
using any other than download according to your operating system.
As you complete the Download Run the setup….
Then follow the instructions…………
After you complete the Installation :
Go to the Directory where you install java and copy address
from address bar at BIN
Ex. “C:\Program Files\Java\jdk1.7.0\bin” after copying that address..
·
Right click on My Computer
·
>Properties
·
>Advanced system settings
·
>Environment Variables
·
>new
·
>in Variable name :you can use any variable
like java, path etc.
·
>in Variable Value: just past the
address “C:\Program
Files\Java\jdk1.7.0\bin”
·
>ok
·
>ok
·
>ok
Now go to command prompt and type java
you get a lots of information about java that means your system is ready
for use…..
EDITOR FOR JAVA:
There are lots of java editor available…
Like:
Jcreator
2. Editplus
3. Netbeans
4. Notepad++
5. Eclipse IDE
But the simplest one are:
Notepad or command prompt editor
1.
If you are using Note pad than use extension of
file as
“your_file_name.java”
2.
You can also use command prompt editor
For that :
·
Go to your java installed directory in command
prompt
·
Ex.
·
C:\Program Files\Java\jdk1.7.0\bin
·
Then type edit “your_file_name.java”
·
C:\Program Files\Java\jdk1.7.0\bin edit
hello.java
·
For Working with command prompt you need to know
about few basic commands
Commands of DOS(Disk Operating System)
cd.. –for change the root
directory
Ex.
C:\Program Files\Java\jdk1.7.0\bin>
cd..
Out put
C:\Program Files\Java\jdk1.7.0>
cd/ -for jump to
Ex.
C:\Program Files\Java\jdk1.7.0\bin>
cd/
Out put
C:\>
Drive_name: -for changing working Drive
C:\Program Files\Java\jdk1.7.0\bin>
d:
Out put
D:\>
cls -command for clear screen to clear your
command prompt screen.
How to Execute/Run java program
Java programs Executed in two steps Interpreted and then
run/executed ….
For interpreter java program –
C:\Program Files\Java\jdk1.7.0\bin>javac “filename.java”
For run-
C:\Program Files\Java\jdk1.7.0\bin>java classname
Note:- Here the class name is the name of class that you are
used in file
Example:
//To print hello to java
file name- hello.java
class hello
{
public static void main(String a[])
{
System.out.println(“hello”);
}
}
Explanation of program:
C:\Program Files\Java\jdk1.7.0\bin>javac hello.java
Note: if any kind of error present in your program than,
that is shown as error. If not than it return to the current directory.
C:\Program Files\Java\jdk1.7.0\bin>java hello
Out put will be: hello
Points to remember:-
- · Try to use same name for file name and class name. You can use different name also ,but careful while execution/running the program
- · Public static void main---all are in small letter But String uses Capital ‘S’ similarly in System.out.println()
- · You can use System.out.println() or print() :- println() print with new line while print() print with same line.