View RSS Feed

Most Popular Blogs

  1. A simple GUI code

    by , 12-18-2011 at 01: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
  2. JList Example

    by , 12-27-2011 at 11:17 PM
    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
  3. JList Multiple Selection and Copying with a Button to Another JList Example

    by , 12-28-2011 at 10: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
  4. A Simple GridLayout Example

    by , 12-29-2011 at 12: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
  5. Look of a Calculator

    by , 12-30-2011 at 05: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
  6. Static initialize

    by , 01-08-2012 at 10:50 AM
    All the code blocks that do not have a function name and are declared as static are executed before the constructor is called. They are usually used to initialize static fields as shown in below code.

    Java Code: This is an example of static initialize
    public class StaticInitilaizer {
    public static final int A = 5;
    public static final int B;
    //Static initializer block, which is executed only once when the class is loaded.
    static {
    if(A == 5)
    B = 10;
    else
    B = 5;
    ...

    Updated 01-14-2012 at 06:37 PM by Java Basic

    Categories
    Tutorial
  7. Writing an Array Object to a Binary File and Reading Back

    by , 01-13-2012 at 11:03 PM
    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
  8. Reading Bytes from a Text File

    by , 01-13-2012 at 11:48 PM
    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
  9. Reading Byte From a Text File and Printing To Console Character And Byte Value

    by , 01-14-2012 at 11:12 AM
    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
  10. Reading a Files first line with a simple gui application

    by , 01-15-2012 at 11:12 PM
    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
  11. Using of Class Class. An Example:

    by , 01-28-2012 at 10: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
  12. Casting with Class: Class.

    by , 01-28-2012 at 08: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
  13. Initializing

    by , 02-01-2012 at 06: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. Using of Inner Classes

    by , 02-06-2012 at 12: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
  15. A little on Containers. ( Collections + Maps )

    by , 02-07-2012 at 07: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
  16. Checking for Randomness of Java with HashMap

    by , 02-07-2012 at 10: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
  17. Making your own class Iterable.

    by , 02-09-2012 at 07: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 10:33 PM by fatabass (Code tags.)

    Categories
    Uncategorized
  18. Create new Form in Eclipse

    by , 02-11-2012 at 02:59 PM
    Click the JFormDesigner button in toolbar of Eclipse. Also it can be initiated using following short keys.
    • For Windows (Ctrl+Shift+V)
    • For Mac (Shift+Command+V)

    To create a new form using Eclipse’s Package Explorer, select destination folder and right click. It will open following dialog box.

    Name:  1.JPG
Views: 8805
Size:  52.8 KB

    Create new Form in Eclipse
    Tags: eclipse, new form Add / Edit Tags
    Categories
    Eclipse GUI
  19. Listing the installed look and feels

    by , 02-15-2012 at 07: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
  20. Cassandra alternatives

    by , 02-21-2012 at 08:12 PM
    Before taking any start along with Cassandra, it is important to be well aware of the fact that many alternatives exists for complimenting the relational database. E.g., memcached has been made to be used for Livejournal.com, and is free of cost. If you apply such solution to some larger Mysql database alone, you may expect a great performance boost of 100 times.

    Other than this, another famous Nosql solution that has been well renowned is MongoDB, which has been written in language ...
    Tags: cassandra Add / Edit Tags
    Categories
    Framework
  21. Strategy Pattern Example

    by , 03-03-2012 at 10: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
  22. Self Made Observable Pattern

    by , 03-03-2012 at 10: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
  23. Factory Pattern Example

    by , 03-04-2012 at 08: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
  24. Working with JSP and Servlet

    by , 04-03-2012 at 11:44 AM
    Suppose you are familiar with some beginner concepts regarding Servlet and Java Server Pages (JSP), this article focuses on some techniques for making JSP and Servlet working together in a Java web application.

    A brief overview of Servlet and JSP technologies

    A Servlet is a Java class running on a web server to serve client’s requests. Servlets are commonly used to handle HTTP requests. They are created to address shortcomings of CGI scripting, and enhance functionality ...
    Tags: jsp, servlet Add / Edit Tags
    Categories
    Servlet , JSP
  25. isTheStringPalinDrome, reverseTheWordOrder, fibonaciWithoutRecursion, removeDuplicates

    by , 04-03-2012 at 11:51 PM
    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
  26. Email Senders and Recipients

    by , 04-25-2012 at 09:31 PM
    Recipient and sender of email addresses are presented in JavaMail, by InternetAddress class instances. Email addresses are taken by the constructor as a string, & AddressException are raised when there is no resemblance b/w valid email address and address. Personal name is provided as a string, for 2nd parameter.
    Sender address could be set by calling setForm() method, at MimeMessage object. Sender address has these given types:
    • Registered administration’s address, for application.
    • User’s
    ...
  27. Send multipart mail using java mail

    by , 04-25-2012 at 10:02 PM
    By the help of java mail how one could send multipart mails has been shown in this example. One might think a Multipart to be a container which contains more than one body parts. For sending the multipart mail, Multipart class object is made. After this BodyPart class object is created and text is set in the BodyPart class object which is then added to Multipart class object. Ultimately message is sent. In the given code, Class Multipart is abstract class. In this program, method of Multipart class ...
    Categories
    Mail API
  28. Passing Information to a Method or a Constructor

    by , 04-26-2012 at 05:15 PM
    Declaration for constructor or a method makes declared the type & number of the arguments for that constructor or method. For instance, given method computes the home loan monthly payments which depend upon the loan amount, loan length, interest rate or the loan’s future value.
    Java Code:
    public double computePayment(
                      double loanAmt,
                      double rate,
                      double futureValue,
                      int numPeriods) {
    ...
    Categories
    Tutorial
  29. Java String Quantifiers

    by , 04-26-2012 at 06:49 PM
    Number of occurrences are specified by the quantifiers so that to match. For sake of convenience, Pattern API has been divided into 3 sections with specifications that describe possessive, greedy and reluctant quantifiers are represented below. In first look, this might happen that X?+, X? And X?? Be doing similar things as all of them promise to be match X i.e once, or not at all. Subtle differences of implementations are present that will be discussed at the end of this section.

    ...
    Categories
    Regex
  30. Closer Look at Swing. Where is MVC?

    by , 04-26-2012 at 08:42 PM
    Model delegate which a common MVC flavor is being implemented by the internally swing, which coalesces controller and view to UI delegate. Rarely, developers deal with controller or view part while applications are being written. Instead they deal with components.Swing components are not at all the part of MVC but they are considered as mediators present b/w view, model and controller.

    Custom coding is involved in building of the components and model creations to communicate to the ...
    Categories
    MVC
Page 3 of 4 FirstFirst 1234 LastLast