Skip to content

Instantly share code, notes, and snippets.

View rishi93's full-sized avatar

Rajarishi Devarajan rishi93

View GitHub Profile
@rishi93
rishi93 / test.java
Created November 11, 2015 06:37
Swing Basic Example
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class MyFrame extends JFrame
{
public MyFrame()
{
this.setTitle("Example Application");
this.setSize(400,400);
@rishi93
rishi93 / test.java
Last active November 11, 2015 09:07
Swing Buttons with Action Listener
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
class MyFrame extends JFrame
{
public MyFrame()
{
this.setTitle("Example Application");
@rishi93
rishi93 / sequence.java
Created November 17, 2015 10:02
Static and non-static Blocks
import java.io.*;
public class Sequence
{
/* A static block. Called only once, the first
time you are accessing the class. Static block is
executed before class is loaded. */
static
{
System.out.println("Executing static block..");
@rishi93
rishi93 / poly.java
Created November 17, 2015 12:03
Using Parent reference to store child class objects
class Alpha
{
String getType()
{
return "alpha";
}
}
class Beta extends Alpha
{
@rishi93
rishi93 / interface_test.java
Last active November 19, 2015 10:30
Example of Using Interface
import java.io.*;
interface StartStop
{
public abstract void start();
public abstract void stop();
}
class Car implements StartStop
{
@rishi93
rishi93 / test2.java
Created November 18, 2015 09:16
Inheritance Example Data Members
import java.io.*;
class Feline
{
String type = "f";
public Feline()
{
System.out.println("feline");
}
@rishi93
rishi93 / factory.java
Last active July 11, 2016 15:46
Design Patterns - Factory Pattern
import java.io.*;
interface Shape
{
public void draw();
}
class Square implements Shape
{
@Override
@rishi93
rishi93 / clone.java
Created November 20, 2015 12:26
Cloneable
import java.io.*;
class A implements Cloneable
{
public int data;
public A(int data)
{
System.out.println("Constructor called");
this.data = data;
}
@rishi93
rishi93 / test.java
Created November 23, 2015 11:52
Comparing Objects for sort, Comparable Interface.
import java.io.*;
import java.util.*;
class A implements Comparable<A>
{
private int data;
public A(int data)
{
this.data = data;
}
@rishi93
rishi93 / test.java
Last active November 25, 2015 09:39
Threads in Java by extending Thread class
import java.io.*;
class MyThread extends Thread
{
private String threadName;
MyThread(String threadName)
{
this.threadName = threadName;
System.out.println("Creating Thread " + this.threadName);
}