From 2669bc8ff63e1efa26ccb372c02b9453e0c4cb02 Mon Sep 17 00:00:00 2001 From: Jakehp Date: Sat, 29 Jun 2013 12:12:23 -0500 Subject: java --- java.html.markdown | 369 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 369 insertions(+) create mode 100644 java.html.markdown (limited to 'java.html.markdown') diff --git a/java.html.markdown b/java.html.markdown new file mode 100644 index 00000000..d780d515 --- /dev/null +++ b/java.html.markdown @@ -0,0 +1,369 @@ +--- +language: java +author: Jake Prather +author_url: http://github.com/JakeHP +--- + +Java is a general-purpose, concurrent, class-based, object-oriented computer programming language. +Read more here: https://en.wikipedia.org/wiki/Java_(programming_language) + +```java +// Single-line comments start with // +/* +Multi-line comments look like this. +*/ + +// Import Packages +import java.util.ArrayList; +import package.path.here; +// Import "sub-packages" +import java.lang.Math.*; + +// Your program's entry point is a function called main +public class Main +{ + public static void main (String[] args) throws java.lang.Exception + { + //stuff here + } +} + +// Printing +System.out.println("Hello World"); +System.out.println("Integer: "+10+"Double: "+3.14+ "Boolean: "+true); + +/////////////////////////////////////// +// Types +/////////////////////////////////////// + +// You have to declare variables before using them. A variable declaration +// requires you to specify its type; a variable's type determines its size +// in bytes. + +// Integers +int x_int = 0; + +// shorts are usually 2 bytes +short x_short = 0; + +// chars are guaranteed to be 1 byte +char x_char = 0; +char y_char = 'y'; // Char literals are quoted with '' + +// longs are often 4 to 8 bytes; long longs are guaranteed to be at least +// 64 bits +long x_long = 0; +long long x_long_long = 0; + +// floats are usually 32-bit floating point numbers +float x_float = 0.0; + +// doubles are usually 64-bit floating-point numbers +double x_double = 0.0; + +// Integral types may be unsigned. This means they can't be negative, but +// the maximum value of an unsigned variable is greater than the maximum +// value of the same size. +unsigned char ux_char; +unsigned short ux_short; +unsigned int ux_int; +unsigned long long ux_long_long; + +// Other than char, which is always 1 byte, these types vary in size depending +// on your machine. sizeof(T) gives you the size of a variable with type T in +// bytes so you can express the size of these types in a portable way. +// For example, +printf("%d\n", sizeof(int)); // => 4 (on machines with 4-byte words) + +// Arrays must be initialized with a concrete size. +char my_char_array[20]; // This array occupies 1 * 20 = 20 bytes +int my_int_array[20]; // This array occupies 4 * 20 = 80 bytes + // (assuming 4-byte words) + + +// You can initialize an array to 0 thusly: +char my_array[20] = {0}; + +// Indexing an array is like other languages -- or, +// rather, other languages are like C +my_array[0]; // => 0 + +// Arrays are mutable; it's just memory! +my_array[1] = 2; +printf("%d\n", my_array[1]); // => 2 + +// Strings are just arrays of chars terminated by a NUL (0x00) byte, +// represented in strings as the special character '\0'. +// (We don't have to include the NUL byte in string literals; the compiler +// inserts it at the end of the array for us.) +char a_string[20] = "This is a string"; +printf("%s\n", a_string); // %s formats a string + +/* +You may have noticed that a_string is only 16 chars long. +Char #17 is the NUL byte. +Chars #18, 19 and 20 have undefined values. +*/ + +printf("%d\n", a_string[16]); => 0 + +/////////////////////////////////////// +// Operators +/////////////////////////////////////// + +int i1 = 1, i2 = 2; // Shorthand for multiple declaration +float f1 = 1.0, f2 = 2.0; + +// Arithmetic is straightforward +i1 + i2; // => 3 +i2 - i1; // => 1 +i2 * i1; // => 2 +i1 / i2; // => 0 (0.5, but truncated towards 0) + +f1 / f2; // => 0.5, plus or minus epsilon + +// Modulo is there as well +11 % 3; // => 2 + +// Comparison operators are probably familiar, but +// there is no boolean type in c. We use ints instead. +// 0 is false, anything else is true. (The comparison +// operators always return 0 or 1.) +3 == 2; // => 0 (false) +3 != 2; // => 1 (true) +3 > 2; // => 1 +3 < 2; // => 0 +2 <= 2; // => 1 +2 >= 2; // => 1 + +// Logic works on ints +!3; // => 0 (Logical not) +!0; // => 1 +1 && 1; // => 1 (Logical and) +0 && 1; // => 0 +0 || 1; // => 1 (Logical or) +0 || 0; // => 0 + +// Bitwise operators! +~0x0F; // => 0xF0 (bitwise negation) +0x0F & 0xF0; // => 0x00 (bitwise AND) +0x0F | 0xF0; // => 0xFF (bitwise OR) +0x04 ^ 0x0F; // => 0x0B (bitwise XOR) +0x01 << 1; // => 0x02 (bitwise left shift (by 1)) +0x02 >> 1; // => 0x01 (bitwise right shift (by 1)) + +/////////////////////////////////////// +// Control Structures +/////////////////////////////////////// + +if (0) { + printf("I am never run\n"); +} else if (0) { + printf("I am also never run\n"); +} else { + printf("I print\n"); +} + +// While loops exist +int ii = 0; +while (ii < 10) { + printf("%d, ", ii++); // ii++ increments ii in-place, after using its value. +} // => prints "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, " + +printf("\n"); + +int kk = 0; +do { + printf("%d, ", kk); +} while (++kk < 10); // ++kk increments kk in-place, before using its value +// => prints "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, " + +printf("\n"); + +// For loops too +int jj; +for (jj=0; jj < 10; jj++) { + printf("%d, ", jj); +} // => prints "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, " + +printf("\n"); + +/////////////////////////////////////// +// Typecasting +/////////////////////////////////////// + +// Every value in C has a type, but you can cast one value into another type +// if you want. + +int x_hex = 0x01; // You can assign vars with hex literals + +// Casting between types will attempt to preserve their numeric values +printf("%d\n", x_hex); // => Prints 1 +printf("%d\n", (short) x_hex); // => Prints 1 +printf("%d\n", (char) x_hex); // => Prints 1 + +// Types will overflow without warning +printf("%d\n", (char) 257); // => 1 (Max char = 255) + +// Integral types can be cast to floating-point types, and vice-versa. +printf("%f\n", (float)100); // %f formats a float +printf("%lf\n", (double)100); // %lf formats a double +printf("%d\n", (char)100.0); + +/////////////////////////////////////// +// Pointers +/////////////////////////////////////// + +// A pointer is a variable declared to store a memory address. Its declaration will +// also tell you the type of data it points to. You can retrieve the memory address +// of your variables, then mess with them. + +int x = 0; +printf("%p\n", &x); // Use & to retrieve the address of a variable +// (%p formats a pointer) +// => Prints some address in memory; + +// Pointer types end with * in their declaration +int* px; // px is a pointer to an int +px = &x; // Stores the address of x in px +printf("%p\n", px); // => Prints some address in memory + +// To retreive the value at the address a pointer is pointing to, +// put * in front to de-reference it. +printf("%d\n", *px); // => Prints 0, the value of x, which is what px is pointing to the address of + +// You can also change the value the pointer is pointing to. +// We'll have to wrap the de-reference in parenthesis because +// ++ has a higher precedence than *. +(*px)++; // Increment the value px is pointing to by 1 +printf("%d\n", *px); // => Prints 1 +printf("%d\n", x); // => Prints 1 + +int x_array[20]; // Arrays are a good way to allocate a contiguous block of memory +int xx; +for (xx=0; xx<20; xx++) { + x_array[xx] = 20 - xx; +} // Initialize x_array to 20, 19, 18,... 2, 1 + +// Declare a pointer of type int and initialize it to point to x_array +int* x_ptr = x_array; +// x_ptr now points to the first element in the array (the integer 20). +// This works because arrays are actually just pointers to their first element. + +// Arrays are pointers to their first element +printf("%d\n", *(x_ptr)); // => Prints 20 +printf("%d\n", x_array[0]); // => Prints 20 + +// Pointers are incremented and decremented based on their type +printf("%d\n", *(x_ptr + 1)); // => Prints 19 +printf("%d\n", x_array[1]); // => Prints 19 + +// You can also dynamically allocate contiguous blocks of memory with the +// standard library function malloc, which takes one integer argument +// representing the number of bytes to allocate from the heap. +int* my_ptr = (int*) malloc(sizeof(int) * 20); +for (xx=0; xx<20; xx++) { + *(my_ptr + xx) = 20 - xx; // my_ptr[xx] = 20-xx would also work here +} // Initialize memory to 20, 19, 18, 17... 2, 1 (as ints) + +// Dereferencing memory that you haven't allocated gives +// unpredictable results +printf("%d\n", *(my_ptr + 21)); // => Prints who-knows-what? + +// When you're done with a malloc'd block of memory, you need to free it, +// or else no one else can use it until your program terminates +free(my_ptr); + +// Strings can be char arrays, but are usually represented as char +// pointers: +char* my_str = "This is my very own string"; + +printf("%c\n", *my_str); // => 'T' + +function_1(); +} // end main function + +/////////////////////////////////////// +// Functions +/////////////////////////////////////// + +// Function declaration syntax: +// () + +int add_two_ints(int x1, int x2){ + return x1 + x2; // Use return to return a value +} + +/* +Functions are pass-by-value, but you can make your own references +with pointers so functions can mutate their values. + +Example: in-place string reversal +*/ + +// A void function returns no value +void str_reverse(char* str_in){ + char tmp; + int ii=0, len = strlen(str_in); // Strlen is part of the c standard library + for(ii=0; ii ".tset a si sihT" +*/ + +/////////////////////////////////////// +// User-defined types and structs +/////////////////////////////////////// + +// Typedefs can be used to create type aliases +typedef int my_type; +my_type my_type_var = 0; + +// Structs are just collections of data +struct rectangle { + int width; + int height; +}; + + +void function_1(){ + + struct rectangle my_rec; + + // Access struct members with . + my_rec.width = 10; + my_rec.height = 20; + + // You can declare pointers to structs + struct rectangle* my_rec_ptr = &my_rec; + + // Use dereferencing to set struct pointer members... + (*my_rec_ptr).width = 30; + + // ... or use the -> shorthand + my_rec_ptr->height = 10; // Same as (*my_rec_ptr).height = 10; +} + +// You can apply a typedef to a struct for convenience +typedef struct rectangle rect; + +int area(rect r){ + return r.width * r.height; +} + +``` + +## Further Reading + +Best to find yourself a copy of [K&R, aka "The C Programming Language"](https://en.wikipedia.org/wiki/The_C_Programming_Language) + +Another good resource is [Learn C the hard way](http://c.learncodethehardway.org/book/) + +Other than that, Google is your friend. -- cgit v1.2.3 From d32bad8aed47e58c4f675d9487537ac42d54004e Mon Sep 17 00:00:00 2001 From: Jakehp Date: Sat, 29 Jun 2013 12:46:34 -0500 Subject: up --- java.html.markdown | 49 +++++++++++++++++-------------------------------- 1 file changed, 17 insertions(+), 32 deletions(-) (limited to 'java.html.markdown') diff --git a/java.html.markdown b/java.html.markdown index d780d515..48e1ff36 100644 --- a/java.html.markdown +++ b/java.html.markdown @@ -36,38 +36,23 @@ System.out.println("Integer: "+10+"Double: "+3.14+ "Boolean: "+true); // Types /////////////////////////////////////// -// You have to declare variables before using them. A variable declaration -// requires you to specify its type; a variable's type determines its size -// in bytes. - -// Integers -int x_int = 0; - -// shorts are usually 2 bytes -short x_short = 0; - -// chars are guaranteed to be 1 byte -char x_char = 0; -char y_char = 'y'; // Char literals are quoted with '' - -// longs are often 4 to 8 bytes; long longs are guaranteed to be at least -// 64 bits -long x_long = 0; -long long x_long_long = 0; - -// floats are usually 32-bit floating point numbers -float x_float = 0.0; - -// doubles are usually 64-bit floating-point numbers -double x_double = 0.0; - -// Integral types may be unsigned. This means they can't be negative, but -// the maximum value of an unsigned variable is greater than the maximum -// value of the same size. -unsigned char ux_char; -unsigned short ux_short; -unsigned int ux_int; -unsigned long long ux_long_long; +// Byte - 8-bit signed two's complement integer (-128 <= byte <= 127) + +// Short - 16-bit signed two's complement integer (-32,768 <= short <= 32,767) + +//Integer - 32-bit signed two's complement integer (-2,147,483,648 <= int <= 2,147,483,647) +int x = 1; + +//Long - 64-bit signed two's complement integer (-9,223,372,036,854,775,808 <= long <= 9,223,372,036,854,775,807) + +//Float - Single-precision 32-bit IEEE 754 Floating Point + +//Double - Double-precision 64-bit IEEE 754 Floating Point + +//Boolean - True & False + +//Char - A single 16-bit Unicode character + // Other than char, which is always 1 byte, these types vary in size depending // on your machine. sizeof(T) gives you the size of a variable with type T in -- cgit v1.2.3 From 4b873348fce636644917b812fbf746f59b56bcc4 Mon Sep 17 00:00:00 2001 From: Jake Prather Date: Sat, 29 Jun 2013 22:12:03 -0500 Subject: Update java.html.markdown --- java.html.markdown | 290 ++++++++++++++++++++++++++--------------------------- 1 file changed, 144 insertions(+), 146 deletions(-) (limited to 'java.html.markdown') diff --git a/java.html.markdown b/java.html.markdown index 48e1ff36..0ca36132 100644 --- a/java.html.markdown +++ b/java.html.markdown @@ -1,177 +1,175 @@ --- + language: java + author: Jake Prather + author_url: http://github.com/JakeHP + --- Java is a general-purpose, concurrent, class-based, object-oriented computer programming language. Read more here: https://en.wikipedia.org/wiki/Java_(programming_language) ```java -// Single-line comments start with // -/* -Multi-line comments look like this. -*/ - -// Import Packages -import java.util.ArrayList; -import package.path.here; -// Import "sub-packages" -import java.lang.Math.*; - -// Your program's entry point is a function called main -public class Main -{ - public static void main (String[] args) throws java.lang.Exception +/////////////////////////////////////// +// General +/////////////////////////////////////// + // Single-line comments start with // + /* + Multi-line comments look like this. + */ + + // Import Packages + import java.util.ArrayList; + import package.path.here; + // Import all "sub-packages" + import java.lang.Math.*; + + // Your program's entry point is a function called main + public class Main { - //stuff here + public static void main (String[] args) throws java.lang.Exception + { + //stuff here + } } -} - -// Printing -System.out.println("Hello World"); -System.out.println("Integer: "+10+"Double: "+3.14+ "Boolean: "+true); + + // Printing, and forcing a new line on next print = println() + System.out.println("Hello World"); + System.out.println("Integer: "+10+"Double: "+3.14+ "Boolean: "+true); + // Printing, without forcing a new line on next print = print() + System.out.print("Hello World"); + System.out.print("Integer: "+10+"Double: "+3.14+ "Boolean: "+true); /////////////////////////////////////// // Types /////////////////////////////////////// -// Byte - 8-bit signed two's complement integer (-128 <= byte <= 127) - -// Short - 16-bit signed two's complement integer (-32,768 <= short <= 32,767) - -//Integer - 32-bit signed two's complement integer (-2,147,483,648 <= int <= 2,147,483,647) -int x = 1; - -//Long - 64-bit signed two's complement integer (-9,223,372,036,854,775,808 <= long <= 9,223,372,036,854,775,807) - -//Float - Single-precision 32-bit IEEE 754 Floating Point - -//Double - Double-precision 64-bit IEEE 754 Floating Point - -//Boolean - True & False - -//Char - A single 16-bit Unicode character - - -// Other than char, which is always 1 byte, these types vary in size depending -// on your machine. sizeof(T) gives you the size of a variable with type T in -// bytes so you can express the size of these types in a portable way. -// For example, -printf("%d\n", sizeof(int)); // => 4 (on machines with 4-byte words) - -// Arrays must be initialized with a concrete size. -char my_char_array[20]; // This array occupies 1 * 20 = 20 bytes -int my_int_array[20]; // This array occupies 4 * 20 = 80 bytes - // (assuming 4-byte words) - - -// You can initialize an array to 0 thusly: -char my_array[20] = {0}; - -// Indexing an array is like other languages -- or, -// rather, other languages are like C -my_array[0]; // => 0 - -// Arrays are mutable; it's just memory! -my_array[1] = 2; -printf("%d\n", my_array[1]); // => 2 - -// Strings are just arrays of chars terminated by a NUL (0x00) byte, -// represented in strings as the special character '\0'. -// (We don't have to include the NUL byte in string literals; the compiler -// inserts it at the end of the array for us.) -char a_string[20] = "This is a string"; -printf("%s\n", a_string); // %s formats a string - -/* -You may have noticed that a_string is only 16 chars long. -Char #17 is the NUL byte. -Chars #18, 19 and 20 have undefined values. -*/ - -printf("%d\n", a_string[16]); => 0 + // Byte - 8-bit signed two's complement integer (-128 <= byte <= 127) + byte foo = 100; + + // Short - 16-bit signed two's complement integer (-32,768 <= short <= 32,767) + short bar = 10000; + + //Integer - 32-bit signed two's complement integer (-2,147,483,648 <= int <= 2,147,483,647) + int foo = 1; + + //Long - 64-bit signed two's complement integer (-9,223,372,036,854,775,808 <= long <= 9,223,372,036,854,775,807) + long bar = 100000L; + + //Float - Single-precision 32-bit IEEE 754 Floating Point + float foo = 234.5f; + + //Double - Double-precision 64-bit IEEE 754 Floating Point + double bar = 123.4; + + //Boolean - True & False + boolean foo = true; + boolean bar = false; + + //Char - A single 16-bit Unicode character + char foo = 'A'; + + //Strings + String foo = "Hello World!"; + // \n is an escaped character that starts a new line + String foo = "Hello World!\nLine2!"; + System.out.println(foo); + //Hello World! + //Line2! + + //Arrays + //The array size must be decided upon declaration + //The format for declaring an array is follows: + // [] = new []; + int [] array = new int[10]; + String [] array = new String[1]; + boolean [] array = new boolean[100]; + + // Indexing an array - Accessing an element + array[0]; + + // Arrays are mutable; it's just memory! + array[1] = 1; + System.out.println(array[1]); // => 1 + array[1] = 2; + printf("%d\n", my_array[1]); // => 2 + + //Others to check out + //ArrayLists - Like arrays except more functionality is offered, and the size is mutable + //LinkedLists + //Maps + //HashMaps /////////////////////////////////////// // Operators /////////////////////////////////////// -int i1 = 1, i2 = 2; // Shorthand for multiple declaration -float f1 = 1.0, f2 = 2.0; - -// Arithmetic is straightforward -i1 + i2; // => 3 -i2 - i1; // => 1 -i2 * i1; // => 2 -i1 / i2; // => 0 (0.5, but truncated towards 0) - -f1 / f2; // => 0.5, plus or minus epsilon - -// Modulo is there as well -11 % 3; // => 2 - -// Comparison operators are probably familiar, but -// there is no boolean type in c. We use ints instead. -// 0 is false, anything else is true. (The comparison -// operators always return 0 or 1.) -3 == 2; // => 0 (false) -3 != 2; // => 1 (true) -3 > 2; // => 1 -3 < 2; // => 0 -2 <= 2; // => 1 -2 >= 2; // => 1 - -// Logic works on ints -!3; // => 0 (Logical not) -!0; // => 1 -1 && 1; // => 1 (Logical and) -0 && 1; // => 0 -0 || 1; // => 1 (Logical or) -0 || 0; // => 0 - -// Bitwise operators! -~0x0F; // => 0xF0 (bitwise negation) -0x0F & 0xF0; // => 0x00 (bitwise AND) -0x0F | 0xF0; // => 0xFF (bitwise OR) -0x04 ^ 0x0F; // => 0x0B (bitwise XOR) -0x01 << 1; // => 0x02 (bitwise left shift (by 1)) -0x02 >> 1; // => 0x01 (bitwise right shift (by 1)) + int i1 = 1, i2 = 2; // Shorthand for multiple declarations + + // Arithmetic is straightforward + i1 + i2; // => 3 + i2 - i1; // => 1 + i2 * i1; // => 2 + i1 / i2; // => 0 (0.5, but truncated towards 0) + + // Modulo + 11 % 3; // => 2 + + // Comparison operators + 3 == 2; // => 0 (false) + 3 != 2; // => 1 (true) + 3 > 2; // => 1 + 3 < 2; // => 0 + 2 <= 2; // => 1 + 2 >= 2; // => 1 + + // Bitwise operators! + ~ Unary bitwise complement + << Signed left shift + >> Signed right shift + >>> Unsigned right shift + & Bitwise AND + ^ Bitwise exclusive OR + | Bitwise inclusive OR /////////////////////////////////////// // Control Structures /////////////////////////////////////// -if (0) { - printf("I am never run\n"); -} else if (0) { - printf("I am also never run\n"); -} else { - printf("I print\n"); -} - -// While loops exist -int ii = 0; -while (ii < 10) { - printf("%d, ", ii++); // ii++ increments ii in-place, after using its value. -} // => prints "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, " - -printf("\n"); - -int kk = 0; -do { - printf("%d, ", kk); -} while (++kk < 10); // ++kk increments kk in-place, before using its value -// => prints "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, " - -printf("\n"); - -// For loops too -int jj; -for (jj=0; jj < 10; jj++) { - printf("%d, ", jj); -} // => prints "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, " + if (false) { + System.out.println("I never run"); + } else if (false) { + System.out.println("I am also never run"); + } else { + System.out.println("I print"); + } + } -printf("\n"); + // While loops exist + int ii = 0; + while (ii < 10) { + printf("%d, ", ii++); // ii++ increments ii in-place, after using its value. + } // => prints "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, " + + printf("\n"); + + int kk = 0; + do { + printf("%d, ", kk); + } while (++kk < 10); // ++kk increments kk in-place, before using its value + // => prints "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, " + + printf("\n"); + + // For loops too + int jj; + for (jj=0; jj < 10; jj++) { + printf("%d, ", jj); + } // => prints "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, " + + printf("\n"); /////////////////////////////////////// // Typecasting -- cgit v1.2.3 From 5b29da12e6d595bce088a8d25c956abbdb5fee7a Mon Sep 17 00:00:00 2001 From: Jake Prather Date: Sat, 29 Jun 2013 22:52:18 -0500 Subject: Update java.html.markdown --- java.html.markdown | 299 ++++++++++++++++++++--------------------------------- 1 file changed, 114 insertions(+), 185 deletions(-) (limited to 'java.html.markdown') diff --git a/java.html.markdown b/java.html.markdown index 0ca36132..2f9c143b 100644 --- a/java.html.markdown +++ b/java.html.markdown @@ -71,6 +71,9 @@ Read more here: https://en.wikipedia.org/wiki/Java_(programming_language) //Char - A single 16-bit Unicode character char foo = 'A'; + //Make a variable a constant + final int HOURS_I_WORK_PER_WEEK = 9001; + //Strings String foo = "Hello World!"; // \n is an escaped character that starts a new line @@ -133,6 +136,13 @@ Read more here: https://en.wikipedia.org/wiki/Java_(programming_language) & Bitwise AND ^ Bitwise exclusive OR | Bitwise inclusive OR + + // Incrementations + int i=0; + i++; //i = 1. Post Incrementation + ++i; //i = 2. Pre Incrementation + i--; //i = 1. Post Decrementation + --i; //i = 0. Pre Decrementation /////////////////////////////////////// // Control Structures @@ -147,206 +157,125 @@ Read more here: https://en.wikipedia.org/wiki/Java_(programming_language) } } - // While loops exist - int ii = 0; - while (ii < 10) { - printf("%d, ", ii++); // ii++ increments ii in-place, after using its value. - } // => prints "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, " - - printf("\n"); - - int kk = 0; - do { - printf("%d, ", kk); - } while (++kk < 10); // ++kk increments kk in-place, before using its value - // => prints "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, " + // While loop + int i = 0; + while(i < 100){ + System.out.println(i); + //Increment the counter + i++; + } - printf("\n"); + // Do While Loop + int i = 0; + do{ + System.out.println(i); + //Increment the counter + i++; + }while(i < 100); - // For loops too - int jj; - for (jj=0; jj < 10; jj++) { - printf("%d, ", jj); - } // => prints "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, " + // For Loop + int i; + //for loop structure => for(;;) + for(i=0;i<100;i++){ + System.out.println(i); + } - printf("\n"); /////////////////////////////////////// // Typecasting /////////////////////////////////////// -// Every value in C has a type, but you can cast one value into another type -// if you want. - -int x_hex = 0x01; // You can assign vars with hex literals - -// Casting between types will attempt to preserve their numeric values -printf("%d\n", x_hex); // => Prints 1 -printf("%d\n", (short) x_hex); // => Prints 1 -printf("%d\n", (char) x_hex); // => Prints 1 - -// Types will overflow without warning -printf("%d\n", (char) 257); // => 1 (Max char = 255) - -// Integral types can be cast to floating-point types, and vice-versa. -printf("%f\n", (float)100); // %f formats a float -printf("%lf\n", (double)100); // %lf formats a double -printf("%d\n", (char)100.0); - -/////////////////////////////////////// -// Pointers -/////////////////////////////////////// - -// A pointer is a variable declared to store a memory address. Its declaration will -// also tell you the type of data it points to. You can retrieve the memory address -// of your variables, then mess with them. - -int x = 0; -printf("%p\n", &x); // Use & to retrieve the address of a variable -// (%p formats a pointer) -// => Prints some address in memory; - -// Pointer types end with * in their declaration -int* px; // px is a pointer to an int -px = &x; // Stores the address of x in px -printf("%p\n", px); // => Prints some address in memory - -// To retreive the value at the address a pointer is pointing to, -// put * in front to de-reference it. -printf("%d\n", *px); // => Prints 0, the value of x, which is what px is pointing to the address of - -// You can also change the value the pointer is pointing to. -// We'll have to wrap the de-reference in parenthesis because -// ++ has a higher precedence than *. -(*px)++; // Increment the value px is pointing to by 1 -printf("%d\n", *px); // => Prints 1 -printf("%d\n", x); // => Prints 1 - -int x_array[20]; // Arrays are a good way to allocate a contiguous block of memory -int xx; -for (xx=0; xx<20; xx++) { - x_array[xx] = 20 - xx; -} // Initialize x_array to 20, 19, 18,... 2, 1 - -// Declare a pointer of type int and initialize it to point to x_array -int* x_ptr = x_array; -// x_ptr now points to the first element in the array (the integer 20). -// This works because arrays are actually just pointers to their first element. - -// Arrays are pointers to their first element -printf("%d\n", *(x_ptr)); // => Prints 20 -printf("%d\n", x_array[0]); // => Prints 20 - -// Pointers are incremented and decremented based on their type -printf("%d\n", *(x_ptr + 1)); // => Prints 19 -printf("%d\n", x_array[1]); // => Prints 19 - -// You can also dynamically allocate contiguous blocks of memory with the -// standard library function malloc, which takes one integer argument -// representing the number of bytes to allocate from the heap. -int* my_ptr = (int*) malloc(sizeof(int) * 20); -for (xx=0; xx<20; xx++) { - *(my_ptr + xx) = 20 - xx; // my_ptr[xx] = 20-xx would also work here -} // Initialize memory to 20, 19, 18, 17... 2, 1 (as ints) - -// Dereferencing memory that you haven't allocated gives -// unpredictable results -printf("%d\n", *(my_ptr + 21)); // => Prints who-knows-what? - -// When you're done with a malloc'd block of memory, you need to free it, -// or else no one else can use it until your program terminates -free(my_ptr); - -// Strings can be char arrays, but are usually represented as char -// pointers: -char* my_str = "This is my very own string"; - -printf("%c\n", *my_str); // => 'T' - -function_1(); -} // end main function - -/////////////////////////////////////// -// Functions -/////////////////////////////////////// - -// Function declaration syntax: -// () - -int add_two_ints(int x1, int x2){ - return x1 + x2; // Use return to return a value -} - -/* -Functions are pass-by-value, but you can make your own references -with pointers so functions can mutate their values. - -Example: in-place string reversal -*/ - -// A void function returns no value -void str_reverse(char* str_in){ - char tmp; - int ii=0, len = strlen(str_in); // Strlen is part of the c standard library - for(ii=0; ii ".tset a si sihT" -*/ + // Converting data + + //Convert String To Integer + Integer.parseInt("123");//returns an integer version of "123" + + //Convert Integer To String + Integer.toString(123);//returns a string version of 123 + + //For other conversions check out the following classes: + //Double + //Long + //String + + // You can also cast java objects, there's a lot of details and + // deals with some more intermediate concepts. + // Feel free to check it out here: http://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html + /////////////////////////////////////// -// User-defined types and structs +// Classes And Functions /////////////////////////////////////// -// Typedefs can be used to create type aliases -typedef int my_type; -my_type my_type_var = 0; - -// Structs are just collections of data -struct rectangle { - int width; - int height; -}; - - -void function_1(){ - - struct rectangle my_rec; - - // Access struct members with . - my_rec.width = 10; - my_rec.height = 20; - - // You can declare pointers to structs - struct rectangle* my_rec_ptr = &my_rec; + // Classes Syntax shown below. + // Function declaration syntax: + // () + // Here is a quick rundown on access level modifiers (public, private, etcetc) http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html - // Use dereferencing to set struct pointer members... - (*my_rec_ptr).width = 30; - - // ... or use the -> shorthand - my_rec_ptr->height = 10; // Same as (*my_rec_ptr).height = 10; -} - -// You can apply a typedef to a struct for convenience -typedef struct rectangle rect; - -int area(rect r){ - return r.width * r.height; -} + + public class Bicycle { + + // Bicycle's Fields/Variables + public int cadence; + public int gear; + public int speed; + + // Constructors are a way of creating classes + // This is a default constructor + public Bicycle(){ + gear = 1; + cadence = 50; + startGear = 1; + } + + // This is a specified constructor (it contains arguments) + public Bicycle(int startCadence, int startSpeed, int startGear) { + gear = startGear; + cadence = startCadence; + speed = startSpeed; + } + + // the Bicycle class has + // four methods + public void setCadence(int newValue) { + cadence = newValue; + } + + public void setGear(int newValue) { + gear = newValue; + } + + public void applyBrake(int decrement) { + speed -= decrement; + } + + public void speedUp(int increment) { + speed += increment; + } + + } + + //Now..Later in the main / driver of your java program + + public class Main + { + public static void main (String[] args) throws java.lang.Exception + { + //Call bicycle's constructor + Bicycle trek = new Bicycle(); + trek.speedUp(3); + trek.setCadence(100); + } + } ``` ## Further Reading -Best to find yourself a copy of [K&R, aka "The C Programming Language"](https://en.wikipedia.org/wiki/The_C_Programming_Language) - -Another good resource is [Learn C the hard way](http://c.learncodethehardway.org/book/) - -Other than that, Google is your friend. +Other Topics To Research: + -Inheritance (http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming)) + -Abstraction (http://en.wikipedia.org/wiki/Abstraction_(computer_science)) + -Exceptions (http://en.wikipedia.org/wiki/Exception_handling) + -Interfaces (http://en.wikipedia.org/wiki/Interfaces_(computer_science)) + -Generics (http://en.wikipedia.org/wiki/Generics_in_Java) + The links provided are just to get an understanding of the topic, feel free to google and find specific examples -- cgit v1.2.3 From 64c292a05976a0f61f7699102bf4e344747675c1 Mon Sep 17 00:00:00 2001 From: Jake Prather Date: Sat, 29 Jun 2013 22:54:10 -0500 Subject: Update java.html.markdown --- java.html.markdown | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'java.html.markdown') diff --git a/java.html.markdown b/java.html.markdown index 2f9c143b..80271f7f 100644 --- a/java.html.markdown +++ b/java.html.markdown @@ -180,6 +180,38 @@ Read more here: https://en.wikipedia.org/wiki/Java_(programming_language) System.out.println(i); } + // Switch Case + int month = 8; + String monthString; + switch (month) { + case 1: monthString = "January"; + break; + case 2: monthString = "February"; + break; + case 3: monthString = "March"; + break; + case 4: monthString = "April"; + break; + case 5: monthString = "May"; + break; + case 6: monthString = "June"; + break; + case 7: monthString = "July"; + break; + case 8: monthString = "August"; + break; + case 9: monthString = "September"; + break; + case 10: monthString = "October"; + break; + case 11: monthString = "November"; + break; + case 12: monthString = "December"; + break; + default: monthString = "Invalid month"; + break; + } + System.out.println(monthString); /////////////////////////////////////// // Typecasting -- cgit v1.2.3 From 9c9f2c6b9a50ccc7a987d3c9bf6fd26bd1cc3d15 Mon Sep 17 00:00:00 2001 From: Jake Prather Date: Sat, 29 Jun 2013 22:54:53 -0500 Subject: Update java.html.markdown --- java.html.markdown | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'java.html.markdown') diff --git a/java.html.markdown b/java.html.markdown index 80271f7f..5f8aec2b 100644 --- a/java.html.markdown +++ b/java.html.markdown @@ -305,9 +305,15 @@ Read more here: https://en.wikipedia.org/wiki/Java_(programming_language) ## Further Reading Other Topics To Research: - -Inheritance (http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming)) - -Abstraction (http://en.wikipedia.org/wiki/Abstraction_(computer_science)) - -Exceptions (http://en.wikipedia.org/wiki/Exception_handling) - -Interfaces (http://en.wikipedia.org/wiki/Interfaces_(computer_science)) - -Generics (http://en.wikipedia.org/wiki/Generics_in_Java) - The links provided are just to get an understanding of the topic, feel free to google and find specific examples + + * Inheritance (http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming)) + + * Abstraction (http://en.wikipedia.org/wiki/Abstraction_(computer_science)) + + * Exceptions (http://en.wikipedia.org/wiki/Exception_handling) + + * Interfaces (http://en.wikipedia.org/wiki/Interfaces_(computer_science)) + + * Generics (http://en.wikipedia.org/wiki/Generics_in_Java) + + * The links provided are just to get an understanding of the topic, feel free to google and find specific examples -- cgit v1.2.3 From 0523de70a1335c036442863b6dc672d50157d66a Mon Sep 17 00:00:00 2001 From: Jake Prather Date: Sat, 29 Jun 2013 22:56:22 -0500 Subject: Update java.html.markdown --- java.html.markdown | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'java.html.markdown') diff --git a/java.html.markdown b/java.html.markdown index 5f8aec2b..e14f356d 100644 --- a/java.html.markdown +++ b/java.html.markdown @@ -97,7 +97,7 @@ Read more here: https://en.wikipedia.org/wiki/Java_(programming_language) array[1] = 1; System.out.println(array[1]); // => 1 array[1] = 2; - printf("%d\n", my_array[1]); // => 2 + System.out.println(array[1]); // => 2 //Others to check out //ArrayLists - Like arrays except more functionality is offered, and the size is mutable @@ -139,10 +139,10 @@ Read more here: https://en.wikipedia.org/wiki/Java_(programming_language) // Incrementations int i=0; - i++; //i = 1. Post Incrementation - ++i; //i = 2. Pre Incrementation - i--; //i = 1. Post Decrementation - --i; //i = 0. Pre Decrementation + i++; //i = 1. Post-Incrementation + ++i; //i = 2. Pre-Incrementation + i--; //i = 1. Post-Decrementation + --i; //i = 0. Pre-Decrementation /////////////////////////////////////// // Control Structures @@ -288,13 +288,13 @@ Read more here: https://en.wikipedia.org/wiki/Java_(programming_language) } //Now..Later in the main / driver of your java program - public class Main { public static void main (String[] args) throws java.lang.Exception { //Call bicycle's constructor Bicycle trek = new Bicycle(); + //Manipulate your object trek.speedUp(3); trek.setCadence(100); } -- cgit v1.2.3 From ba55f6fcaadebbcd76501ab69b5be03a66d0460f Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 29 Jun 2013 23:13:53 -0700 Subject: Fix whitespace --- java.html.markdown | 480 ++++++++++++++++++++++++++--------------------------- 1 file changed, 240 insertions(+), 240 deletions(-) (limited to 'java.html.markdown') diff --git a/java.html.markdown b/java.html.markdown index e14f356d..f6890d9b 100644 --- a/java.html.markdown +++ b/java.html.markdown @@ -15,173 +15,173 @@ Read more here: https://en.wikipedia.org/wiki/Java_(programming_language) /////////////////////////////////////// // General /////////////////////////////////////// - // Single-line comments start with // - /* - Multi-line comments look like this. - */ - - // Import Packages - import java.util.ArrayList; - import package.path.here; - // Import all "sub-packages" - import java.lang.Math.*; - - // Your program's entry point is a function called main - public class Main - { - public static void main (String[] args) throws java.lang.Exception - { - //stuff here - } - } - - // Printing, and forcing a new line on next print = println() - System.out.println("Hello World"); - System.out.println("Integer: "+10+"Double: "+3.14+ "Boolean: "+true); - // Printing, without forcing a new line on next print = print() - System.out.print("Hello World"); - System.out.print("Integer: "+10+"Double: "+3.14+ "Boolean: "+true); +// Single-line comments start with // +/* +Multi-line comments look like this. +*/ + +// Import Packages +import java.util.ArrayList; +import package.path.here; +// Import all "sub-packages" +import java.lang.Math.*; + +// Your program's entry point is a function called main +public class Main +{ + public static void main (String[] args) throws java.lang.Exception + { + //stuff here + } +} + +// Printing, and forcing a new line on next print = println() +System.out.println("Hello World"); +System.out.println("Integer: "+10+"Double: "+3.14+ "Boolean: "+true); +// Printing, without forcing a new line on next print = print() +System.out.print("Hello World"); +System.out.print("Integer: "+10+"Double: "+3.14+ "Boolean: "+true); /////////////////////////////////////// // Types /////////////////////////////////////// - // Byte - 8-bit signed two's complement integer (-128 <= byte <= 127) - byte foo = 100; - - // Short - 16-bit signed two's complement integer (-32,768 <= short <= 32,767) - short bar = 10000; - - //Integer - 32-bit signed two's complement integer (-2,147,483,648 <= int <= 2,147,483,647) - int foo = 1; - - //Long - 64-bit signed two's complement integer (-9,223,372,036,854,775,808 <= long <= 9,223,372,036,854,775,807) - long bar = 100000L; - - //Float - Single-precision 32-bit IEEE 754 Floating Point - float foo = 234.5f; - - //Double - Double-precision 64-bit IEEE 754 Floating Point - double bar = 123.4; - - //Boolean - True & False - boolean foo = true; - boolean bar = false; - - //Char - A single 16-bit Unicode character - char foo = 'A'; - - //Make a variable a constant - final int HOURS_I_WORK_PER_WEEK = 9001; - - //Strings - String foo = "Hello World!"; - // \n is an escaped character that starts a new line - String foo = "Hello World!\nLine2!"; - System.out.println(foo); - //Hello World! - //Line2! - - //Arrays - //The array size must be decided upon declaration - //The format for declaring an array is follows: - // [] = new []; - int [] array = new int[10]; - String [] array = new String[1]; - boolean [] array = new boolean[100]; - - // Indexing an array - Accessing an element - array[0]; - - // Arrays are mutable; it's just memory! - array[1] = 1; - System.out.println(array[1]); // => 1 - array[1] = 2; - System.out.println(array[1]); // => 2 - - //Others to check out - //ArrayLists - Like arrays except more functionality is offered, and the size is mutable - //LinkedLists - //Maps - //HashMaps +// Byte - 8-bit signed two's complement integer (-128 <= byte <= 127) +byte foo = 100; + +// Short - 16-bit signed two's complement integer (-32,768 <= short <= 32,767) +short bar = 10000; + +//Integer - 32-bit signed two's complement integer (-2,147,483,648 <= int <= 2,147,483,647) +int foo = 1; + +//Long - 64-bit signed two's complement integer (-9,223,372,036,854,775,808 <= long <= 9,223,372,036,854,775,807) +long bar = 100000L; + +//Float - Single-precision 32-bit IEEE 754 Floating Point +float foo = 234.5f; + +//Double - Double-precision 64-bit IEEE 754 Floating Point +double bar = 123.4; + +//Boolean - True & False +boolean foo = true; +boolean bar = false; + +//Char - A single 16-bit Unicode character +char foo = 'A'; + +//Make a variable a constant +final int HOURS_I_WORK_PER_WEEK = 9001; + +//Strings +String foo = "Hello World!"; +// \n is an escaped character that starts a new line +String foo = "Hello World!\nLine2!"; +System.out.println(foo); +//Hello World! +//Line2! + +//Arrays +//The array size must be decided upon declaration +//The format for declaring an array is follows: +// [] = new []; +int [] array = new int[10]; +String [] array = new String[1]; +boolean [] array = new boolean[100]; + +// Indexing an array - Accessing an element +array[0]; + +// Arrays are mutable; it's just memory! +array[1] = 1; +System.out.println(array[1]); // => 1 +array[1] = 2; +System.out.println(array[1]); // => 2 + +//Others to check out +//ArrayLists - Like arrays except more functionality is offered, and the size is mutable +//LinkedLists +//Maps +//HashMaps /////////////////////////////////////// // Operators /////////////////////////////////////// - int i1 = 1, i2 = 2; // Shorthand for multiple declarations - - // Arithmetic is straightforward - i1 + i2; // => 3 - i2 - i1; // => 1 - i2 * i1; // => 2 - i1 / i2; // => 0 (0.5, but truncated towards 0) - - // Modulo - 11 % 3; // => 2 - - // Comparison operators - 3 == 2; // => 0 (false) - 3 != 2; // => 1 (true) - 3 > 2; // => 1 - 3 < 2; // => 0 - 2 <= 2; // => 1 - 2 >= 2; // => 1 - - // Bitwise operators! - ~ Unary bitwise complement - << Signed left shift - >> Signed right shift - >>> Unsigned right shift - & Bitwise AND - ^ Bitwise exclusive OR - | Bitwise inclusive OR - - // Incrementations - int i=0; - i++; //i = 1. Post-Incrementation - ++i; //i = 2. Pre-Incrementation - i--; //i = 1. Post-Decrementation - --i; //i = 0. Pre-Decrementation +int i1 = 1, i2 = 2; // Shorthand for multiple declarations + +// Arithmetic is straightforward +i1 + i2; // => 3 +i2 - i1; // => 1 +i2 * i1; // => 2 +i1 / i2; // => 0 (0.5, but truncated towards 0) + +// Modulo +11 % 3; // => 2 + +// Comparison operators +3 == 2; // => 0 (false) +3 != 2; // => 1 (true) +3 > 2; // => 1 +3 < 2; // => 0 +2 <= 2; // => 1 +2 >= 2; // => 1 + +// Bitwise operators! +~ Unary bitwise complement +<< Signed left shift +>> Signed right shift +>>> Unsigned right shift +& Bitwise AND +^ Bitwise exclusive OR +| Bitwise inclusive OR + +// Incrementations +int i=0; +i++; //i = 1. Post-Incrementation +++i; //i = 2. Pre-Incrementation +i--; //i = 1. Post-Decrementation +--i; //i = 0. Pre-Decrementation /////////////////////////////////////// // Control Structures /////////////////////////////////////// - if (false) { - System.out.println("I never run"); - } else if (false) { - System.out.println("I am also never run"); - } else { - System.out.println("I print"); - } - } - - // While loop - int i = 0; - while(i < 100){ - System.out.println(i); - //Increment the counter - i++; - } - - // Do While Loop - int i = 0; - do{ - System.out.println(i); - //Increment the counter - i++; - }while(i < 100); - - // For Loop - int i; - //for loop structure => for(;;) - for(i=0;i<100;i++){ - System.out.println(i); - } - - // Switch Case - int month = 8; +if (false) { + System.out.println("I never run"); + } else if (false) { + System.out.println("I am also never run"); + } else { + System.out.println("I print"); + } +} + +// While loop +int i = 0; +while(i < 100){ + System.out.println(i); + //Increment the counter + i++; +} + +// Do While Loop +int i = 0; +do{ + System.out.println(i); + //Increment the counter + i++; +}while(i < 100); + +// For Loop +int i; +//for loop structure => for(;;) +for(i=0;i<100;i++){ + System.out.println(i); +} + +// Switch Case +int month = 8; String monthString; switch (month) { case 1: monthString = "January"; @@ -217,88 +217,88 @@ Read more here: https://en.wikipedia.org/wiki/Java_(programming_language) // Typecasting /////////////////////////////////////// - // Converting data - - //Convert String To Integer - Integer.parseInt("123");//returns an integer version of "123" - - //Convert Integer To String - Integer.toString(123);//returns a string version of 123 - - //For other conversions check out the following classes: - //Double - //Long - //String - - // You can also cast java objects, there's a lot of details and - // deals with some more intermediate concepts. - // Feel free to check it out here: http://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html - +// Converting data + +//Convert String To Integer +Integer.parseInt("123");//returns an integer version of "123" + +//Convert Integer To String +Integer.toString(123);//returns a string version of 123 + +//For other conversions check out the following classes: +//Double +//Long +//String + +// You can also cast java objects, there's a lot of details and +// deals with some more intermediate concepts. +// Feel free to check it out here: http://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html + /////////////////////////////////////// // Classes And Functions /////////////////////////////////////// - // Classes Syntax shown below. - // Function declaration syntax: - // () - // Here is a quick rundown on access level modifiers (public, private, etcetc) http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html - - - public class Bicycle { - - // Bicycle's Fields/Variables - public int cadence; - public int gear; - public int speed; - - // Constructors are a way of creating classes - // This is a default constructor - public Bicycle(){ - gear = 1; - cadence = 50; - startGear = 1; - } - - // This is a specified constructor (it contains arguments) - public Bicycle(int startCadence, int startSpeed, int startGear) { - gear = startGear; - cadence = startCadence; - speed = startSpeed; - } - - // the Bicycle class has - // four methods - public void setCadence(int newValue) { - cadence = newValue; - } - - public void setGear(int newValue) { - gear = newValue; - } - - public void applyBrake(int decrement) { - speed -= decrement; - } - - public void speedUp(int increment) { - speed += increment; - } - - } - - //Now..Later in the main / driver of your java program - public class Main - { - public static void main (String[] args) throws java.lang.Exception - { - //Call bicycle's constructor - Bicycle trek = new Bicycle(); - //Manipulate your object - trek.speedUp(3); - trek.setCadence(100); - } - } +// Classes Syntax shown below. +// Function declaration syntax: +// () +// Here is a quick rundown on access level modifiers (public, private, etcetc) http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html + + +public class Bicycle { + + // Bicycle's Fields/Variables + public int cadence; + public int gear; + public int speed; + + // Constructors are a way of creating classes + // This is a default constructor + public Bicycle(){ + gear = 1; + cadence = 50; + startGear = 1; + } + + // This is a specified constructor (it contains arguments) + public Bicycle(int startCadence, int startSpeed, int startGear) { + gear = startGear; + cadence = startCadence; + speed = startSpeed; + } + + // the Bicycle class has + // four methods + public void setCadence(int newValue) { + cadence = newValue; + } + + public void setGear(int newValue) { + gear = newValue; + } + + public void applyBrake(int decrement) { + speed -= decrement; + } + + public void speedUp(int increment) { + speed += increment; + } + +} + +//Now..Later in the main / driver of your java program +public class Main +{ + public static void main (String[] args) throws java.lang.Exception + { + //Call bicycle's constructor + Bicycle trek = new Bicycle(); + //Manipulate your object + trek.speedUp(3); + trek.setCadence(100); + } +} ``` @@ -306,14 +306,14 @@ Read more here: https://en.wikipedia.org/wiki/Java_(programming_language) Other Topics To Research: - * Inheritance (http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming)) - - * Abstraction (http://en.wikipedia.org/wiki/Abstraction_(computer_science)) - - * Exceptions (http://en.wikipedia.org/wiki/Exception_handling) - - * Interfaces (http://en.wikipedia.org/wiki/Interfaces_(computer_science)) - - * Generics (http://en.wikipedia.org/wiki/Generics_in_Java) - - * The links provided are just to get an understanding of the topic, feel free to google and find specific examples +* Inheritance (http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming)) + +* Abstraction (http://en.wikipedia.org/wiki/Abstraction_(computer_science)) + +* Exceptions (http://en.wikipedia.org/wiki/Exception_handling) + +* Interfaces (http://en.wikipedia.org/wiki/Interfaces_(computer_science)) + +* Generics (http://en.wikipedia.org/wiki/Generics_in_Java) + +* The links provided are just to get an understanding of the topic, feel free to google and find specific examples -- cgit v1.2.3 From 0615be257d5d3437e256be8de9ed5abac4315f02 Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 29 Jun 2013 23:16:41 -0700 Subject: Fixed line lengths --- java.html.markdown | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'java.html.markdown') diff --git a/java.html.markdown b/java.html.markdown index f6890d9b..8d882234 100644 --- a/java.html.markdown +++ b/java.html.markdown @@ -12,9 +12,6 @@ Java is a general-purpose, concurrent, class-based, object-oriented computer pro Read more here: https://en.wikipedia.org/wiki/Java_(programming_language) ```java -/////////////////////////////////////// -// General -/////////////////////////////////////// // Single-line comments start with // /* Multi-line comments look like this. @@ -46,18 +43,24 @@ System.out.print("Integer: "+10+"Double: "+3.14+ "Boolean: "+true); // Types /////////////////////////////////////// -// Byte - 8-bit signed two's complement integer (-128 <= byte <= 127) +// Byte - 8-bit signed two's complement integer +// (-128 <= byte <= 127) byte foo = 100; -// Short - 16-bit signed two's complement integer (-32,768 <= short <= 32,767) +// Short - 16-bit signed two's complement integer +// (-32,768 <= short <= 32,767) short bar = 10000; -//Integer - 32-bit signed two's complement integer (-2,147,483,648 <= int <= 2,147,483,647) +//Integer - 32-bit signed two's complement integer +// (-2,147,483,648 <= int <= 2,147,483,647) int foo = 1; -//Long - 64-bit signed two's complement integer (-9,223,372,036,854,775,808 <= long <= 9,223,372,036,854,775,807) +//Long - 64-bit signed two's complement integer +// (-9,223,372,036,854,775,808 <= long <= 9,223,372,036,854,775,807) long bar = 100000L; +// (Java has no unsigned types) + //Float - Single-precision 32-bit IEEE 754 Floating Point float foo = 234.5f; @@ -100,7 +103,8 @@ array[1] = 2; System.out.println(array[1]); // => 2 //Others to check out -//ArrayLists - Like arrays except more functionality is offered, and the size is mutable +//ArrayLists - Like arrays except more functionality is offered, +// and the size is mutable //LinkedLists //Maps //HashMaps @@ -232,7 +236,8 @@ Integer.toString(123);//returns a string version of 123 // You can also cast java objects, there's a lot of details and // deals with some more intermediate concepts. -// Feel free to check it out here: http://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html +// Feel free to check it out here: +// http://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html /////////////////////////////////////// @@ -242,7 +247,8 @@ Integer.toString(123);//returns a string version of 123 // Classes Syntax shown below. // Function declaration syntax: // () -// Here is a quick rundown on access level modifiers (public, private, etcetc) http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html +// Here is a quick rundown on access level modifiers (public, private, etc.) +// http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html public class Bicycle { -- cgit v1.2.3 From 2008bcc258b899aae6d11033c1f28ef79db7ba42 Mon Sep 17 00:00:00 2001 From: Jake Prather Date: Sun, 30 Jun 2013 07:50:04 -0500 Subject: Fixed url links. Now use markdown. --- java.html.markdown | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'java.html.markdown') diff --git a/java.html.markdown b/java.html.markdown index 8d882234..648b98bc 100644 --- a/java.html.markdown +++ b/java.html.markdown @@ -9,7 +9,7 @@ author_url: http://github.com/JakeHP --- Java is a general-purpose, concurrent, class-based, object-oriented computer programming language. -Read more here: https://en.wikipedia.org/wiki/Java_(programming_language) +[Read more here.](http://docs.oracle.com/javase/tutorial/java/index.html) ```java // Single-line comments start with // @@ -236,8 +236,7 @@ Integer.toString(123);//returns a string version of 123 // You can also cast java objects, there's a lot of details and // deals with some more intermediate concepts. -// Feel free to check it out here: -// http://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html +// Feel free to check it out here: http://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html /////////////////////////////////////// @@ -312,14 +311,16 @@ public class Main Other Topics To Research: -* Inheritance (http://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming)) +* [Inheritance](http://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html) -* Abstraction (http://en.wikipedia.org/wiki/Abstraction_(computer_science)) +* [Polymorphism](http://docs.oracle.com/javase/tutorial/java/IandI/polymorphism.html) -* Exceptions (http://en.wikipedia.org/wiki/Exception_handling) +* [Abstraction](http://docs.oracle.com/javase/tutorial/java/IandI/abstract.html) -* Interfaces (http://en.wikipedia.org/wiki/Interfaces_(computer_science)) +* [Exceptions](http://docs.oracle.com/javase/tutorial/essential/exceptions/index.html) -* Generics (http://en.wikipedia.org/wiki/Generics_in_Java) +* [Interfaces](http://docs.oracle.com/javase/tutorial/java/IandI/createinterface.html) + +* [Generics](http://docs.oracle.com/javase/tutorial/java/generics/index.html) * The links provided are just to get an understanding of the topic, feel free to google and find specific examples -- cgit v1.2.3 From fbe0fb471896e55c40d734b082f5e994e6dc775d Mon Sep 17 00:00:00 2001 From: Jake Prather Date: Sun, 30 Jun 2013 12:17:19 -0500 Subject: Added file name param and more. See description. -Fixed some minor issues/details -Can actually compile now (not just a bunch of random snippets) -Added more text & explanation to a few parts --- java.html.markdown | 377 ++++++++++++++++++++++++++++------------------------- 1 file changed, 200 insertions(+), 177 deletions(-) (limited to 'java.html.markdown') diff --git a/java.html.markdown b/java.html.markdown index 648b98bc..3208971d 100644 --- a/java.html.markdown +++ b/java.html.markdown @@ -6,6 +6,8 @@ author: Jake Prather author_url: http://github.com/JakeHP +filename: learnjava.java + --- Java is a general-purpose, concurrent, class-based, object-oriented computer programming language. @@ -19,120 +21,120 @@ Multi-line comments look like this. // Import Packages import java.util.ArrayList; -import package.path.here; // Import all "sub-packages" import java.lang.Math.*; -// Your program's entry point is a function called main -public class Main +// Inside of the learnjava class, is your program's +// starting point. The main method. +public class learnjava { - public static void main (String[] args) throws java.lang.Exception + //main method + public static void main (String[] args) { - //stuff here - } -} - -// Printing, and forcing a new line on next print = println() -System.out.println("Hello World"); -System.out.println("Integer: "+10+"Double: "+3.14+ "Boolean: "+true); -// Printing, without forcing a new line on next print = print() -System.out.print("Hello World"); -System.out.print("Integer: "+10+"Double: "+3.14+ "Boolean: "+true); + +System.out.println("->Printing"); +// Printing, and forcing a new line on next print, use println() +System.out.println("Hello World!"); +System.out.println("Integer: "+10+" Double: "+3.14+ " Boolean: "+true); +// Printing, without forcing a new line on next print, use print() +System.out.print("Hello World - "); +System.out.print("Integer: "+10+" Double: "+3.14+ " Boolean: "+true); /////////////////////////////////////// // Types /////////////////////////////////////// - +System.out.println("\n\n->Types"); // Byte - 8-bit signed two's complement integer // (-128 <= byte <= 127) -byte foo = 100; +byte fooByte = 100; // Short - 16-bit signed two's complement integer // (-32,768 <= short <= 32,767) -short bar = 10000; +short fooShort = 10000; -//Integer - 32-bit signed two's complement integer +// Integer - 32-bit signed two's complement integer // (-2,147,483,648 <= int <= 2,147,483,647) -int foo = 1; +int fooInt = 1; -//Long - 64-bit signed two's complement integer +// Long - 64-bit signed two's complement integer // (-9,223,372,036,854,775,808 <= long <= 9,223,372,036,854,775,807) -long bar = 100000L; +long fooLong = 100000L; // (Java has no unsigned types) -//Float - Single-precision 32-bit IEEE 754 Floating Point -float foo = 234.5f; +// Float - Single-precision 32-bit IEEE 754 Floating Point +float fooFloat = 234.5f; -//Double - Double-precision 64-bit IEEE 754 Floating Point -double bar = 123.4; +// Double - Double-precision 64-bit IEEE 754 Floating Point +double fooDouble = 123.4; -//Boolean - True & False -boolean foo = true; -boolean bar = false; +// Boolean - True & False +boolean fooBoolean = true; +boolean barBoolean = false; -//Char - A single 16-bit Unicode character -char foo = 'A'; +// Char - A single 16-bit Unicode character +char fooChar = 'A'; -//Make a variable a constant +// Make a variable a constant final int HOURS_I_WORK_PER_WEEK = 9001; -//Strings -String foo = "Hello World!"; +// Strings +String fooString = "My String Is Here!"; // \n is an escaped character that starts a new line -String foo = "Hello World!\nLine2!"; -System.out.println(foo); -//Hello World! -//Line2! +String barString = "Printing on a new line?\nNo Problem!"; +System.out.println(fooString); +System.out.println(barString); -//Arrays +// Arrays //The array size must be decided upon declaration //The format for declaring an array is follows: // [] = new []; -int [] array = new int[10]; -String [] array = new String[1]; -boolean [] array = new boolean[100]; +int [] intArray = new int[10]; +String [] stringArray = new String[1]; +boolean [] booleanArray = new boolean[100]; // Indexing an array - Accessing an element -array[0]; +System.out.println("intArray @ 0: "+intArray[0]); // Arrays are mutable; it's just memory! -array[1] = 1; -System.out.println(array[1]); // => 1 -array[1] = 2; -System.out.println(array[1]); // => 2 +intArray[1] = 1; +System.out.println("intArray @ 1: "+intArray[1]); // => 1 +intArray[1] = 2; +System.out.println("intArray @ 1: "+intArray[1]); // => 2 -//Others to check out -//ArrayLists - Like arrays except more functionality is offered, +// Others to check out +// ArrayLists - Like arrays except more functionality is offered, // and the size is mutable -//LinkedLists -//Maps -//HashMaps +// LinkedLists +// Maps +// HashMaps /////////////////////////////////////// // Operators /////////////////////////////////////// +System.out.println("\n->Operators"); int i1 = 1, i2 = 2; // Shorthand for multiple declarations // Arithmetic is straightforward -i1 + i2; // => 3 -i2 - i1; // => 1 -i2 * i1; // => 2 -i1 / i2; // => 0 (0.5, but truncated towards 0) +System.out.println("1+2 = "+(i1 + i2)); // => 3 +System.out.println("1+2 = "+(i2 - i1)); // => 1 +System.out.println("1+2 = "+(i2 * i1)); // => 2 +System.out.println("1+2 = "+(i1 / i2)); // => 0 (0.5, but truncated towards 0) // Modulo -11 % 3; // => 2 +System.out.println("11%3 = "+(11 % 3)); // => 2 // Comparison operators -3 == 2; // => 0 (false) -3 != 2; // => 1 (true) -3 > 2; // => 1 -3 < 2; // => 0 -2 <= 2; // => 1 -2 >= 2; // => 1 +System.out.println("3 == 2? "+(3 == 2)); // => 0 (false) +System.out.println("3 != 2? "+(3 != 2)); // => 1 (true) +System.out.println("3 > 2? "+(3 > 2)); // => 1 +System.out.println("3 < 2? "+(3 < 2)); // => 0 +System.out.println("2 <= 2? "+(2 <= 2)); // => 1 +System.out.println("2 >= 2? "+(2 >= 2)); // => 1 // Bitwise operators! +/* ~ Unary bitwise complement << Signed left shift >> Signed right shift @@ -140,100 +142,110 @@ i1 / i2; // => 0 (0.5, but truncated towards 0) & Bitwise AND ^ Bitwise exclusive OR | Bitwise inclusive OR +*/ // Incrementations int i=0; -i++; //i = 1. Post-Incrementation -++i; //i = 2. Pre-Incrementation -i--; //i = 1. Post-Decrementation ---i; //i = 0. Pre-Decrementation +System.out.println("\n->Inc/Dec-rementation"); +System.out.println(i++); //i = 1. Post-Incrementation +System.out.println(++i); //i = 2. Pre-Incrementation +System.out.println(i--); //i = 1. Post-Decrementation +System.out.println(--i); //i = 0. Pre-Decrementation /////////////////////////////////////// // Control Structures /////////////////////////////////////// - -if (false) { - System.out.println("I never run"); - } else if (false) { - System.out.println("I am also never run"); - } else { - System.out.println("I print"); - } +System.out.println("\n->Control Structures"); +if (false){ + System.out.println("I never run"); +}else if (false) { + System.out.println("I am also never run"); +} else { + System.out.println("I print"); } // While loop -int i = 0; -while(i < 100){ - System.out.println(i); +int fooWhile = 0; +while(fooWhile < 100) +{ + //System.out.println(fooWhile); //Increment the counter - i++; + //Iterated 99 times, fooWhile 0->99 + fooWhile++; } +System.out.println("fooWhile Value: "+fooWhile); // Do While Loop -int i = 0; -do{ - System.out.println(i); +int fooDoWhile = 0; +do +{ + //System.out.println(fooDoWhile); //Increment the counter - i++; -}while(i < 100); + //Iterated 99 times, fooDoWhile 0->99 + fooDoWhile++; +}while(fooDoWhile < 100); +System.out.println("fooDoWhile Value: "+fooDoWhile); // For Loop -int i; +int fooFor; //for loop structure => for(;;) -for(i=0;i<100;i++){ - System.out.println(i); +for(fooFor=0;fooFor<100;fooFor++){ + //System.out.println(fooFor); + //Iterated 99 times, fooFor 0->99 } +System.out.println("fooFor Value: "+fooFor); // Switch Case int month = 8; - String monthString; - switch (month) { - case 1: monthString = "January"; - break; - case 2: monthString = "February"; - break; - case 3: monthString = "March"; - break; - case 4: monthString = "April"; - break; - case 5: monthString = "May"; - break; - case 6: monthString = "June"; - break; - case 7: monthString = "July"; - break; - case 8: monthString = "August"; - break; - case 9: monthString = "September"; - break; - case 10: monthString = "October"; - break; - case 11: monthString = "November"; - break; - case 12: monthString = "December"; - break; - default: monthString = "Invalid month"; - break; - } - System.out.println(monthString); +String monthString; +switch (month){ + case 1: monthString = "January"; + break; + case 2: monthString = "February"; + break; + case 3: monthString = "March"; + break; + case 4: monthString = "April"; + break; + case 5: monthString = "May"; + break; + case 6: monthString = "June"; + break; + case 7: monthString = "July"; + break; + case 8: monthString = "August"; + break; + case 9: monthString = "September"; + break; + case 10: monthString = "October"; + break; + case 11: monthString = "November"; + break; + case 12: monthString = "December"; + break; + default: monthString = "Invalid month"; + break; +} +System.out.println("Switch Case Result: "+monthString); /////////////////////////////////////// -// Typecasting +// Converting Data Types And Typcasting /////////////////////////////////////// // Converting data -//Convert String To Integer +// Convert String To Integer Integer.parseInt("123");//returns an integer version of "123" -//Convert Integer To String +// Convert Integer To String Integer.toString(123);//returns a string version of 123 -//For other conversions check out the following classes: -//Double -//Long -//String +// For other conversions check out the following classes: +// Double +// Long +// String +// Typecsating // You can also cast java objects, there's a lot of details and // deals with some more intermediate concepts. // Feel free to check it out here: http://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html @@ -243,66 +255,77 @@ Integer.toString(123);//returns a string version of 123 // Classes And Functions /////////////////////////////////////// -// Classes Syntax shown below. -// Function declaration syntax: -// () -// Here is a quick rundown on access level modifiers (public, private, etc.) -// http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html - - -public class Bicycle { - - // Bicycle's Fields/Variables - public int cadence; - public int gear; - public int speed; - - // Constructors are a way of creating classes - // This is a default constructor - public Bicycle(){ - gear = 1; - cadence = 50; - startGear = 1; - } - - // This is a specified constructor (it contains arguments) - public Bicycle(int startCadence, int startSpeed, int startGear) { - gear = startGear; - cadence = startCadence; - speed = startSpeed; - } - - // the Bicycle class has - // four methods - public void setCadence(int newValue) { - cadence = newValue; - } + // Read about the class, and function syntax before + // reading this. + System.out.println("\n->Classes & Functions"); + // Call bicycle's constructor + Bicycle trek = new Bicycle(); + // Manipulate your object + trek.speedUp(3); + trek.setCadence(100); + System.out.println("trek info: "+trek.toString()); + + // Classes Syntax: + // class { + // //data fields, constructors, functions all inside + // } + // Function Syntax: + // () + // Here is a quick rundown on access level modifiers (public, private, etc.) + // http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html + +// This bracket ends the main method +} + // The static field is only required because this class + // is nested inside of the learnjava.java class. + public static class Bicycle { + + // Bicycle's Fields/Variables + public int cadence; + public int gear; + public int speed; + + // Constructors are a way of creating classes + // This is a default constructor + public Bicycle(){ + gear = 1; + cadence = 50; + speed = 5; + } - public void setGear(int newValue) { - gear = newValue; - } + // This is a specified constructor (it contains arguments) + public Bicycle(int startCadence, int startSpeed, int startGear) { + gear = startGear; + cadence = startCadence; + speed = startSpeed; + } - public void applyBrake(int decrement) { - speed -= decrement; - } + // the Bicycle class has + // four functions/methods + public void setCadence(int newValue) { + cadence = newValue; + } - public void speedUp(int increment) { - speed += increment; - } + public void setGear(int newValue) { + gear = newValue; + } -} + public void applyBrake(int decrement) { + speed -= decrement; + } -//Now..Later in the main / driver of your java program -public class Main -{ - public static void main (String[] args) throws java.lang.Exception - { - //Call bicycle's constructor - Bicycle trek = new Bicycle(); - //Manipulate your object - trek.speedUp(3); - trek.setCadence(100); + public void speedUp(int increment) { + speed += increment; + } + + public String toString(){ + return "gear: "+Integer.toString(gear)+ + " cadence: "+Integer.toString(cadence)+ + " speed: "+Integer.toString(speed); + } + // bracket to close nested Bicycle class } +// bracket to close learnjava.java } ``` -- cgit v1.2.3 From 2d6ed6d0832b12b7463f391b80a2fbd9dd9466ae Mon Sep 17 00:00:00 2001 From: Jake Prather Date: Mon, 1 Jul 2013 07:56:02 -0500 Subject: fixed some issues & added a new array init --- java.html.markdown | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'java.html.markdown') diff --git a/java.html.markdown b/java.html.markdown index 3208971d..e0ef49c3 100644 --- a/java.html.markdown +++ b/java.html.markdown @@ -19,10 +19,10 @@ Java is a general-purpose, concurrent, class-based, object-oriented computer pro Multi-line comments look like this. */ -// Import Packages +// Import ArrayList class inside of the java.util package import java.util.ArrayList; -// Import all "sub-packages" -import java.lang.Math.*; +// Import all classes inside of java.lang package +import java.lang.*; // Inside of the learnjava class, is your program's // starting point. The main method. @@ -93,6 +93,9 @@ int [] intArray = new int[10]; String [] stringArray = new String[1]; boolean [] booleanArray = new boolean[100]; +// Another way to declare & initialize an array +int [] y = {9000, 1000, 1337}; + // Indexing an array - Accessing an element System.out.println("intArray @ 0: "+intArray[0]); @@ -118,9 +121,9 @@ int i1 = 1, i2 = 2; // Shorthand for multiple declarations // Arithmetic is straightforward System.out.println("1+2 = "+(i1 + i2)); // => 3 -System.out.println("1+2 = "+(i2 - i1)); // => 1 -System.out.println("1+2 = "+(i2 * i1)); // => 2 -System.out.println("1+2 = "+(i1 / i2)); // => 0 (0.5, but truncated towards 0) +System.out.println("1-2 = "+(i2 - i1)); // => 1 +System.out.println("1*2 = "+(i2 * i1)); // => 2 +System.out.println("1/2 = "+(i1 / i2)); // => 0 (0.5, but truncated towards 0) // Modulo System.out.println("11%3 = "+(11 % 3)); // => 2 -- cgit v1.2.3 From 1863a5de878d527ade6d15f0e4c4ad92695c054d Mon Sep 17 00:00:00 2001 From: Jake Prather Date: Mon, 1 Jul 2013 07:59:59 -0500 Subject: Text fix. --- java.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'java.html.markdown') diff --git a/java.html.markdown b/java.html.markdown index e0ef49c3..587e793e 100644 --- a/java.html.markdown +++ b/java.html.markdown @@ -121,8 +121,8 @@ int i1 = 1, i2 = 2; // Shorthand for multiple declarations // Arithmetic is straightforward System.out.println("1+2 = "+(i1 + i2)); // => 3 -System.out.println("1-2 = "+(i2 - i1)); // => 1 -System.out.println("1*2 = "+(i2 * i1)); // => 2 +System.out.println("2-1 = "+(i2 - i1)); // => 1 +System.out.println("2*1 = "+(i2 * i1)); // => 2 System.out.println("1/2 = "+(i1 / i2)); // => 0 (0.5, but truncated towards 0) // Modulo -- cgit v1.2.3 From ebf9dd011de8b2e2a79d92c188d6aee63fc31cb7 Mon Sep 17 00:00:00 2001 From: vsthsqrs Date: Mon, 1 Jul 2013 16:10:05 +0200 Subject: Fixed typo: typcsating => typecasting --- java.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'java.html.markdown') diff --git a/java.html.markdown b/java.html.markdown index 3208971d..7c297737 100644 --- a/java.html.markdown +++ b/java.html.markdown @@ -245,7 +245,7 @@ Integer.toString(123);//returns a string version of 123 // Long // String -// Typecsating +// Typecasting // You can also cast java objects, there's a lot of details and // deals with some more intermediate concepts. // Feel free to check it out here: http://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html -- cgit v1.2.3 From 9da1289d91d710dcd9157e364a32b0ba7928c679 Mon Sep 17 00:00:00 2001 From: Jake Prather Date: Mon, 1 Jul 2013 09:32:19 -0500 Subject: Added code conventions link --- java.html.markdown | 2 ++ 1 file changed, 2 insertions(+) (limited to 'java.html.markdown') diff --git a/java.html.markdown b/java.html.markdown index 587e793e..3d2e6bbe 100644 --- a/java.html.markdown +++ b/java.html.markdown @@ -349,4 +349,6 @@ Other Topics To Research: * [Generics](http://docs.oracle.com/javase/tutorial/java/generics/index.html) +* [Java Code Conventions](http://www.oracle.com/technetwork/java/codeconv-138413.html) + * The links provided are just to get an understanding of the topic, feel free to google and find specific examples -- cgit v1.2.3 From 832652a45762d46804587ce1525f8a26e210055a Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 1 Jul 2013 09:24:57 -0700 Subject: Updated java quick --- java.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'java.html.markdown') diff --git a/java.html.markdown b/java.html.markdown index 3339b6d1..206f9cbe 100644 --- a/java.html.markdown +++ b/java.html.markdown @@ -22,7 +22,7 @@ Multi-line comments look like this. // Import ArrayList class inside of the java.util package import java.util.ArrayList; // Import all classes inside of java.lang package -import java.lang.*; +import java.security.*; // Inside of the learnjava class, is your program's // starting point. The main method. -- cgit v1.2.3 From e5d2150714a7145e539245f305303aa39962df7c Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 1 Jul 2013 11:03:36 -0700 Subject: Change name of java file to be a camelcase class name --- java.html.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'java.html.markdown') diff --git a/java.html.markdown b/java.html.markdown index 206f9cbe..712233ba 100644 --- a/java.html.markdown +++ b/java.html.markdown @@ -6,7 +6,7 @@ author: Jake Prather author_url: http://github.com/JakeHP -filename: learnjava.java +filename: LearnJava.java --- @@ -24,9 +24,9 @@ import java.util.ArrayList; // Import all classes inside of java.lang package import java.security.*; -// Inside of the learnjava class, is your program's +// Inside of the LearnJava class, is your program's // starting point. The main method. -public class learnjava +public class LearnJava { //main method public static void main (String[] args) -- cgit v1.2.3