Skip to content

Instantly share code, notes, and snippets.

View ozkansari's full-sized avatar
🏠
Working from home

Ozkan Sari ozkansari

🏠
Working from home
View GitHub Profile
@ozkansari
ozkansari / AtmDisplay.java
Created June 6, 2012 12:53
Atm Status Finite State Machine Example using Apache Commons SCXML Library
package net.javafun.example.atmstatusfsm;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
@ozkansari
ozkansari / BitDemo1.java
Created January 6, 2013 10:49
Sİmple binary operation example
class BitDemo1 {
/**
* prints "2"
*/
public static void main(String[] args) {
int val = 0x2222;
int bitmask = 0x000F;
@ozkansari
ozkansari / BitwiseShiftOperations.java
Created January 6, 2013 10:54
Java bitwise opeartions example
class BitwiseShiftOperations {
/**
* Shift Operations Example
*/
public static void main(String[] args) {
int val = 0x000F;
printBinary(val);
@ozkansari
ozkansari / PowerOf2Util1.java
Last active December 10, 2015 17:18
Checking if a number can be written as power of 2 using bitwise operations
/**
* Problem: Given an integer, i, find whether it can be expressed as 2^k. Where k< i
*/
class PowerOf2Util1 {
/**
* Test
*/
public static void main(String[] args) {
int input = 262144; // 2^18
@ozkansari
ozkansari / PowerOf2Util2.java
Created January 6, 2013 11:00
Checking if a number can be written as power of 2 using bitwise operations
/**
* Problem: Given an integer, i, find whether it can be expressed as 2^k. Where k< i
*/
class PowerOf2Util2 {
/**
* Test
*/
public static void main(String[] args) {
int input = 262144; // 2^18
@ozkansari
ozkansari / PowerOf2Util3.java
Created January 6, 2013 11:02
Checking if a number can be written as power of 2
/**
* Problem: Given an integer, i, find whether it can be expressed as 2^k. Where k< i
*/
class PowerOf2Util3 {
/**
* Test
*/
public static void main(String[] args) {
int input = 262144; // 2^18
@ozkansari
ozkansari / PowerOf2Util4.java
Created January 6, 2013 11:05
Checking if a number can be written as kth power of 2 using bitwise operations
/**
* Problem: Given an integer, i, find whether it can be expressed as 2^k. Where k< i
*/
class PowerOf2Util4 {
/**
* Test
*/
public static void main(String[] args) {
int k=18;
@ozkansari
ozkansari / BinaryTreeUtils.java
Last active December 10, 2015 17:28
Binary Tree utils for (1) getting nodes at a given distance & (2) getting zig zag order traversal of binary tree. Includes two different implementation for both operations.
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.LinkedList;
import java.util.Map;
import java.util.Stack;
import java.util.Queue;
import java.util.Collections;
/**
/**
* What is printed to standard output ?
*
* a) "NullPointerException thrown"
* b) "Exception thrown"
* c) "Done with exceptions"
* d) "checkResult is done"
* e) None of the above
*
*/
@ozkansari
ozkansari / QuizInheritance.java
Last active December 11, 2015 03:19
Simple question about java inheritance
/**
* What will be printed to standard output?
*
* a) The code will not compile.
* b) The code compiles and "5, Super" is printed to standard output.
* c) The code compiles and "5, Sub" is printed to standard output.
* d) The code compiles and "2, Super" is printed to standard output.
* e) The code compiles and "2, Sub" is printed to standard output.
* f) The code compiles, but throws an exception.
*/