Skip to content

Instantly share code, notes, and snippets.

package com.diycomputerscience;
/**
* This is the customary 'Hello World' in Java.
* When we run a Java class, it's main method os invoked. This has to be
* a public static method which takes an array of String objects.
*/
public class HelloWorld {
public static void main(String args[]) {
//The following line prints 'Hello World' to your console
@adaptives
adaptives / gist:1106420
Created July 26, 2011 10:05
Java Strings
package com.diycomputerscience;
/**
* This example explains Java Strings and a few commonly used methods
* in the {@link String} class
*
*/
public class JavaStrings {
public static void main(String[] args) {
@adaptives
adaptives / StringBufferAndBuilder.java
Created July 26, 2011 10:38
StringBuffer and StringBuilder
package com.diycomputerscience;
public class StringBufferAndBuilder {
public static final int MAX_ITER = 10000;
/**
* @param args
* This example shows how to perform common String operations in Java
*/
@adaptives
adaptives / JavaArrays.java
Created July 26, 2011 12:28
Using arrays in Java
package com.diycomputerscience;
/**
* This example explains how to create and use single and
* multidimensional arrays
*/
public class JavaArrays {
public static void main(String args[]) {
@adaptives
adaptives / JavaLists.java
Created July 28, 2011 06:13
Using Lists in Java
package com.diycomputerscience;
import java.util.List;
import java.util.ArrayList;
import java.util.ListIterator;
/**
* This class explains the usage of Lists in Java
*/
public class JavaLists {
@adaptives
adaptives / JavaSet.java
Created July 28, 2011 07:12
Using the Set interface in Java
package com.diycomputerscience;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;
public class JavaSet {
public static void main(String args[]) {
@adaptives
adaptives / JavaMaps.java
Created July 28, 2011 08:04
Working with Maps in Java
package com.diycomputerscience;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
public class JavaMaps {
public static void main(String args[]) {
@adaptives
adaptives / gist:1119693
Created August 2, 2011 06:34
LPTHW - Ex1
print "Hello World!"
print "Hello Again"
print "I like typing this."
print "This is fun."
print 'Yay! Printing.'
print "I'd much rather you 'not'."
print 'I "said" do not touch this.'
@adaptives
adaptives / LPTHW - Exercise 2
Created August 2, 2011 06:50
LPTHW - Exercise 2
# A comment, this is so you can read your program later.
# Anything after the # is ignored by Python.
print "I could have code like this." # and the comment after is ignored
# You can also use a comment to "disable" or comment out a piece of code:
# print "This won't run."
print "This will run."
# The meaning of operators in Python
# + plus Addition
# - minus Subtraction
# / slash Division
# * asterisk Multiplication
# / percent Also modulus operator, which returns the remainder from division
# < less-than Returns true if the operans on the LHS is less than RHS
# > greater-than Returns true if the operand on the LHS is greater than RHS
# <= less-than-equal Returns true if the operand on the LHS is less than or equal to RHS
# >= greater-than-equal Returns true if the operand on the LHS is greater than or equal to the RHS