Class in Object Oriented architecture:
- Struct keyword can be replaced by class keyword
- Generally "struct" is used in ‘C’ context while "class" is used in Java context
- In a Java class functions can be clubbed together in a class along with the data members
- class and object is Object Oriented terminology
- A class is a template for the creation of like objects
- An object is an instance of a class
- Map real world entities into classes through data members & member functions
- By writing class & creating objects of that class one can map two major pillars of object model i.e. abstraction & encapsulation into software domain
Example 1:
class class-name
{
variable declaration ;
method declaration ;
public static void main(String args[ ])
{
……..
} } // end of class
Running java program:
The java program can be written in notepad file or some tools are also available on for developing java programs like – EditPlus, JCreator, KAWA software, etc. To run a java program, the programmers need to install java set up JDKVersion1.1 or later. Just perform following tasks to run a Java program.
Steps
- Install JDK1.1 or later, which is freely available on www.sun.com
- After installing JDK, create a folder where you are supposed to save your Java programs. For e.g., c:\Java.
- Now open notepad file and write Java code as shown below:
Example 2:
class Hello
{
Public static void main(String [] args)
{
System.out.println(“Welcome, to Java world”);
}
}
Write the code as shown above, now save the file where you have created folder for saving java programs. For e.g. c:\Java. - When you click on SAVE option the window is displayed. Select the path where you want to save your program. The default selection of “Save As Type” in the window is “Text Documents (.*txt)”. Make that option as “All Files”.
- Always make sure that the name of the saving file must be same as to the name of class in which the main function is written. For e.g., as shown in above code, the name of class is Hello. So save the file name of the program as Hello. The name must match with class name and is case-sensitive.
- Save the File name as Hello.java at selected path.
- Look at the folder where your program is saved and check whether it is saved as JAVA file or Text file. If it is saved as Text file then repeat step 5-6 again. If it is saved as JAVA File then your java program is ready for execution.
- Now the important and some what irritating task is going to explain. To run java program, it is very necessary task you have to perform. First go to My Computer properties, select option Advanced, then Environmental Variables. One more window is opened. In that window System Variables includes one variable of the name “Path” and its value. Double click on that or click and Select Edit option, one more window is displayed. Without making any changes to previous variable value of the path, you have to add path value of Java BIN. But be careful that the previous value should not be changed, it records system path.
- Now go to c:\Program Files\Java.
- Click on folder JDK, not on JRE. After entering into JDK folder, click on bin.
- Now just copy the path as displayed in the address bar of C-drive. For e.g., C:\Program Files\Java\jdk1.5.0_01\bin.
- After coping the path again come to properties of My Computer and just paste the path of Java in the Path value separated by semicolon “;”. For e.g., ;C:\Program Files\Java\jdk1.5.0_01\bin.
- After that click on OK-OK-OK.
- Now your system is aware of path of java bin.
- To run Java program, open command prompt. Go to the folder where you have saved your JAVA program through command prompt. For e.g., c:\Java.
- Now type javac
.java , as it is to compile your program. - Now type java
to run Java program.
The output will appear in the command prompt.
No comments:
Post a Comment