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