Skip to content

Instantly share code, notes, and snippets.

View smamran's full-sized avatar
🎯
Focusing

S. M. AMRAN smamran

🎯
Focusing
View GitHub Profile
@smamran
smamran / ThisKeyWord.Java
Created August 21, 2015 04:06
Usage of This keyword..
package com.netcse.java;
public class Main {
int id;
String name;
Main(int i, String n){
id = i;
name = n;
@smamran
smamran / ChartView.java
Created August 25, 2015 14:06
Simple Shadow Chart View
/**
* Created by Google on 8/22/2015.
*/
package com.example.google.interview;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
@smamran
smamran / SynchronizedThreadJoin.java
Created September 15, 2015 05:24
Java Thread with Synchronized Thread Join
class Worker {
private static long count = 0;
public synchronized void increment() {
for (int i = 0; i < 10; i++) {
count++;
}
}
@smamran
smamran / ThreadLockObject.java
Created September 15, 2015 05:51
Thread With Lock Object
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
class App {
public static void main(String[] args) {
Worker worker = new Worker();
worker.main();
@smamran
smamran / OsAndArchitect.java
Created September 20, 2015 09:03
Operating System and Architecture detection i java code.
package com.netcse.java;
public class Main {
private static final String OS_NAME = System.getProperty("os.name").toString();
public static void main(String[] args) {
System.out.println("Hello world java programming in this world is nothing but java");
System.out.println(OS_NAME);
System.out.println(System.getProperty("os.arch").toString());
@smamran
smamran / StackTraceCheck.java
Last active September 20, 2015 09:20
Stack Tracing for a function.
package com.netcse.java;
public class Main {
public static void main(String[] args) {
StackTraceElement[] stackTraceElement = Thread.currentThread().getStackTrace();
for (StackTraceElement s : stackTraceElement) {
System.out.println(s.toString());
}
@smamran
smamran / ExitFXGUI.java
Created September 20, 2015 13:52
Exit FX Stage or Scene by Pressing Esc Key
primaryStage.addEventHandler(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>(){
@Override
public void handle(KeyEvent event) {
if(event.getCode() == KeyCode.ESCAPE){
primaryStage.close();
}
}
@smamran
smamran / ExitJFrameGUI.java
Created September 20, 2015 13:54
Exit Focused JFrame by Pressing Esc Key
getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "Cancel");
getRootPane().getActionMap().put("Cancel", new AbstractAction()
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
});
@smamran
smamran / GenericsVsNonGen.java
Last active September 20, 2015 14:15
Generics vs Non Generics Java
// The following code snippet without generics requires casting:
List list = new ArrayList();
list.add("hello");
String s = (String) list.get(0);
// When re-written to use generics, the code does not require casting:
List<String> list = new ArrayList<String>();
list.add("hello");
String s = list.get(0); // no cast
@smamran
smamran / AmbiguousOverloading.java
Last active September 22, 2015 06:26
Java Ambiguous Function Overloading
class Main {
static int max(int x, double y) {
return (x > y) ? x : (int) y;
}
static int max(double x, int y) {
return (x > y) ? (int) x : y;
}