You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mahuntington 8c9a7ba43f
Update 'README.md'
3 weeks ago
Bird.class code 3 weeks ago
Bird.java code 3 weeks ago
Car.class code 3 weeks ago
Car.java code 3 weeks ago
HelloWorld.class code 3 weeks ago
HelloWorld.java code 3 weeks ago
Human.class code 3 weeks ago
Human.java code 3 weeks ago
README.md Update 'README.md' 3 weeks ago
Sedan.class code 3 weeks ago
Sedan.java code 3 weeks ago
SuperHuman.class code 3 weeks ago
SuperHuman.java code 3 weeks ago
Swallow.class code 3 weeks ago
Swallow.java code 3 weeks ago

README.md

Intro to Java

Basic

class HelloWorld{
	void main(String[] args){
		System.out.println("Hello, Matt");
	}
}

Variables

String greeting = "Hello there!";
int myAge = 46;
int myNewAge = myAge + 2;
double myWeight = 144.5;

Flow of Control

Boolean isCool = false;
if(isCool){
	System.out.println("Welcome to the party");
} else {
	System.out.println("Get lost dweeeeeeb");
}
int myAge = 46;
while(myAge < 50){
	System.out.println(myAge);
	myAge++;
}
for(int i = 0; i < 5; i++){
	System.out.println(i);
}

Arrays

String[] cars = {"Volvo", "Toyota", "Mazda"};
System.out.println(cars[1]);

Functions

class HelloWorld{
	void printMessage() {
		System.out.println("Hi");
	}

	void main(String[] args){
		printMessage();
	}
}
class HelloWorld{
	int add(int a, int b){
		return a + b;
	}

	void main(String[] args){
		int result = add(4, 2);
		System.out.println(result);
	}
}

Classes

class Human {
	String name;
	Human(String name){
		this.name = name;
	}
}

class HelloWorld{
	void main(String[] args){
		Human matt = new Human("Matthew");
		System.out.println(matt.name);
	}
}

Inheritance

class SuperHuman extends Human {
	private String power;
	SuperHuman(String name, String power){
		super(name);
		this.power = power;
	}
	public String getPower(){
		return this.power;
	}
}

class HelloWorld{
	void main(String[] args){
		SuperHuman superman = new SuperHuman("Clark", "flight");
		superman.name = "bilbo";
		System.out.println(superman.name);
		//superman.power = "burping";
		System.out.println(superman.getPower());
	}
}

Abstract/Interface

abstract class Car {
	abstract void drive();
	void stop(){
		System.out.println("screeeeech");
	}
}

class Sedan extends Car{
	void drive(){
		System.out.println("vroom");
	}
}

class HelloWorld{
	void main(String[] args){
		Sedan myCar = new Sedan();
		myCar.drive();
		myCar.stop();
	}
}
interface Bird {
	void fly();
}

class Swallow implements Bird {
	public void fly() {
		System.out.println("sweeeee");
	}
}

class HelloWorld{
	void main(String[] args){
		Swallow stewart = new Swallow();
		stewart.fly();
	}

}