+ All Categories
Home > Documents > O AK R IDGE N ATIONAL L ABORATORY U. S. D EPARTMENT OF E NERGY 1 Java Pros and Cons − Roundtable...

O AK R IDGE N ATIONAL L ABORATORY U. S. D EPARTMENT OF E NERGY 1 Java Pros and Cons − Roundtable...

Date post: 04-Jan-2016
Category:
Upload: janel-gaines
View: 215 times
Download: 1 times
Share this document with a friend
21
1 OAK RIDGE NATIONAL LABORATORY U. S. DEPARTMENT OF ENERGY Java Pros and Cons − Roundtable American Nuclear Society Annual Meeting June 16, 2004 Pittsburgh, PA
Transcript
Page 1: O AK R IDGE N ATIONAL L ABORATORY U. S. D EPARTMENT OF E NERGY 1 Java Pros and Cons − Roundtable American Nuclear Society Annual Meeting June 16, 2004.

1

OAK RIDGE NATIONAL LABORATORYU. S. DEPARTMENT OF ENERGY

Java Pros and Cons − Roundtable

American Nuclear Society

Annual Meeting

June 16, 2004 Pittsburgh, PA

Page 2: O AK R IDGE N ATIONAL L ABORATORY U. S. D EPARTMENT OF E NERGY 1 Java Pros and Cons − Roundtable American Nuclear Society Annual Meeting June 16, 2004.

2

OAK RIDGE NATIONAL LABORATORYU. S. DEPARTMENT OF ENERGY

Java – an Object-Oriented Programming Language

Based on objects: data and methods together

Four Concepts: Abstraction – describes physical world Encapsulation – data and methods together Inheritance - just like something else but ... Polymorphism – method overloading

Page 3: O AK R IDGE N ATIONAL L ABORATORY U. S. D EPARTMENT OF E NERGY 1 Java Pros and Cons − Roundtable American Nuclear Society Annual Meeting June 16, 2004.

3

OAK RIDGE NATIONAL LABORATORYU. S. DEPARTMENT OF ENERGY

Abstraction / Encapsulation public class Particle {

Position position;

Direction direction;

double energy;

public Particle(){

position = new Position(0, 0, 0);

direction = new Position(1, 0, 0);

energy = 1.0;

}

public void move(double distance){

position.move(direction, distance);

}

public void scat(double t, double p){

...

}

}

public class Position {

double x, y, z; public Position(double a, double b, double c){ x = a; y = b; z = c; }

public void move(Direction d, double dis){ x = x + d.u*dis; y = y + d.v*dis; z = z + d.w*dis; }

public double howFarTo(Position p){ double answer = (p.x-x)*(p.x-x) + (p.y-y)*(p.y-y) + (p.z-z)*(p.z-z); answer = Math.sqrt( answer ); return answer; }}

Page 4: O AK R IDGE N ATIONAL L ABORATORY U. S. D EPARTMENT OF E NERGY 1 Java Pros and Cons − Roundtable American Nuclear Society Annual Meeting June 16, 2004.

4

OAK RIDGE NATIONAL LABORATORYU. S. DEPARTMENT OF ENERGY

Inheritance (1/2)

public class ChargedParticle extends Particle {

double restMass; int charge;

// Physical Constants static double ELEMCHARGE = 1.60217733e-19; // Coulombs static double RESTMASSKG = 9.1093897e-31; // kg static double RESTMASS = 0.511; // MeV static double ERADIUS = 2.81792e-15; // meter

public ChargedParticle(){ super(); restMass = ChargedParticle.RESTMASS; charge = -1; }

public double getSpeed(){ double speed = ... (energy-restMass) ... return speed; }

}

Page 5: O AK R IDGE N ATIONAL L ABORATORY U. S. D EPARTMENT OF E NERGY 1 Java Pros and Cons − Roundtable American Nuclear Society Annual Meeting June 16, 2004.

5

OAK RIDGE NATIONAL LABORATORYU. S. DEPARTMENT OF ENERGY

Inheritance (2/2)

public class Photon extends Particle {

// Physical Constants static double speedOfLight = 299792458.0; // m/s static double planckConstant = 6.6260755e-34; // Joule seconds

public Photon(){ super(); }

public Particle[] comptonScatter(){ Particle[] answer = new Particle[2]; // photoelectron answer[0] = new ChargedParticle(...);

// scattered photon answer[1] = new Photon(...);

return answer; }}

Page 6: O AK R IDGE N ATIONAL L ABORATORY U. S. D EPARTMENT OF E NERGY 1 Java Pros and Cons − Roundtable American Nuclear Society Annual Meeting June 16, 2004.

6

OAK RIDGE NATIONAL LABORATORYU. S. DEPARTMENT OF ENERGY

Polymorphismpublic class Particle {

Position position; Direction direction; double energy; public Particle(){ position = new Position(0, 0, 0); direction = new Position(1, 0, 0); energy = 1.0; } public Particle(Position p, Direction d, double e){ position = p direction = d; energy = e; }

public Particle(Particle p){ position = p.position; direction = p.direction; energy = p.energy; }

}

Page 7: O AK R IDGE N ATIONAL L ABORATORY U. S. D EPARTMENT OF E NERGY 1 Java Pros and Cons − Roundtable American Nuclear Society Annual Meeting June 16, 2004.

7

OAK RIDGE NATIONAL LABORATORYU. S. DEPARTMENT OF ENERGY

Java Pros Free, freely distributable Portable – “Write once, run anywhere” Internet savvy Extensive libraries – database, GUI,

networking, etc. Language – strongly typed, array indices

are checked, automatic garbage collection, Threads, Exceptions

*.jar files – Java archive, runnable

Page 8: O AK R IDGE N ATIONAL L ABORATORY U. S. D EPARTMENT OF E NERGY 1 Java Pros and Cons − Roundtable American Nuclear Society Annual Meeting June 16, 2004.

8

OAK RIDGE NATIONAL LABORATORYU. S. DEPARTMENT OF ENERGY

Java Cons Interpreted

Page 9: O AK R IDGE N ATIONAL L ABORATORY U. S. D EPARTMENT OF E NERGY 1 Java Pros and Cons − Roundtable American Nuclear Society Annual Meeting June 16, 2004.

9

OAK RIDGE NATIONAL LABORATORYU. S. DEPARTMENT OF ENERGY

Page 10: O AK R IDGE N ATIONAL L ABORATORY U. S. D EPARTMENT OF E NERGY 1 Java Pros and Cons − Roundtable American Nuclear Society Annual Meeting June 16, 2004.

10

OAK RIDGE NATIONAL LABORATORYU. S. DEPARTMENT OF ENERGY

Page 11: O AK R IDGE N ATIONAL L ABORATORY U. S. D EPARTMENT OF E NERGY 1 Java Pros and Cons − Roundtable American Nuclear Society Annual Meeting June 16, 2004.

11

OAK RIDGE NATIONAL LABORATORYU. S. DEPARTMENT OF ENERGY

Page 12: O AK R IDGE N ATIONAL L ABORATORY U. S. D EPARTMENT OF E NERGY 1 Java Pros and Cons − Roundtable American Nuclear Society Annual Meeting June 16, 2004.

12

OAK RIDGE NATIONAL LABORATORYU. S. DEPARTMENT OF ENERGY

Page 13: O AK R IDGE N ATIONAL L ABORATORY U. S. D EPARTMENT OF E NERGY 1 Java Pros and Cons − Roundtable American Nuclear Society Annual Meeting June 16, 2004.

13

OAK RIDGE NATIONAL LABORATORYU. S. DEPARTMENT OF ENERGY

Page 14: O AK R IDGE N ATIONAL L ABORATORY U. S. D EPARTMENT OF E NERGY 1 Java Pros and Cons − Roundtable American Nuclear Society Annual Meeting June 16, 2004.

14

OAK RIDGE NATIONAL LABORATORYU. S. DEPARTMENT OF ENERGY

Page 15: O AK R IDGE N ATIONAL L ABORATORY U. S. D EPARTMENT OF E NERGY 1 Java Pros and Cons − Roundtable American Nuclear Society Annual Meeting June 16, 2004.

15

OAK RIDGE NATIONAL LABORATORYU. S. DEPARTMENT OF ENERGY

Page 16: O AK R IDGE N ATIONAL L ABORATORY U. S. D EPARTMENT OF E NERGY 1 Java Pros and Cons − Roundtable American Nuclear Society Annual Meeting June 16, 2004.

16

OAK RIDGE NATIONAL LABORATORYU. S. DEPARTMENT OF ENERGY

Page 17: O AK R IDGE N ATIONAL L ABORATORY U. S. D EPARTMENT OF E NERGY 1 Java Pros and Cons − Roundtable American Nuclear Society Annual Meeting June 16, 2004.

17

OAK RIDGE NATIONAL LABORATORYU. S. DEPARTMENT OF ENERGY

Page 18: O AK R IDGE N ATIONAL L ABORATORY U. S. D EPARTMENT OF E NERGY 1 Java Pros and Cons − Roundtable American Nuclear Society Annual Meeting June 16, 2004.

18

OAK RIDGE NATIONAL LABORATORYU. S. DEPARTMENT OF ENERGY

Java 1.5 “Tiger”

Generics - no casting, errors at compile time, not runtime

Enhanced for Loop Autoboxing/Unboxing -

collections of primitive data types

Formatted Output - more like C or FORTRAN

New JVM Profiling API Improved Diagnostic

Ability - getStackTrace, Thread.getAllStackTraces

private void printCollection(Collection c) { Iterator<String> i = c.iterator(); while(i.hasNext()) { String item = i.next(); System.out.println("Item: "+item); }}

public void newFor(Collection<String> c) { for(String str : c) { System.out.println(str); }}

System.out.printf("%s %3d", name, age);

Page 19: O AK R IDGE N ATIONAL L ABORATORY U. S. D EPARTMENT OF E NERGY 1 Java Pros and Cons − Roundtable American Nuclear Society Annual Meeting June 16, 2004.

19

OAK RIDGE NATIONAL LABORATORYU. S. DEPARTMENT OF ENERGY

Sun Microsystems, Inc.Binary Code License Agreement

for theJAVATM 2 SOFTWARE DEVELOPMENT KIT (J2SDK),

STANDARD EDITION, VERSION 1.4.2_X

3. RESTRICTIONS. ... You acknowledge that Licensed Software is not designed or intended for use in the design, construction, operation or maintenance of any nuclear facility. ...

Page 20: O AK R IDGE N ATIONAL L ABORATORY U. S. D EPARTMENT OF E NERGY 1 Java Pros and Cons − Roundtable American Nuclear Society Annual Meeting June 16, 2004.

20

OAK RIDGE NATIONAL LABORATORYU. S. DEPARTMENT OF ENERGY

Sun Microsystems, Inc.Binary Code License Agreement

for theJAVATM 2 SOFTWARE DEVELOPMENT KIT (J2SDK),

STANDARD EDITION, VERSION 1.4.2_X

3. RESTRICTIONS. ... You acknowledge that Licensed Software is not designed or intended for use in the design, construction, operation or maintenance of any nuclear facility. ...

Page 21: O AK R IDGE N ATIONAL L ABORATORY U. S. D EPARTMENT OF E NERGY 1 Java Pros and Cons − Roundtable American Nuclear Society Annual Meeting June 16, 2004.

21

OAK RIDGE NATIONAL LABORATORYU. S. DEPARTMENT OF ENERGY

Any Questions?


Recommended