Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Tuesday, 4 October 2016

The InetAddress Class

One of the classes within package java.net is called InetAddress , which handles Internet addresses both as host names and as IP addresses. Static method getByName of this class uses DNS (Domain Name System) to return the Internet address of a  specifi ed host name as an InetAddress object. In order to display the IP address from this object, we can simply use method println (which will cause the object’s toString method to be executed). Since method getByName throws the checked exception UnknownHostException if the host name is not recognised, we must either throw this exception or (preferably) handle it with a catch clause. The following example illustrates this.
Example

import java.net.*;
import java.util.*;
public class IPFinder
{
          public static void main(String[] args)
          {
              String host;
              Scanner input = new Scanner(System.in);
              InetAddress address;
              System.out.print("\n\nEnter host name: ");
              host = input.next();
                       try
                        {
                           address = InetAddress.getByName(host);
                           System.out.println("IP address: "
                                                     + address.toString());
                       }
                      catch (UnknownHostException uhEx)
                      {
                         System.out.println("Could not fi nd " + host);
                      }
          }
}

Saturday, 24 September 2016

Why Java Programming language has been named as Java?

What is Java?

Everyone who has a brief knowledge of computer is familiar with Java. Java, the most widely used object oriented programming language nowadays.
Here is a brief introduction to java.
Java is an Object Oriented Programming language released by Sun Microsystems in 1995. Now java has reached to its peak time. A team of engineers initiated it, known as Green team. Java is fast,secure and reliable language.

Why it is java?

Originally java was called Oak, after the tree that stood outside of Gosling’s office, the name was changed because of a copyright already owned by Oak technologies. Other names that were considered were Green, DNA, Silk, Neon, Pepper, Lyric, NetProse, WRL (WebRunner Language), WebDancer, and WebSpinner. The team was looking for something fresh and wanted to avoid so called “nerdy names” with Net or Web in them. It is highly contested who actually suggested the name Java, which reflected the teams’ love for coffee.

Friday, 2 September 2016

Introduction to Object Oriented Programming Language


With the improvement in technology, the trends of programming languages have shifted towards the Object Oriented Programming(OOP). Here I tried to explain classes and Objects in java.
Object oriented programming means any kind of programming language which uses some object oriented concepts. In OOP, programmer not only define the data types of data structure but also the functions to be performed. In this way, data structure becomes an object which includes data and function. Examples of Object oriented languages are C++, Java etc.
Main concepts of OOP

Some of the main concepts of Object Oriented Programming are:
1.    Classes
2.    Data Abstraction
3.    Information Hiding
4.    Inheritance
5.    Polymorphism
6.    Encapsulation

Java classes
I will explain the concept of classes in java here. A class is a blueprint or prototype from which objects are created. This section defines a class that models the state and behavior of a real-world object. It intentionally focuses on the basics, showing how even a simple class can cleanly model state and behavior. A class contain data members and functions. A class defines all the common properties of object that belong to it.

Example of class in java
For example you want to write a class of car in java. As I stated earlier class is simply a prototype of real world object. So first think about the car for which you have to write a class.
A car has some properties, like car is of red color, car has some price and other in the same way. These properties are data members for which you have to write functions or operations or some action of real world. Like if you want to know car color, you have to write a function which will return color of the cars. That's it. Here a sample of class is given below:
public class car{
String color;
double price;
String model;
String getCarColor(){
}
double getCarPrice(){
}
}

 Defining a class


Variable types in a class

A class can contain any of the following variable types.
  • Local variables: Variables defined inside methods, constructors or blocks are called local variables. The variable will be declared and initialized within the method and the variable will be destroyed when the method has completed.
  • Instance variables: Instance variables are variables within a class but outside any method. These variables are initialized when the class is instantiated. Instance variables can be accessed from inside any method, constructor or blocks of that particular class.
  • Class variables: Class variables are variables declared with in a class, outside any method, with the static keyword.
A class can have any number of methods to access the value of various kinds of methods. In the above example, barking(), hungry() and sleeping() are methods.

Tuesday, 30 August 2016

Why Java Programming language has been named as Java?

What is Java?

Everyone who has a brief knowledge of computer is familiar with Java. Java, the most widely used object oriented programming language nowadays.
Here is a brief introduction to java.
Java is an Object Oriented Programming language released by Sun Microsystems in 1995. Now java has reached to its peak time. A team of engineers initiated it, known as Green team. Java is fast,secure and reliable language.

Why it is java?

Originally java was called Oak, after the tree that stood outside of Gosling’s office, the name was changed because of a copyright already owned by Oak technologies. Other names that were considered were Green, DNA, Silk, Neon, Pepper, Lyric, NetProse, WRL (WebRunner Language), WebDancer, and WebSpinner. The team was looking for something fresh and wanted to avoid so called “nerdy names” with Net or Web in them. It is highly contested who actually suggested the name Java, which reflected the teams’ love for coffee.