170 likes | 376 Views
Java Coding in Eclipse. Eclipse basics. Written in Java Based on Equinox framework Modular Java specification OSGi (Open Services Gateway initiative) Dynamically loaded modules: bundles Android Development Tools (ADT) plug-in: Bundle. Eclipse Environments. Java Runtime Environment
E N D
Java Coding in Eclipse CS440
Eclipse basics • Written in Java • Based on Equinox framework • Modular Java specification OSGi (Open Services Gateway initiative) • Dynamically loaded modules: bundles • Android Development Tools (ADT) plug-in: Bundle CS440
Eclipse Environments • Java Runtime Environment • Integrated Development Environment (IDE) • Modify eclipse.ini • Java Compiler: • .class files • Error messages, autocompletion (ctrl+space) • Application Runtime • Where the android emulator runs • Android Virtual Device (AVD) CS440
Eclipse basic ingredients • Workspace • File → Switch Workspace → Others • Perspective • Window → Open Perspective → Other • Views and Editors • Java Perspective and Package Explorer • More info at: http://www.vogella.de/articles/Eclipse/article.html#eclipsesui CS440
Eclipse Workspace • Keeps project state • Organized in directories • Different settings for different workspaces • Ex. AndroidProjects CS440
Eclipse Projects • Java Project vs Android Project • Different plugins • Builder: generates artifacts • Transforms .class files to .dex files • Association • Open with.. CS440
Eclipse Views and perspectives • Package explorer • Task list: todo list • Outline: code hierarchy • Problems: compiler errors, builder errors. • Other views? CS440
New Project: CarDealership • Classes • Car • Public void drive(): prints “Going down the road” • Ragtop extends Car • JoyRide • driveCars • Test the Car class using: a main method in the drive cars class • Create object: myCar • test CS440
More Java: Object class CS440
Objects and classes • Class: • Fields (data) • Methods (procedures) • Class that inherits from another: subtype or subclass • Parent class: supertypeor superclass CS440
Class Trivial • Create a trivial class with: • Fields: • private long ctr • Methods: • public void incr(): Increases ctr by 1 every time it is called • Constructor that takes as input ling initCtr • Constructor that initializes ctr to 0 CS440
Object class and its methods • http://docs.oracle.com/javase/6/docs/api/java/lang/Object.html • toString • equals CS440
Objects, Inheritance, and Polymorphism • Objects of single type can have different behavior • Subtype are declared with extends keyword • Example: Cars! CS440
Continue Project: CarDealership • Classes • Car • Public void drive(): prints “Going down the road” • Ragtop extends Car • Extend drive method to: • Print: “top down!” • Use superclass method • Print” “Got the radio on!” • Test ragtop CS440
Continue Project: CarDealership • Class Joyride: • Fields: • private Car myCar • Methods: • Public void park(Car) • Assing field mycar to the argument • Public Car whatsInTheGarage() • Return car • Public void letsGo() • Call parkto park a new Ragtop • Call whatsInTheGarage and drive it! • Test JoyRide CS440
References • Programming Android by ZigurdMednieks, Laird Dornin, G. Blake Meike, Masumi Nakamura • Eclipse http://www.vogella.de/articles/Eclipse/article.html#eclipsesui CS440