Search This Blog

If you like any posts in this blog then click this icon which is present under the post

Wednesday, 29 June 2011

Program to get IP address in java

    getLocalHost() function is used to display Name and IP address of local system.
    getByName(" ") function is used to display Name and IP address of a given website.
    getAllByName() function is used to display more than one IP address of  a given website. 

import java.net.*;
public class Main{

    public Main(){
    }
    
    public static void main(String[] args) {
    try
    {    
     InetAddress add= InetAddress.getLocalHost();

Sunday, 5 June 2011

Declarations of Variables

     All variables present in the problem must be declared before it is used. This is done with the help of declaration statement. The general form is

Data-type variable list;
                       Where,
                                  Data-type            -              valid data type such as int, char etc.
                                  Variable unit        -              list of variable separated by comma.

Getting Values of Variables

 The values of the variable are displayed on the VUD by using the following two methods

                     i.            Print ( )
                   ii.            Println ( )

Print ( ) method prints the output on a line until a newline character is encountered.

Println ( ) method prints the output on a line and the control comes to the new line.

Thursday, 2 June 2011

Introduction to Java

     Java is a platform independent object oriented language. It was developed by James Gosling and Patrick Naughton of Sun Microsystems, USA in 1991. 

     It was the first programming language which was not dependent on any particular hardware or operating system. It was initially named as Oak and later renamed as Java in 1995. 

      Java language is to nest suited for developing web based applications.

Charcteristics of Java Program

The following are the important characteristics of java program. They are

1 . Simple, small and familiar
2 . Object oriented
3 . Distributed
4 . Robust
5 . Secure

Java Virtual Machine

      Java compiler compiles the source code and produces a machine independent intermediate code called bytecode. This  code cannot be used dirctly by the computer. This intermediate codes are called java virtual machine (JVM).
      These intermediate codes can be used by any machine with the help of the correct interpreter. The interpreter produces the machine dependent code called machine code can be run by the computer.
       
--->sourcecode--->java compiler--->bytecode--->javainterpreter--->machinecode

     This shows the steps involved in executing a java pragram.

Creating and Executing Java Program

     The following steps are follwed to create and execute a java program.


1 . Create the program using any text editor such as notepad or word pad etc. The general form for saving the created program in a  file is
                                                    
                                               filename.java
                       Where,  
                                     filename - Name of the class containing the main method
                                     java         - Keyword
     Ths file is called source file. If the program has more than one class, the file name must be the name of the main class.

Followers