Lecture 1 summary of Java SE section 1

22
presentation DAD – Distributed Applications Development Cristian Toma D.I.C.E/D.E.I.C – Department of Economic Informatics & Cybernetics www.dice.ase.ro Lecture 1 summary of Java SE – section 1

Transcript of Lecture 1 summary of Java SE section 1

Page 1: Lecture 1 summary of Java SE section 1

presentation

DAD – Distributed Applications Development Cristian Toma D.I.C.E/D.E.I.C – Department of Economic Informatics & Cybernetics www.dice.ase.ro

Lecture 1

summary of Java SE – section 1

Page 2: Lecture 1 summary of Java SE section 1

Cristian Toma – Business Card

Page 3: Lecture 1 summary of Java SE section 1

Agenda for Lecture 1 – Summary of JSE

JVM and OOP

in Java SE Java Generics & JCF

Exchange

Ideas

Page 4: Lecture 1 summary of Java SE section 1

JVM & OOP in Java SE

JVM – Java Virtual Machine, Object Oriented Programming – classes, objects, polymorphism, inheritance, interfaces as type, abstract classes

Page 5: Lecture 1 summary of Java SE section 1

1.1 Java Virtual Machine Summary

Compilers & Interpreters Questions:

What is a virtual machine? How many types of JVM do you know?

What is the difference of stack based vs. registered based JVM and what are

features of JIT compiler?

Should have a virtual machine associated one or more state machines?

What are advantages and disadvantages of virtual machines – native compilers vs.

interpreters?

Hello World sample program in VMWare Player 4 Linux Ubuntu 12 with JDK 6

Command line compiling with JDK 6.0 – all lectures samples are command line

based – and Netbeans 6.5 / Eclipse INDIGO projects in Linux Ubuntu 12

Ubuntu 12 VM download: http://ism.ase.ro/vm/ujava.zip ~ 20 GB HDD, 1 CPU

core, 1GB RAM / use IZarc / 7ZIP utility program - All seminars will be in

/home/stud/dad/labs directory and the lectures are in /home/stud/dad/lectures :

user=stud / pass=stud

Page 6: Lecture 1 summary of Java SE section 1

1.1 Java Object Oriented Programming Summary

You had graduated from lectures of Java Fundamentals – let’s talk:

What is a class?

What is a package of classes in Java?

What is an object / instance?

How many bytes has an object inside JVM?

Why do we need clone, equals and hash methods?

Demo & memory model for the Certificate Java class

Page 7: Lecture 1 summary of Java SE section 1

1.1 Java Object Oriented Programming Summary

http://www.media-art-online.org/java/help/how-it-works.html

http://support.novell.com/techcenter/articles/ana19970701.html

Page 8: Lecture 1 summary of Java SE section 1

1.1 Java Object Oriented Programming Summary

http://en.wikipedia.org/wiki/Java_virtual_machine http://www.research.ibm.com/compsci/project_spotlight/plansoft/index.html

Page 9: Lecture 1 summary of Java SE section 1

1.1 Java Object Oriented Programming Summary

You had graduated from lectures of Java Fundamentals – let’s talk:

Polymorphism – “the ability to have multiple forms” is obtaining through:

The overriding (not overloading; overloading is a form of polymorphism) of

the methods from a Java class

“Pure” form of polymorphism has to have the following conditions:

Inheritance mechanism – “extends is the key word”

Virtual Methods – “in Java by default”

Overriding the virtual methods

Using the pointer / references to the objects – “in Java by default”

Interface – “contract between objects of the class that implements the interface and

another objects of another classes that interact with objects from the

implementation class” – has the following features:

static fields

Static and non-static methods prototypes – declaration but NOT

implementation

The implementation class use the “implements” keyword

It is possible to have interface as type – declare objects with type interface

but you must call the constructor methods from a real Java class

Page 10: Lecture 1 summary of Java SE section 1

1.1 Java Object Oriented Programming Summary

You had graduated from lectures of Java Fundamentals – let’s talk:

Abstract Class – “a class that have at least one method abstract” – has

the following features:

At least one abstract method – keyword “abstract”

May contain standard static and non-static fully implemented methods

You may declare objects from an abstract class but you can NOT

instantiate them, you should use constructor method from a real Java

class

Pay attention @: Objects vs. vectors / arrays of objects + null pointer

exception

Page 11: Lecture 1 summary of Java SE section 1

1.1 Java Object Oriented Programming Summary

You had graduated from lectures of Java Fundamentals – let’s talk:

What are the advantages of derivation and inheritance in object-oriented

programming in Java?

What are the advantages of polymorphism?

What is an interface or an abstract class?

What are the advantages and disadvantages for using “Interface as type”?

Demo & memory model for the Vehicle, Plane, Car Java classes

Page 12: Lecture 1 summary of Java SE section 1

Fact: DAD needs Java In few samples it is simple to remember: Object Oriented Programming in Java – class, object, object’s deep vs. shallow copy, interface, interface as type, abstract class, inheritance, polymorphism.

Section Conclusion

Page 13: Lecture 1 summary of Java SE section 1

Java Generics & JCF

Java Generics and JCF – Java Collection Framework

Page 14: Lecture 1 summary of Java SE section 1

2.1 Summary of Java Generics What are advantages of Generics in programming?

Moves the errors from “run-time in compile-time”

Is there any macro-expansion as in C / C + + within Generic programming?

NO

Where is the most intensive usage of Generic programming?

Starting with JDK 5.0 and especially in JCF – Java Collection Framework

ATTENTION!!! For advanced Java Generics concepts please read:

“Sub-typing”, “Wild-Cards”, “Type-Erasure” in the web resources

http://docs.oracle.com/javase/tutorial/java/generics/

http://docs.oracle.com/javase/tutorial/extra/generics/index.html

http://java.sun.com

Java Generics Simple Samples – Generics1.java & Generics4.java

Page 15: Lecture 1 summary of Java SE section 1

2.1 Summary of Java Generics

Recommendations for parameters naming are:

* E - Element – intensively uses in JCF - Java Collections Framework

* K - Key

* N - Number

* T - Type

* V - Value

* S,U,V etc. - 2nd, 3rd, 4th types

Please in Ubuntu 12 virtual machine check-out lecture 1 from

/home/stud/dad directory

Page 16: Lecture 1 summary of Java SE section 1

2.2 Summary of JCF

JCF – Java Collection Framework Features:

JCF is an hierarchy of classes, abstract classes, interfaces and

algorithms, that implements the standard data structures used in

programming – vector, list – stack/queue, binary-tree, hash-table

JCF contains interfaces, implementations & algorithms

JCF involves to code with interface as type style

The classes hierarchy is based on:

Collection – defines a value for each item in the data structure

Map – defines a pair of items, key-value, for each element/node in

the data structure

Page 17: Lecture 1 summary of Java SE section 1

2.2 Summary of JCF

<<interface>> Iterable<T>

<<interface>> Collection<E> <<interface>>

Map<K,V>

java.util.*

<<interface>> List<E>

<<interface>> Set<E>

Vector<E> ArrayList<E> LinkedList<E> TreeSet<E> HashSet<E> LinkedHashSet<E> TreeMap<K,V> HashMap<K,V> Hashtable<K,V>

Page 18: Lecture 1 summary of Java SE section 1

2.2 Summary of JCF

1. In order to go through a data structure from JCF, it is possible to use

foreach or iterators (or partially tu use Enumeration for classes

Vector and Hashtable)

a. for(Object o : collection) System.out.println(o);

b. for(Iterator<?> it = collection.iterator(); it.hasNext();)

System.out.println(it.next())

2. The order of the items/elements into collections/data structures

(including for use of sorting algorithms) is given by the implementation

of the method “compareTo(...)” from the interface Comparable<T> or

by the implementation of the method “compare(...)” from the

interface Comparator<T>.

3. For optimization and best practice programming, it is recommended

for the classes that instantiate objectes which are used in hash-data

structures, to implement the inherited methods “hashCode()” and

“equals(...)” from class Object.

Page 19: Lecture 1 summary of Java SE section 1

Section Conclusions

Generics & JCF Summary

for easy sharing

Java Generics programming is NOT equivalent with C++ template class programming

Java Generics “moves the error from run-time to

compile-time” JCF – Java Collection Framework is a set of classes,

interfaces and algorithms for standard data-structure processing

JCF – needs for order of the items in the data-

structures to process objects from classes that provide methods for comparing.

In JCF the best practice is to override methods

from class Object for equality and hashing value, in order to work with hash data structure

Page 20: Lecture 1 summary of Java SE section 1

Communicate & Exchange Ideas Share knowledge, Empowering Minds

Page 21: Lecture 1 summary of Java SE section 1

? Questions & Answers!

Page 22: Lecture 1 summary of Java SE section 1

What’s Your Message? Thanks!

DAD – Distributed Application Development End of Lecture 1 – summary of Java SE – section 1