Skip to content

Instantly share code, notes, and snippets.

View daveRanjan's full-sized avatar
💭
Working Class Hero

Devendra Tiwari daveRanjan

💭
Working Class Hero
View GitHub Profile
public class AreaFinder{
 
public static void main(String[] args){
//This will create an object of circle class
Shape circle = new Circle();
//This will create an object of Rectangle class
Shape rectangle = new Rectangle();
// Drumbeats ……
//This should print 78.5
public class Rectangle extends Shape {
private Double length = 5.0;
private Double breadth= 10.0;
// See this annotation @Override, it is telling that this method is from parent
// class Shape and is overridden here
@Override
public Double area(){
return length * breadth;
}
 }
public class Circle extends Shape {
private Double radius = 5.0;
// See this annotation @Override, it is telling that this method is from parent
// class Shape and is overridden here
@Override
public Double area(){
return 3.14 * radius * radius;
}
 }
public abstract class Shape{
public abstract Double area();
 }
static String valueOf(boolean b) 
 static String valueOf(char c) 
 static String valueOf(char[] data) 
 static String valueOf(char[] data, int offset, int count) 
 static String valueOf(double d) 
 static String valueOf(float f) 
 static String valueOf(int i) 
 static String valueOf(long l) 
 static String valueOf(Object obj)
public class Shape{
//It could be a circle or rectangle or square
private String type;
//To calculate area of rectangle
public Double area(Long length, Long breadth){
return (Double) length * breadth;
}
//To calculate area of a circle
public class BadConstructor{
public String param1;
public int param2;
public char[] param3;
public AnotherClass param4;
public List param5;
public Set param6;
public BadConstructor(String param1, int param2, char[] param3, AnotherClass param4, List<String> param5, HashSet<String> param6){
@daveRanjan
daveRanjan / transactional.xml
Last active November 3, 2016 13:42
transaction-rollback.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:sec="http://www.springframework.org/schema/security"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd"
default-autowire="byName">
@daveRanjan
daveRanjan / Singleton.java
Created November 1, 2016 14:00
A very simple explaned example of singleton class
class Singleton {
// This is an object of the same class, but give more attention towards
// private :- This object cannot be accessed from outside, you have use getter (getInstance) method
// static :- This object is static as getInstance have to be static (Why?? You'll know) and
// only static variables can be accessed in static methods
private static Singleton INSTANCE = null;
// Ofcourse a class is of no use if it does not have any data (So this is the data for which every thread will fight)
private String criticalData;