Posts

java questions

    *      What is the use of bin and lib in JDK?- Bin contains all tools such as javac, appletviewer, awt tool, etc., whereas lib contains API and all packages.     *      What is casting?- Casting is used to convert the value of one type to another.     *      What is final, finalize() and finally?- final : final keyword can be used for class, method and variables. A final class cannot be subclassed and it prevents other programmers from subclassing a secure class to invoke insecure methods. A final method can’t be overridden. A final variable can’t change from its initialized value. finalize() : finalize() method is used just before an object is destroyed and can be called just prior to garbage collection. finally : finally, a key word used in exception handling, creates a block of code that will be executed after a try/catch block has completed and before the c...

Capture image from webcam java code, examples

import java.applet.Applet; import java.awt.BorderLayout; import java.awt.Component; import java.awt.Dimension; import java.awt.Frame; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; import java.awt.Panel; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.image.BufferedImage; import java.io.FileOutputStream; import java.net.MalformedURLException; import java.net.URL; import javax.media.Buffer; import javax.media.CaptureDeviceInfo; import javax.media.CaptureDeviceManager; import javax.media.Manager; import javax.media.MediaLocator; import javax.media.Player; import javax.media.control.FrameGrabbingControl; import javax.media.format.VideoFormat; import javax.media.util.BufferToImage; import javax.swing.JButton; import javax.swing.JComponent; import com.sun.image.codec.jpeg.JPEGCodec; import com.sun.image.codec.jpeg.JPEGE...

Map.Entry Interface

Map.Entry Interface -     Map.Entry Interface is used to hold the view of key-value pair from Map. Map interface has a method entrySet() which returns the Set object that holds the key value pair. You can iterate the key and value from getKey() and getValue(). You can also set value an element by the setValue() method. List of methods within the Map.Entry Interface -  boolean equals(Object o) -          This method is used to compares the specified object with this entry. If both are equal it return true otherwise return false.  K getKey() -     This method returns the key of map.  V getValue() -     This method returns the value of corresponding to this entry.  int hashCode() -     This method is used to return the hash code value for this map entry.  V setValue(V value) -     This method is used to set the values at  corr...

ListIterator Interface

ListIterator Interface -     ListIterator Interface is used for traverse list in both direction. You can find previous element by previous() method and next element by next() method. Within the both method ListIterator maintain the cursor position. ListIterator has previousIndex() for checking that List has previous index or not.      ListIterator Interface extends Iterator Interface. You can also set any new element in the list. List of methods within the ListIterator Interface - void add(E e) -     This method is used to add a given element into the list. boolean hasNext() -     This method is used to check the presence of element in the list when traversing the list in the forward direction. boolean hasPrevious() -     This method is used to check the presence of element in the list when traversing the list in the reverse direction. E next() -     this method is used to retu...

NavigableSet Interface

NavigableSet Interface -     NavigableSet Interface is very useful for searching strategics. NavigableSet Interface gives the functionality for closest search mechanism. NavigableSet may search less than, less than or equal, greater than or equal, and greater than through the lower, floor, ceiling, and higher methods. There is a example - import java.util.Iterator; import java.util.NavigableSet; import java.util.concurrent.ConcurrentSkipListSet; public class Test {     public static void main(String[] args) {             NavigableSet nSet = new ConcurrentSkipListSet();             nSet.add("A");             nSet.add("B");             nSet.add("C");             nSet.add("D");          ...

Creational Patterns in java

Creational Patterns in java:- Definition:- Ceartional Patterns is designed for making the object of any class with best possible ways.  So that application can manage the heap memory allocation area. Creational design patterns solve this problem by somehow controlling this object creation. There are some example of Creational Patterns. Abstract factory pattern Factory method pattern Builder pattern Lazy initialization pattern Object pool pattern Prototype pattern Singleton pattern

Creational Patterns : Factory pattern

Creational Patterns : factory pattern in Java:- Definition:- Factory pattern is comes under the creational pattern. In the Factory pattern, There is a class which manage the creation of object according to the situation is called factory.     There is an example which describe the Factory pattern. public class course {    private int courseCode;    private String CourseName;    public int getCourseCode() {        return courseCode;    }    public void setCourseCode(int courseCode) {        this.courseCode = courseCode;    }    public String getCourseName() {        return CourseName;    }    public void setCourseName(String courseName) {        CourseName = courseName;   ...

Recent Post

Recent Posts Widget