Disclaimer - The views expressed in this presentation are my personal views. - Any opinions, comments, solutions or other commentary expressed by me are based on my experience. - This presentation is presented for educational purposes and is therefore supplementary and not to be considered exhaustive. Swing vs. Android - Johnny Hujol - CEJUG Fortaleza, Brasil - 2011/12/09
This presents my experience with building Swing apps vs. Android apps in the past 10+ years. It is not intended to go into deep details of technology but rather highlighting the main aspects and differences between the 2 platforms
This presentation was given at The Ceara Java User Group meeting in Fortaleza, Ceara, Brasil December 9, 2011 by Johnny Hujol.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Disclaimer
- The views expressed in this presentation are my personal views.
- Any opinions, comments, solutions or other commentary expressed by me are based on my experience.
- This presentation is presented for educational purposes and is therefore supplementary and not to be considered exhaustive.
Swing vs. Android - Johnny Hujol - CEJUG Fortaleza, Brasil - 2011/12/09
Building Swing vs. Android
Applications
By Johnny Hujol
Who am I
- A French leaving in Boston. - Software Engineer for a US pharmaceuticals company.
- 10+ years in Biotech/Pharmaceuticals sector developing scientific applications.
- 10+ years in Java. - 1+ year in Android.
- Co-published book on Java called ‘Java for Bioinformatics and Biomedical Applications’.
• 10+ years kitesurfing • 4th time in Taiba, Ceara, Brasil.
Swing vs. Android - Johnny Hujol - CEJUG Fortaleza, Brasil - 2011/12/09
Agenda
- History
- Swing Application
- Android Application
- Development Environment
- Comparison
- Building Applications
- Conclusion
Swing vs. Android - Johnny Hujol - CEJUG Fortaleza, Brasil - 2011/12/09
History
- 1995: Oak (Java) was released for Sun machines.
- 1996: Java 1 initial release.
- 1998: Swing part of JDK 1.2.
- September 23, 2008: Android 1.0.
- July 28, 2011: JSE 7.0.
- October 2011: Android 4.0 (Ice Cream Sandwich).
Swing vs. Android - Johnny Hujol - CEJUG Fortaleza, Brasil - 2011/12/09
Swing App
Swing vs. Android - Johnny Hujol - CEJUG Fortaleza, Brasil - 2011/12/09
Swing App - Anatomy
- JFrame, JButton, custom Java classes, events, exceptions, etc.
- Implement algorithms, business rules, etc.
- Connect to some storage to deal with data i.e. database, web service, file system, memory, etc.
- Might have multiple background tasks running.
- Offline or online app.
- Goal: help people to do things better. Swing vs. Android - Johnny Hujol - CEJUG Fortaleza, Brasil - 2011/12/09
Swing App - Life Cycle
- Main() method as starting point of program.
Swing vs. Android - Johnny Hujol - CEJUG Fortaleza, Brasil - 2011/12/09
Swing App – Multi-Threaded
- A Swing application is multi-threaded by nature.
- Single thread model for Event Dispatching Thread (EDT).
- Importance of (EDT) for UI responsiveness.
- EventQueue.invokeLater(Runnable).
- SwingWorker doInBackground() and done().
Swing vs. Android - Johnny Hujol - CEJUG Fortaleza, Brasil - 2011/12/09
Swing App – Multi-Threaded
Swing vs. Android - Johnny Hujol - CEJUG Fortaleza, Brasil - 2011/12/09
Swing App – Multi-Threaded
- Do heavy work in the background.
- More fine and advanced control with java.util.concurrent package.
- Executors to do background works to keep UI responsive.
- FutureTask (java.util.concurrent).
Swing vs. Android - Johnny Hujol - CEJUG Fortaleza, Brasil - 2011/12/09
Swing App – Multi-Threaded
Swing vs. Android - Johnny Hujol - CEJUG Fortaleza, Brasil - 2011/12/09
Swing App - More
- Exception handling policy based on requirements.
- Custom exceptions.
- Asynchronous messaging mechanism with java.awt.event i.e. event classes and listener classes.
- System events i.e. MouseEvent, KeyboardEvent, screen, etc.
- Semantic events i.e. ActionEvent, TextEvent, etc.
- Events are always fired in the EDT. Swing vs. Android - Johnny Hujol - CEJUG Fortaleza, Brasil - 2011/12/09
Swing App – And More
- Internationalization.
- 2D/3D/OpenGL, Media APIs, etc…
- Debugging tools.
- Logging, Tests, Profiling APIs.
- Compilers, JVMs.
- Encryption.
- More… Swing vs. Android - Johnny Hujol - CEJUG Fortaleza, Brasil - 2011/12/09
Android Application
Swing vs. Android - Johnny Hujol - CEJUG Fortaleza, Brasil - 2011/12/09
Android App - Anatomy
- Activity, TextView, custom Java classes, exceptions, etc. - Implement algorithms, business rules, etc.
- Connect to some storage to deal with data i.e. database, web service, file system, SD card, etc.
- Might have multiple background tasks running.
- Offline or online app.
- Goal: help people to do things better.
Swing vs. Android - Johnny Hujol - CEJUG Fortaleza, Brasil - 2011/12/09
Android App - Components
- Activity = UI.
- Service = background tasks.
- Content Provider: sharing data uniformly from multiple apps.
- Broadcast receiver = big announcer across components or apps i.e. a broader event mechanism.
Swing vs. Android - Johnny Hujol - CEJUG Fortaleza, Brasil - 2011/12/09
Android App – Life Cycle
- Components Life Cycle well defined.
- Activity (UI) starts with onCreate() in UI thread.
- Visible lifetime between onStart() and onStop().
- Foreground lifetime between onResume() and onPause().
Swing vs. Android - Johnny Hujol - CEJUG Fortaleza, Brasil - 2011/12/09
Android App – Activity
Swing vs. Android - Johnny Hujol - CEJUG Fortaleza, Brasil - 2011/12/09
Android App - Multi-Threaded
- Single thread model for UI toolkit.
- The Andoid UI toolkit is not thread-safe.
- Do not block the UI thread.
- Do not access the Android UI toolkit outside the UI thread.
Swing vs. Android - Johnny Hujol - CEJUG Fortaleza, Brasil - 2011/12/09
Android App - Multi-Threaded
- Activity.runOnUiThread(Runnable)
- View.post(Runnable)
- View.postDelayed(Runnable, long)
Swing vs. Android - Johnny Hujol - CEJUG Fortaleza, Brasil - 2011/12/09
Android App - Multi-Threaded
- AsyncTask similar to SwingWorker.
- Package java.util.concurrent for Executors, etc.
Swing vs. Android - Johnny Hujol - CEJUG Fortaleza, Brasil - 2011/12/09
Android App - More
- Exception handling policy based on requirements.
- Custom exceptions. - Separation of layout from UI logic with XML.
- Notifications with Toast, Status Bar and Progress.
- Listeners.
- Sensor APIs for GPS, camera, telephony, accelerometer, etc.
Swing vs. Android - Johnny Hujol - CEJUG Fortaleza, Brasil - 2011/12/09