Skip to content

Instantly share code, notes, and snippets.

View rajeevprasanna's full-sized avatar

Rajeev Kumar kallempudi rajeevprasanna

View GitHub Profile
import sbt._
import Keys._
import sbtassembly.Plugin._
import AssemblyKeys._
import org.scalatra.sbt._
import org.scalatra.sbt.PluginKeys._
import com.mojolly.scalate.ScalatePlugin._
import ScalateKeys._
import sbt._
import Keys._
import sbtassembly.Plugin._
import AssemblyKeys._
import org.scalatra.sbt._
import org.scalatra.sbt.PluginKeys._
import com.mojolly.scalate.ScalatePlugin._
import ScalateKeys._
@rajeevprasanna
rajeevprasanna / gist:8493409
Created January 18, 2014 17:17
Different ways of creating objects in Java
package objectCreation;
public class TestObject implements Cloneable {
private String name = "DefaultTestName";
public String getName() {
return name;
}
// By convention, classes that implement this interface should override
@rajeevprasanna
rajeevprasanna / InstanceVariables.java
Created January 18, 2014 18:10
Examples of different variable types in java
package variableTypes;
public class InstanceVariables {
public int mCost;//manage outside class access using access modifiers.
//Default public constructor
public InstanceVariables(){}
public InstanceVariables(int profit){
@rajeevprasanna
rajeevprasanna / EncapsulationExample.java
Created January 18, 2014 18:40
Encapsulation examples
package encapsulation;
public class EncapsulationExample {
public int left = 9;
public int right = 3;
// Now consider this question: Is the value of right always going to be one-
// third the value of left? It looks like it will, until you realize that
// users of the Foo class don’t need to use the setLeft() method! They can
@rajeevprasanna
rajeevprasanna / Car.java
Created January 19, 2014 02:20
Inheritance IS-A and HAS-A relation
package inheritanceIsaAndHasA;
public class Car {
//color and maxSpeed are instance variables
private String color;
private int maxSpeed;
//Below are methods of Car class
public void carInfo() {
System.out.println("Car Color= " + color + " Max Speed= " + maxSpeed);
@rajeevprasanna
rajeevprasanna / InstanceOfExampleTest.java
Last active January 3, 2016 18:08
instanceOf Example
package inheritanceIsaAndHasA;
//Refer : https://gist.github.com/rajeevprasanna/8499735
public class InstanceOfExampleTest {
public static void main(String[] args) {
Test t1 = new Test();
Test t2 = new Test();
if (!t1.equals(t2)) {// equals compares references
System.out.println("they're not equal");
}
package inheritanceIsaAndHasA.codeReuseExample;
public class CodeReuseExampleTest {
public static void main(String[] args) {
PlayerPiece shape = new PlayerPiece();
shape.displayShape();
shape.movePiece();
}
}
@rajeevprasanna
rajeevprasanna / GameShape.java
Created January 19, 2014 03:04
Polymorphism example
package inheritanceIsaAndHasA.polymorphism;
public class GameShape {
public void displayShape() {
System.out.println("displaying shape");
}
// more code
}
@rajeevprasanna
rajeevprasanna / Car.java
Created January 19, 2014 03:16
inheritance example2
package inheritanceIsaAndHasA.isa;
public class Car extends Vehicle {
// Cool Car code goes here
}