diff options
Diffstat (limited to 'java.html.markdown')
-rw-r--r-- | java.html.markdown | 68 |
1 files changed, 62 insertions, 6 deletions
diff --git a/java.html.markdown b/java.html.markdown index b4624d5e..50875491 100644 --- a/java.html.markdown +++ b/java.html.markdown @@ -101,14 +101,17 @@ public class LearnJava { // Arrays //The array size must be decided upon instantiation - //The format for declaring an array is follows: + //The following formats work for declaring an arrow //<datatype> [] <var name> = new <datatype>[<array size>]; + //<datetype> <var name>[] = new <datatype>[<array size>]; int [] intArray = new int[10]; String [] stringArray = new String[1]; - boolean [] booleanArray = new boolean[100]; + boolean boolArray [] = new boolean[100]; // Another way to declare & initialize an array int [] y = {9000, 1000, 1337}; + String names [] = {"Bob", "John", "Fred", "Juan Pedro"}; + boolean bools[] = new boolean[] {true, false, false}; // Indexing an array - Accessing an element System.out.println("intArray @ 0: " + intArray[0]); @@ -191,7 +194,7 @@ public class LearnJava { { //System.out.println(fooWhile); //Increment the counter - //Iterated 99 times, fooWhile 0->99 + //Iterated 100 times, fooWhile 0,1,2...99 fooWhile++; } System.out.println("fooWhile Value: " + fooWhile); @@ -405,13 +408,53 @@ class PennyFarthing extends Bicycle { } +//Interfaces +//Interface declaration syntax +//<access-level> interface <interface-name> extends <super-interfaces> { +// //Constants +// //Method declarations +//} + +//Example - Food: +public interface Edible { + public void eat(); //Any class that implements this interface, must implement this method +} + +public interface Digestible { + public void digest(); +} + + +//We can now create a class that implements both of these interfaces +public class Fruit implements Edible, Digestible { + public void eat() { + //... + } + + public void digest() { + //... + } +} + +//In java, you can extend only one class, but you can implement many interfaces. +//For example: +public class ExampleClass extends ExampleClassParent implements InterfaceOne, InterfaceTwo { + public void InterfaceOneMethod() { + + } + + public void InterfaceTwoMethod() { + + } +} + ``` ## Further Reading The links provided here below are just to get an understanding of the topic, feel free to Google and find specific examples. -Other Topics To Research: +**Official Oracle Guides**: * [Java Tutorial Trail from Sun / Oracle](http://docs.oracle.com/javase/tutorial/index.html) @@ -430,6 +473,19 @@ Other Topics To Research: * [Java Code Conventions](http://www.oracle.com/technetwork/java/codeconv-138413.html) -Books: +**Online Practice and Tutorials** + +* [Learneroo.com - Learn Java](http://www.learneroo.com) + +* [Codingbat.com](http://codingbat.com/java) + + +**Books**: + +* [Head First Java](http://www.headfirstlabs.com/books/hfjava/) + +* [Objects First with Java](http://www.amazon.com/Objects-First-Java-Practical-Introduction/dp/0132492660) + +* [Java The Complete Reference](http://www.amazon.com/gp/product/0071606300) + -* [Head First Java] (http://www.headfirstlabs.com/books/hfjava/) |