View RSS Feed

Uncategorized

Entries with no category

  1. isTheStringPalinDrome, reverseTheWordOrder, fibonaciWithoutRecursion, removeDuplicates

    by , 04-04-2012 at 12:51 AM
    Java Code:
    package assignmentOne;
    
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.Set;
    
    public class PartOneAssignments {
    	
    	// This method accepts a String as the argument and checks whether it is palindrome or not
    	static boolean isTheStringPalinDrome(String s) {
    		
    		// Be positive and assume that the String provided is Palindrome
    		boolean stringIsPalinDrome = true;
    ...
    Categories
    Uncategorized
  2. A recursive method for searching an array of integers...

    by , 03-08-2012 at 09:49 PM
    Java Code:
    public class ArrayLister {
    	
    	private static int arraySearcher(int[] arrayToSort,int numberToFind,int left,int right){
    		
    		int middle = (left + right) / 2 ;
    		System.out.println(middle);
    
    		if(middle==arrayToSort.length-1)
    		{
    			if(arrayToSort[middle] == numberToFind) {
    				return middle;
    			}
    			else
    				return -1;
    		}
    		
    		if(arrayToSort[middle] == numberToFind) {
    			return
    ...
    Categories
    Uncategorized
  3. Factory Pattern Example

    by , 03-04-2012 at 09:10 PM
    Java Code:
    package factoryPattern2;
    
    public abstract class Product {
    	
    	private String productName;
    	
    	public void setName(String name) {
    		this.productName = name;
    	}
    	
    	public String getName() {
    		return productName;
    	}
    
    	public void putInABox() {
    		System.out.println("Putting the product in a box..");
    	}
    
    }
    
    
    package factoryPattern2;
    ...
    Categories
    Uncategorized
  4. Self Made Observable Pattern

    by , 03-03-2012 at 11:50 PM
    Java Code:
    package observerPatternSelfMade;
    
    public class MyObservableClass implements MyObservableInterface {
    
    	
    	
    	@Override
    	public void registerObserver(MyObserverInterface o) {
    		observers.add(o);
    	}
    
    	@Override
    	public void removeObserver(MyObserverInterface o) {
    		observers.remove(o);
    	}
    
    	@Override
    	public void notifyObservers() {
    		
    		for(int i = 0; i<observers.size();i++)
    ...
    Categories
    Uncategorized
  5. Strategy Pattern Example

    by , 03-03-2012 at 11:20 PM
    Java Code:
    package strategyPattern;
    
    public class Warrior {
    	
    	private AttackBehaviour attackBehaviour;
    	public String name;
    
    	void setAttackBehaviour(AttackBehaviour aB) {
    		this.attackBehaviour = aB;
    	}
    	
    	void attack() {
    		attackBehaviour.attack();
    	}
    }
    
    package strategyPattern;
    
    public interface AttackBehaviour {
    	
    	void attack();
    
    }
    
    package
    ...
    Categories
    Uncategorized
  6. Using the Observable - Observer class , interface in JAVA. Observer Pattern example.

    by , 03-03-2012 at 11:00 PM
    Java Code:
    package observerPatternBuiltIn;
    
    import java.util.Observable;
    
    public class MyObservable extends Observable {
    	
    	int integerToBeObserved;
    	
    	public void setInt(int i) {
    		integerToBeObserved = i;
    		setChanged();
    		notifyObservers();
    	}
    	
    	public int getInt() {
    		return integerToBeObserved;
    	}
    
    }
    
    
    package observerPatternBuiltIn;
    
    import
    ...
    Categories
    Uncategorized
  7. Decorator Pattern Example

    by , 03-03-2012 at 10:27 PM
    Java Code:
    package decoratorPattern;
    
    public abstract class Beverage {
    	
    	String description;
    	int size;
    	
    	public Beverage(int size) {
    		this.size = size;
    	}
    		
    	public String getDescription() {
    		
    		String mySize = null;
    		
    		if(size == 1)
    			mySize = "Small";
    		else if(size==2)
    			mySize="Medium";
    		else if(size==3)
    			mySize="Large";
    ...
    Categories
    Uncategorized
  8. Listing the installed look and feels

    by , 02-15-2012 at 08:55 PM
    Java Code:
    import javax.swing.UIManager;
    
    public class TestClass {
    
    	public static void main(String args[]) {
    		UIManager.LookAndFeelInfo laf[] = UIManager
    				.getInstalledLookAndFeels();
    		for (int i = 0, n = laf.length; i < n; i++) {
    			System.out.print("LAF Name: " + laf[i].getName() + "\t");
    			System.out.println("  LAF Class name: "
    					+ laf[i].getClassName());
    		}
    		System.exit(0);
    ...
    Categories
    Uncategorized
  9. Making your own class Iterable.

    by , 02-09-2012 at 08:21 PM
    Java Code:
    package myPaackkage;
    
    import java.util.*;
    
    
    public class SomeClass implements Iterable<String> 
    {
    	@Override
    	public Iterator<String> iterator() 
    	{
    		System.out.println("Hello!!");
    		
    		return new Iterator<String>()
    				{
    			private int i = 0;
    
    					@Override
    					public boolean hasNext() {
    						while(i<words.size())
    							return true;
    ...

    Updated 02-21-2012 at 11:33 PM by fatabass (Code tags.)

    Categories
    Uncategorized
  10. Checking for Randomness of Java with HashMap

    by , 02-07-2012 at 11:19 PM
    Java Code:
    package myPaackkage;
    
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.ListIterator;
    import java.util.Random;
    
    public class SayisalGenerator {
    	
    	static Random myRandomGenerator = new Random();
    	
    	public static void main(String[] args)
    	{
    		HashMap<Integer,Integer> myHashMap = new HashMap<Integer,Integer>();
    		
    		for(int i=0;i<1000;i++)
    		{
    ...
    Categories
    Uncategorized
  11. A little on Containers. ( Collections + Maps )

    by , 02-07-2012 at 08:39 PM
    Java Code:
    package myPaackkage;
    
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.Collection;
    import java.util.Collections;
    import java.util.HashMap;
    import java.util.HashSet;
    import java.util.LinkedHashMap;
    import java.util.LinkedHashSet;
    import java.util.LinkedList;
    import java.util.List;
    import java.util.Map;
    import java.util.TreeMap;
    import java.util.TreeSet;
    
    public class
    ...
    Categories
    Uncategorized
  12. Using of Inner Classes

    by , 02-06-2012 at 01:15 AM
    Java Code:
    package myPackage2;
    
    public abstract class Event 
    {
    	private long eventTime;
    	protected final long delayTime;
    	
    	public Event(long delayTime)
    	{
    		this.delayTime = delayTime;
    		start();
    	}
    	
    	public void start()
    	{
    		eventTime = System.nanoTime() + 2*delayTime;
    	}
    	
    	public boolean ready()
    	{
    		return System.nanoTime() >= eventTime;
    	}
    ...
    Categories
    Uncategorized
  13. Initializing

    by , 02-01-2012 at 07:23 PM
    Java Code:
    package myPackage;
    
    public class SprinklerSystem 
    {
    	private String valve1;
    	private int valveStrength;
    	private WaterSource source = new WaterSource();
    	
    	static 
    	{
    		System.out.println("You are in Static block!");
    	}
    
    	{
    		System.out.println("You are in initi block!");
    		this.valve1 = "Valve1 ";
    	}
    	
    
    	
    	SprinklerSystem()
    ...
    Categories
    Uncategorized
  14. Casting with Class: Class.

    by , 01-28-2012 at 09:21 PM
    Java Code:
    public class ClassCasts 
    {
    	
    	public static void main(String args[])
    	{
    		Building b = new House();
    		Class<House> houseType = House.class;
    		House h = houseType.cast(b);
    		System.out.println(b.getClass());
    	}
    
    }
    Categories
    Uncategorized
  15. Using of Class Class. An Example:

    by , 01-28-2012 at 11:30 AM
    Java Code:
    package myPackage1;
    
    interface HasBatteries{};
    interface Waterproof{};
    interface Shoots{};
    
    class Toy
    {
    	Toy(){};
    	Toy(int i){};
    }
    
    class FancyToy extends Toy implements HasBatteries,Waterproof,Shoots
    {
    	FancyToy()
    	{
    		super(1);
    	}
    }
    
    public class ToyTest 
    {
    	static void printInfo(Class cc)
    	{
    		System.out.println("Class name:
    ...
    Categories
    Uncategorized
  16. Reading a Files first line with a simple gui application

    by , 01-16-2012 at 12:12 AM
    Java Code:
    package myPackage;
    
    import java.awt.Container;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.util.Scanner;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JTextField;
    
    public class FileOrganizer extends JFrame implements ActionListener 
    {
    	public
    ...
    Categories
    Uncategorized
  17. Reading Byte From a Text File and Printing To Console Character And Byte Value

    by , 01-14-2012 at 12:12 PM
    Java Code:
    public static void main(String[] args) 
    	{
    		File myText = new File("c:/myDir/myText.txt");
    		
    		try {
    			InputStream myByteReader = new FileInputStream(myText);
    			System.out.println("Available total bytes:" + myByteReader.available());
    			int firstByte = myByteReader.read();
    			System.out.println("First byte:" + firstByte);
    			System.out.println("Char of first byte:" + (char) firstByte);
    ...
    Categories
    Uncategorized
  18. Reading Bytes from a Text File

    by , 01-14-2012 at 12:48 AM
    Java Code:
    package myPackage;
    
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.FilterOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.ObjectInputStream;
    import java.io.ObjectOutputStream;
    import java.io.OutputStream;
    import java.io.PrintStream;
    import java.io.PrintWriter;
    import java.io.Serializable;
    ...
    Categories
    Uncategorized
  19. Writing an Array Object to a Binary File and Reading Back

    by , 01-14-2012 at 12:03 AM
    Java Code:
    package myPackage;
    
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.FilterOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.ObjectInputStream;
    import java.io.ObjectOutputStream;
    import java.io.OutputStream;
    import java.io.PrintStream;
    import java.io.PrintWriter;
    import java.io.Serializable;
    ...
    Categories
    Uncategorized
  20. Look of a Calculator

    by , 12-30-2011 at 06:37 PM
    Java Code:
    package myPackage;
    
    import java.awt.BorderLayout;
    import java.awt.FlowLayout;
    import java.awt.GridLayout;
    
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    
    public class SimpleCalculator {
    
    	public static void main(String[] args) 
    	{
    		JFrame myFrame = new JFrame( "Testing" );
    ...
    Categories
    Uncategorized
  21. A Simple GridLayout Example

    by , 12-29-2011 at 01:12 AM
    Java Code:
    package myPackage;
    
    import java.awt.Container;
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    import javax.swing.JButton;
    import javax.swing.JFrame;
    
    public class GridLayoutFrame extends JFrame implements ActionListener
    {
    	
    	private JButton[] buttons; // array of buttons
    	private static final String[] names = {"one", "two", "three"
    ...
    Categories
    Uncategorized
  22. JList Multiple Selection and Copying with a Button to Another JList Example

    by , 12-28-2011 at 11:33 PM
    Java Code:
    package myPackage;
    
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JList;
    import javax.swing.JScrollPane;
    import javax.swing.ListSelectionModel;
    
    public class MultipleSelectionFrame extends JFrame 
    {
    	private static final long	serialVersionUID	= 1L;
    	private JList colorJList;
    ...
    Categories
    Uncategorized
  23. JList Example

    by , 12-28-2011 at 12:17 AM
    Java Code:
    package myPackage;
    
    import java.awt.FlowLayout;
    import java.awt.GridLayout;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JList;
    import javax.swing.JScrollPane;
    import javax.swing.ListSelectionModel;
    import javax.swing.event.ListSelectionEvent;
    import javax.swing.event.ListSelectionListener;
    
    public class ListFrame extends JFrame
    {
    	JList myJList;
    	String[] colorrs;
    ...
    Categories
    Uncategorized
  24. A simple GUI code

    by , 12-18-2011 at 02:25 PM
    Java Code:
    package myPackage;
    import java.awt.Color;
    import java.awt.FlowLayout;
    import javax.swing.*;
    @SuppressWarnings("serial")
    public class SamsLearning extends JFrame {
    	public SamsLearning() {
    		super();
    		this.setTitle("My Title");
    		this.setLookAndFeel();
    		this.setSize(500,500);
    		MyButtonClass myButton = new MyButtonClass("Play");
    		MyButtonClass myButton2 = new MyButtonClass("Stop");
    ...
    Categories
    Uncategorized