Posts

Showing posts from January, 2014

Java Encapsulation

Java Encapsulation The following are the key points about Encapsulation. Wrapping of data and code into a single unit is called Encapsulation. In Java, the data and the code are encapsulated. The client able to access a field through a getter and setter. Setters are called mutators; it allows the client to set the data in which owner can write the validation code. Getters are called assessors; the client is allowed to get the data. Advantages of Encapsulation If the owner changes the characteristics, it will not affect all the client codes. Client cannot access the data directly. So, unambiguous data is avoided. 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, Making all the fields as private Providing getter and setter

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 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 construct...

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(); } } }

HTML/JAVASCRIPT