Intro to Java

20
Intro to

Transcript of Intro to Java

Intro to

Intro to Me

Plan of Attack

History and Impact of Java

Characteristics of Java

Development and Compilation in Java

Installing IDE

Similarities with Ruby

Differences with Ruby Objects, Variables, Classes, Constructors, Methods, Exception

Handling, Multiple Inheritance

Examples

History and Impact of Java

History and Impact of Java

Created by Sun Microsystems in 1995

Largely derived and simplified from C++

“Write once, run anywhere”

Amazon, Facebook, Google, Square, Twitter https://blog.twitter.com/2011/twitter-search-now-3x-faster

Characteristics of Java

Simple

Object-oriented

Interpreted

Multithreaded

Dynamic

Reference: http://docs.oracle.com/javase/tutorial/getStarted/intro/definition.html

Architecture neutral

Portable

High performance

Robust

Secure

Compilation

Reference: http://docs.oracle.com/javase/tutorial/getStarted/intro/definition.html

Similarities with Ruby

Object-oriented

Provide inheritance A class may extend only one other class

Public, private, protected modifiers

Automatic garbage collection

Objects

Ruby Everything is an object, including classes and instances of

types

Java Primitive data types – do not extend object class

int, double, boolean, char, etc. Strings have special support from java.lang.String

class Immutable Technically not a primitive data type

Variables

Ruby

age = 2

age = “two”

Java

int age = 2;

String age = “two”;

Classes

Ruby

class Dog

end

d = Dog.new

Java

public class Dog(){

}

Dog d = new Dog();

Constructors

Ruby uses the “initialize” keyword for all classesclass Dog

def initialize(breed)

@breed = breed

end

end

Java requires the public keyword and class name public class Dog(){

public Dog(String breed){

this.breed = breed;

}

}

Methods

Ruby

def getAge

return 1

end

Java

public int getAge(){

return 1;

}

Naming Conventions

Packages Lowercase i.e. com.mycompany.util.package

Classes CamelCase

Interfaces CamelCase Starts with an “I” to denote interface (not required)

Methods, Variables mixedCase

Constants All caps

Quick Example

Exception Handling

Ruby

begin

rescue Exception1

rescue Exception2

ensure

end

Java

try {

}

catch (Exception e) {

}

finally() {

}

Multiple Inheritance

Ruby uses modules and mixins

Java uses interfaces that consist of abstract methods

Let’s get to it!