Posts

Showing posts from January, 2011

Class and Call Functions

Image
Program is written in Notepad File.....  The Program below u see in pic form. there is a class defined. In class there are two functions "Setdata" and "getdata". Setdata function is for input data from main program througs arguments and store it in variables. Getdata Function is for print the variable values... Now Save the program in C:\Program Files\JAVA\jdk1.6.0_u23\bin Then 1. Click Start > Run 2. Type "CMD" > OK 3. the Command Prompt will apear... 4. Open the jdk directory. like C:\Program Files\Java\jdk1.6.0_23\bin 5. Type "javac FileName.java". If there is any Errors in your Program. u will see in command prompt. 6.  To Execute Program type "java Filename" ( No extension. like .java) 7. Example Shown Below

Add Two Numbers in JAVA

Image
In this section, you will learn to work with command prompt arguments provided by the user. We will access these arguments and print the addition of those numbers. In this example, args is an array of String objects that takes values provided in command prompt. These passed arguments are of String types so these can't be added as numbers. So to add, you have to convert these Strings in numeric type ( int , in this example). Integer.parseInt helps you to convert the String type value into integer type. Now you can add these values into a sum variable and print it on the console by println() function. Here is the code of program: public class  AddNumbers{    public static void  main(String[] args) {     System.out.println("Addition of two numbers!");      int  a = 5 ;      int  b...

Class in JAVA

In this section, we will discuss about java classes and its structure. First of all learn:  what is a class in java and then move on to its structural details.  Class: In the object oriented approach, a class defines a set of properties (variables) and methods. Through methods certain functionality is achieved. Methods act upon the variables and generate different outputs corresponding  to the change in variables. Structure for constructing  java program: package package_name; //import necessary packages import package_name.*; Access Modifier class class_nam e{ member variables ; member method s; public static void main(String[] args) {          ...          ... .        } } package: In the java source file you generally use the package statement at header of a java program. We use ...

Variables in JAVA

In this section, you will learn about Java variables . A variable refers to the memory location that holds values like: numbers, texts etc. in the computer memory. A variable is a name of location where the data is stored when a program executes. The Java contains the following types of variables: Instance Variables (Non-static fields): In object oriented programming, objects store their individual states in the "non-static fields" that is declared without the static keyword. Each object of the class has its own set of values for these non-static variables so we can say that these are related to objects (instances of the class).Hence these variables are also known as instance variables . These variables take default values if not initialized.     Class Variables (Static fields): These are collectively related to a class and none of the object can claim them  its sole-proprietor . The variables defined with static keywo...

Create First Program

Image
In this section, you will learn to write a simple Java program. For developing a java program you just need  a simple text editor like "notepad".  Open the notepad and write your program. Let's create a class createfirstprogram that will print a message "Welcome to IntelligentProgrammer.blogspot.com" on the console.  Here is the code of createfirstprogram.java file: class  createfirstprogram{    public static void  main(String[] args) {     System.out.println("Welcome to intelligentprogrammer.blogspot.com");   } } This class contains  public , static and void java keywords (these are pre-defined words in java which carries specific meaning). public keyword specifies the accessibility issues of a class. Here, It specifies that method can be accessed from anywhere. static keyword  indicates that this method can be invo...

Download & Install Java

Image
To compile and run a java program we need to install java platform. JDK (Java Development Kit). JDK is the basic set of tools required to compile and run java programs. This section enables you to download JDK and teaches you the steps to install it. Download and Install JDK (Java Development Kit) The latest version of jdk is 6 (update 1) at the time of writing the tutorial. You can download the latest version of jdk from http://java.sun.com/javase/downloads/index.jsp . Once you download the exe file you can now install it. Just follow as mentioned: To install the jdk, double click on the downloaded exe file (jdk-6u1-windows-i586-p.exe)  Step 1. Double Click the icon of downloaded exe.  You will see jdk 6 update 23 window as shown below. Step 2: Now a " Setup" window opens. click " Next" button to go further. Step 3: Now a "Custom Setup" window  opens. Click " Next " to go further.... ...