Web crawler in Java

Web crawler in Java :

Definition :

A Web crawler is a computer program that browses the World Wide Web in a methodical, automated manner or in an orderly fashion.

For more information visit the wiki page for Web_crawler

Sample Java Program :

package com.test.main;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;

public class WebCrawler {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
URL url = new URL(“http://blog.iguddy.com/”);
BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
String temp = “”;
while(null != (temp = br.readLine())){
System.out.println(temp);
}
} catch (Exception ex) {
ex.printStackTrace();
}

}

}

 

 

Java Constructor

Java Constructor :

  • Constructor is used to construct an Object and initialize values
  • By default if no constructor is specified in the code then JVM supplies the constructor at run time.
  • The constructor is supplied by JVM is called default constructor.
  • If the developer doesn’t write the constructor explicitly then the JVM provides default constructor.
  • If your constructor is PRIVATE then the Object is created with in that class.
  • All four Access level modifiers are allowed, but non-access modifiers are not allowed.
  • The class name should be the constructor name.
  • this()constructor or super()constructor must be in the first line.
  • This() and super() cannot come together.
  • Super()constructor calls the super class constructor.
    • Example : super() ? calls the super class constructor with no arguments.
    • Super(1001,’mutn’) ? calls the super class constructor with two arguments.
  • This()constructor calls the constructor with in the same class.
    • Example: this() ? calls the empty constructor.
    • This(1001,’mutn’) ? calls the constructor  with two arguments in the same class.
  • Generally the execution of constructor occurs subclass constructor calls super class constructor, which calls it super class and so on.
  • Finally Object constructor executes and return to the calling constructor, which completes and return to its calling constructor and so on.
  • Constructor cannot be inherited.
  • Default constructor is stopped by JVM when you explicitly specify the constructor.
  • JVM explicitly adds super() keyword as the first line, if this() or super() keyword is not given explicitly.
  • Abstract class can also have constructor.

When I go for static method

When I go for static method :

  • To write utility functions
  • A common code is accessed by different type of object
  • To auto generate a value
    • Example : Id’s
  • To count the number of objects
  • To perform operations on state of all objects belongs to same type .
    • Example: swimming, the total salary of all the employees, finding the highest salary among employees.

Java Encapsulation

Java Encapsulation

The following are the key points about Encapsulation.

  1. Wrapping of data and code into a single unit is called Encapsulation.
  2. In Java, the data and the code are encapsulated. The client able to access a field through a getter and setter.
  3. Setters are called mutators; it allows the client to set the data in which owner can write the validation code.
  4. Getters are called assessors; the client is allowed to get the data.

Advantages of Encapsulation

  1. If the owner changes the characteristics, it will not affect all the client codes.
  2. Client cannot access the data directly. So, unambiguous data is avoided.
  3. Tight encapsulation is a good encapsulation. This means owner provides only getter to the clients.

How Encapsulation is achieved ?

We can achieve encapsulation in the following ways by,

  1. Making all the fields as private
  2. Providing getter and setter

History of Java Programming Language

History of Java Programming Language:

Java was developed by James Gosling & his team at Sun Micro systems of USA in the mid of 1991.It was originally called as “Oak”. They started a project called “Green” to demonstrate the application of their new language in 1992.The team developed a Web browser called “Hot Java” to locate and run applet programs on Internet in 1994.In 1995, Oak was renamed as “Java” due to some legal snags.

Flavors of Java:

  • J2SE – Java Platform, Standard Edition
  • J2EE – Java Platform, Enterprise Edition
  • J2ME – Java Platform, Micro Edition

J2SE – Java Platform, Standard Edition:

Java Platform, Standard Edition or Java SE is a widely used platform for development and deployment of portable and versatile applications that are intended for desktop and server environments.

J2EE – Java Platform, Enterprise Edition:

Java Platform, Enterprise Edition or Java EE is Oracle’s enterprise Java computing platform. The platform provides an API and run time environment for developing and running enterprise software, including network and web services, and other large-scale, multi-tiered, scalable, reliable, and secure network applications.

J2ME – Java Platform, Micro Edition:

Java Platform, Micro Edition, or Java ME, is a Java platform designed for embedded systems (mobile devices are one kind of such systems).

Features of Java:

  • Platform Independent
  • Data Security
  • Robustness
  • Multitasking
  • Object oriented
  • Remote Method Invocation
  • Distributed
  • High Performance

 

Java Constructor

Constructor :

  • Constructor is used to construct an Object and initialize values
  • By default if no constructor is specified in the code then JVM supplies the constructor at run time.
  • The constructor is supplied by JVM is called default constructor.
  • If the developer doesn’t write the constructor explicitly then the JVM provides default constructor.
  • If your constructor is PRIVATE then the Object is created with in that class.
  • All four Access level modifiers are allowed, but non-access modifiers are not allowed.
  • The class name should be the constructor name.
  • this()constructor or super()constructor must be in the first line.
  • This() and super() cannot come together.
  • Super()constructor calls the super class constructor.
    • Example : super() ? calls the super class constructor with no arguments.
    • Super(1001,’mutn’) ? calls the super class constructor with two arguments.
  • This()constructor calls the constructor with in the same class.
    • Example: this() ? calls the empty constructor.
    • This(1001,’mutn’) ? calls the constructor  with two arguments in the same class.
  • Generally the execution of constructor occurs subclass constructor calls super class constructor, which calls it super class and so on.
  • Finally Object constructor executes and return to the calling constructor, which completes and return to its calling constructor and so on.
  • Constructor cannot be inherited.
  • Default constructor is stopped by JVM when you explicitly specify the constructor.
  • JVM explicitly adds super() keyword as the first line, if this() or super() keyword is not given explicitly.
  • Abstract class can also have constructor.

If You need more visit our site – www.iguddy.com

When I go for static method

When I go for static method :

  • To write utility functions
  • A common code is accessed by different type of object
  • To auto generate a value
    • Example : Id’s
  • To count the number of objects
  • To perform operations on state of all objects belongs to same type .
    • Example: swimming, the total salary of all the employees, finding the highest salary among employees.

     

If You need more visit our site – www.iguddy.com