getting started with java (tcf 2014)

39
1 Getting Started with Java Trenton Computer Festival March 15, 2014 Michael P. Redlich @mpredli about.me/mpredli/ Sunday, March 16, 14

Upload: michael-redlich

Post on 13-Jan-2015

357 views

Category:

Technology


5 download

DESCRIPTION

An introduction to the Java programming language that includes a brief history of Java, how Java evolved, and how to get started using Java.

TRANSCRIPT

Page 1: Getting Started with Java (TCF 2014)

1

Getting Started withJava

Trenton Computer FestivalMarch 15, 2014

Michael P. Redlich@mpredli

about.me/mpredli/

Sunday, March 16, 14

Page 2: Getting Started with Java (TCF 2014)

Who’s Mike?

• BS in CS from

• “Petrochemical Research Organization”

• Ai-Logix, Inc. (now AudioCodes)

• Amateur Computer Group of New Jersey

• Publications

• Presentations

2

Sunday, March 16, 14

Page 3: Getting Started with Java (TCF 2014)

Objectives (1)

• What is Java??

• Evolution of Java

• Features of Java

• Review of Object-Oriented Programming (OOP)

3

Sunday, March 16, 14

Page 4: Getting Started with Java (TCF 2014)

Objectives (2)

• Getting Started with Java

• introduction to the Java class mechanism

• how to implement Java classes

• Live Demos (yea!)

• Java Resources

4

Sunday, March 16, 14

Page 5: Getting Started with Java (TCF 2014)

What is Java?

• “Java is C++ without guns, knives, and clubs.”James Gosling, “father” of Java, Sun Microsystems

• “Java is simple, object-oriented, distributed, interpreted, robust, secure, architecture neutral, portable, high performance, multithreaded dynamic language.”

Sun Microsystems

5

Sunday, March 16, 14

Page 6: Getting Started with Java (TCF 2014)

Evolution of Java (1)

• Created by James Gosling (with Patrick Naughton)

• Sun Microsystems

• 1991 - originally named “Oak”

• consumer applications

• architecture agnostic

• object-oriented

6

Sunday, March 16, 14

Page 7: Getting Started with Java (TCF 2014)

Evolution of Java (2)

• 1994 - Project “*7” dissolved

• but in the meantime...

• 1995 - Java introduced at Sun World ’95

• HotJava browser

7

Sunday, March 16, 14

Page 8: Getting Started with Java (TCF 2014)

Features of Java• Object-Oriented

Programming (OOP) Language

• Documentation Generation

• Applets and Applications

• Comprehensive Exception Handling

• Java Database Connectivity (JDBC)

• Java Beans

• Enterprise Java Beans

• No pointers!!

8

Sunday, March 16, 14

Page 9: Getting Started with Java (TCF 2014)

OOP Review (1)

• Programming Paradigm

• Four (4) Main Attributes

• data encapsulation

• data abstraction

• inheritance

• polymorphism

9

Sunday, March 16, 14

Page 10: Getting Started with Java (TCF 2014)

OOP Review (2)

• Abstract Data Type (ADT)

• user-defined data type

• use of objects through functions (methods) without knowing the internal representation

10

Sunday, March 16, 14

Page 11: Getting Started with Java (TCF 2014)

OOP Review (3)

• Interface

• functions (methods) provided in the ADT that allow access to data

• Implementation

• underlying data structure(s) and business logic within the ADT

11

Sunday, March 16, 14

Page 12: Getting Started with Java (TCF 2014)

OOP Review (4)• Class

• Defines a model

• Declares attributes

• Declares behavior

• Is an ADT

• Object

• Is an instance of a class

• Has state

• Has behavior

• May have many unique objects of the same class

12

Sunday, March 16, 14

Page 13: Getting Started with Java (TCF 2014)

Advantages of OOP

• Interface can (and should) remain unchanged when improving implementation

• Encourages modularity in application development

• Better maintainability of code

• Code reuse

• Emphasis on what, not how

13

Sunday, March 16, 14

Page 14: Getting Started with Java (TCF 2014)

Some Java Keywords• class

• new

• private, protected, public, package

• try, throw, catch, finally

• final

• extends

• implements

• abstract

• interface

14

Sunday, March 16, 14

Page 15: Getting Started with Java (TCF 2014)

Classes (1)

• A user-defined abstract data type

• Extension of C structs

• Contain:

• constructor

• data members and member functions (methods)

15

Sunday, March 16, 14

Page 16: Getting Started with Java (TCF 2014)

Classes (2)

• Dynamic object instantiation

• Multiple Constructors:

• Sports();

• Sports(String,int,int);

• Sports(float,String,int);

16

Sunday, March 16, 14

Page 17: Getting Started with Java (TCF 2014)

Classes (3)

• Abstract Classes

• contain at least one pure virtual member function (C++)

• contain at least one abstract method (Java)

17

Sunday, March 16, 14

Page 18: Getting Started with Java (TCF 2014)

Abstract Classes

• Pure virtual member function (C++)

• virtual void draw() = 0;

• Abstract method (Java)

• public abstract void draw();

18

Sunday, March 16, 14

Page 19: Getting Started with Java (TCF 2014)

Class Inheritance

19

Sunday, March 16, 14

Page 20: Getting Started with Java (TCF 2014)

20

// Sports class (partial listing)

public class Sports {private String team;private int win;

public Sports() {// define default constructor here...}

public Sports(String team,int win,int loss) {// define primary constructor here...}

public int getWin() {return win;}

}

Sunday, March 16, 14

Page 21: Getting Started with Java (TCF 2014)

21

// Baseball class (partial listing)

class Baseball extends Sports {public Baseball() {// define default constructor here...}

Baseball(String team,int win,int loss) {// define primary constructor here...}

}

Sunday, March 16, 14

Page 22: Getting Started with Java (TCF 2014)

Dynamic Instantiation

• Object creation:

• Baseball mets = new Baseball(“Mets”,97,65);

• Access to public member functions:

• mets.getWin(); // returns 97

22

Sunday, March 16, 14

Page 23: Getting Started with Java (TCF 2014)

Deleting Objects

Baseball mets = new Baseball(“Mets”,97,65);

// automatic garbage collection or:

System.gc(); // explicit call

23

Sunday, March 16, 14

Page 24: Getting Started with Java (TCF 2014)

Java Development Kit (JDK)

• Available from Oracle web site

• java.sun.com

• Java SE (standard edition)

• latest version - Java 7, update 51

• Documentation in full HTML format

24

Sunday, March 16, 14

Page 25: Getting Started with Java (TCF 2014)

Working with Java (1)

• Source code

• .java extension

• Intermediate bytecode

• .class extension generated after successful compilation

• Bytecode interprested by Java Virtual Machine (JVM)

25

Sunday, March 16, 14

Page 26: Getting Started with Java (TCF 2014)

Working with Java (2)

• Setup environment and path:

• set JAVA_HOME=path

• set PATH=%PATH%;%JAVA_HOME%\bin

• export JAVA_HOME=path

• export PATH=$JAVA_HOME/bin

26

Sunday, March 16, 14

Page 27: Getting Started with Java (TCF 2014)

Working with Java (3)

• Compile Java source code:

• javac -Xlint:all -d path filename.java

• Run the application:

• java -classpath path filename

27

Sunday, March 16, 14

Page 28: Getting Started with Java (TCF 2014)

Working with Java (4)

• Run the applet:

• in browser via HTML file within <applet></applet> tags

• appletviewer path filename.html

28

Sunday, March 16, 14

Page 29: Getting Started with Java (TCF 2014)

Directories and Packages (2)

• Consistent directory structure

• source code (*.java)

• byte code (*.class)

• Map directories with package name

• under the src folder

29

Sunday, March 16, 14

Page 30: Getting Started with Java (TCF 2014)

Directories and Packages (2)

/usr/local/apps/java-apps

↳java-apps

↳tcf

↳hello

↳src

↳org

↳tcf

↳hello

30

package org.tcf.hello;➜

Sunday, March 16, 14

Page 31: Getting Started with Java (TCF 2014)

Live Demo!

31

Sunday, March 16, 14

Page 32: Getting Started with Java (TCF 2014)

Java IDEs (1)

• IntelliJ

• jetbrains.com/idea

• Eclipse

• eclipse.org

32

Sunday, March 16, 14

Page 33: Getting Started with Java (TCF 2014)

Java IDEs (2)

• NetBeans

• netbeans.org

• JBuilder

• embarcadero.com/products/jbuilder

33

Sunday, March 16, 14

Page 34: Getting Started with Java (TCF 2014)

Local Java User Groups (1)

• ACGNJ Java Users Group

• facilitated by Mike Redlich

• javasig.org

• Princeton Java Users Group

• facilitated by Yakov Fain

• meetup.com/NJFlex

34

Sunday, March 16, 14

Page 35: Getting Started with Java (TCF 2014)

Local Java User Groups (2)

• New York Java SIG

• facilitated by Frank Greco

• javasig.com

• Capital District Java Developers Network

• facilitated by Dan Patsey

• cdjdn.com

35

Sunday, March 16, 14

Page 36: Getting Started with Java (TCF 2014)

Further Reading

36

Sunday, March 16, 14

Page 37: Getting Started with Java (TCF 2014)

Upcoming Events (1)

• Trenton Computer Festival

• March 14-15, 2014

• tcf-nj.org

• Emerging Technologies for the Enterprise

• April 22-23, 2014

• phillyemergingtech.com

37

Sunday, March 16, 14

Page 38: Getting Started with Java (TCF 2014)

38

Upcoming Events (2)

Sunday, March 16, 14

Page 39: Getting Started with Java (TCF 2014)

39

Thanks!

[email protected]

@mpredli

javasig.org

Sunday, March 16, 14