Skip to content

Instantly share code, notes, and snippets.

View finkformatics's full-sized avatar

Lukas Fink finkformatics

View GitHub Profile
@finkformatics
finkformatics / javascript_classes_overview.js
Created April 21, 2022 10:36
JavaScript Classes Overview
"use strict";
// Imperative way
let rect1 = {a: 50, b: 30};
let calculateRectArea = (rect) => {
return rect.a * rect.b;
}
console.log(calculateRectArea(rect1));
@finkformatics
finkformatics / RaceConditionSolvedExample.java
Last active April 9, 2016 13:50
Race condition solved example
/**
* Race condition solved example
*
* The same as race condition example, but with a particular synchronized inc() method to increment z
*
* Result: After program termination z is always 10000
*/
public class RaceConditionSolvedExample {
static int z;
@finkformatics
finkformatics / RaceConditionExample.java
Last active April 9, 2016 13:49
Race condition example
/**
* Race condition example
*
* Creates a high number of threads and lets each increase a static int variable.
*
* Result: In most cases, the variable's value isn't 10000 after the program's finished, but a bit below.
*/
public class RaceConditionExample {
static int z;
@finkformatics
finkformatics / ThreadExampleSysout.java
Created April 9, 2016 08:21
Simple thread example (without synchronized Sysout)
/**
* Simple thread example (without synchronized Sysout)
*
* Creates a certain number of threads and lets each thread print out a message and its index in the array. The
* difference from the ThreadExample.java is, that here we do not build on the synchronized possibility to output
* strings but write an own method to printout each character in a string.
*
* Result: Letter salad :D
*/
public class ThreadExampleSysout {
@finkformatics
finkformatics / ThreadExample.java
Created April 9, 2016 08:20
Simple Thread example
/**
* Simple thread example
*
* Creates a certain number of threads and lets each thread print out a message and its index in the array.
*
* Result: The outputs aren't in the order the threads were created.
*/
public class ThreadExample {
public static void main(String[] args) {