Java: An Operational Semantics Gaurav S. Kc B. Eng. Project Department of Computing Semantics of Java -- why? n Semantics: – Assignment of meanings to programs n Java: – A simple, object-oriented, distributed, interpreted, robust, secure, architecture neutral, portable, high-performance, multithreaded, and dynamic language. Why? … contd. n Better “mental model” of language n Acceptance – reliability – expected behaviour n Java : Security v.s. functionality n Widespread use n Reasoning: towards a compromise Project Goals n Semantics extension n Better understanding of Java n Research based -- no implementation Break-down into parts n Existing features: – inheritance – instance variables – overloading and overriding n Additions: – access modifiers – final, static, abstract – constructors An example in the new syntax abstract class Animal extends Object { int age; Animal() { super();} int getAge() {...} } public final class Dog extends Animal { final int legs = 4; final static boolean hasTail = yes; Dog() { this(“Laika”); } Dog(String s) { super(); … } int getAge(String name) {…} } Access Modifiers n Public n Protected n Private n [default] n No packages l Accessibility checks Semantics extension ... Final and Abstract modifier n Classes – sub-classing not permitted – instantiating not permitted n Fields – Constant behaviour? l Well-formedness l Constructor invocation l Assignment Semantics extension ... Static modifier n Fields that don’t belong to objects n Class and interface fields n State extension: – Class/interface entries – References l Runtime checks l Class or interface v.s. object Semantics extension ... Constructor A constructor is used in the creation of an object that is an instance of a class. It is the basis with which the run-time system allocates space from memory to objects during execution. n Instance fields & [inherited] instance fields n OutOfMemory exception n Static initialisation Syntax of a Constructor n Explicit constructor invocation – this(); n same class – super(); n parent class n static initialisation n Statements public class C extends B { int x = 5; public C (int n) { this(true); print(n); } private C (boolean b) { super(); if (b) … } } [boolean] C(true), s [] B(); x=5; if (b) …, s Constructor execution new C(true); Other research work on Java n Within the Department of Computing: – Exceptions SLURP@DoC – Concurrency SLURP@DoC – Binary Compatibility SLURP@DoC n In other research institutions: – Generics PLT@Rice – Security Issues SIP@Princeton Other research, … contd. n A comparison perhaps? – Different aspects of Java – Post-grad & post-doc work Conclusions n Boring? Certainly not! n Acquired skills n Taste of pure research n Lots of non-trivial work n State of the art technology n Continued research in Java Semantics n Improved know-how of the Java system Acknowledgements n Krysia Broda n Sophia Drossopoulou n Susan Eisenbach n Tanya Valkevych