ref: http://docs.google.com/View?docid=dhshbm3s_47gkcn89 Agenda(議程) why java is a good backend choice (為什麼 java 是後端伺務器最佳選擇) invoking ja...
ref: http://docs.google.com/View?docid=dhshbm3s_47gkcn89
Agenda(議程)
- why java is a good backend choice (為什麼 java 是後端伺務器最佳選擇)
- invoking java from cf ()
- java tooling/ides
- java apis/framework magic
How I Got Into Java(作者個人介紹接觸Java經驗)
- lots of free time coding in college
- needed oo capabilities in cf 5 at work; the java bridge provided a solution
- i was hooked on oo development and started reading up on j2ee and ejbs
- problem: we needed an enterprise-class backend oo platform to accompany cf on the front end
CFCs or EJBs?
- traditional ejb 2.1 sucked (in 2003) (傳統ejb 2.1 非常不好)
- cfmx introduced cfcs; not bad, but ... (cfmx 採用 cfcs 概念, 不差但是...)
- verbose tag-based syntax (冗長的標簽)
- weird scoping issues (var, instance, argument, etc.) (變數範圍問題)
- write whitespace to output stream by default
- no interface (but added in scorpio)
- no cfc frameworks (in 2003) ( 於 2003 期間,沒有 框架 支援.)
Max Loves Spring (最愛用 spring framework)
- figured out how to get Spring to work with CFMX 6 (read: heinous jar file hack) and the rest is history
What about now?(現在如何呢?)
- good cfc frameworks now, so why use java (cfc 支援 框架, 那為什麼又要用 java呢.)
Why use Java?(為什麼使用 java)
- runs on anything for free (在任何使用條件都是免費)
- cf doesn't run on everything, and it's not free (cf 並沒有如上面所述的, 沒有免費)
- backend logic doesn't go away, but front-end presentation technology like cf may change (後端伺服器所有之邏輯並沒有改變, 但是前端介面表現之技術會,會因為時空背景而有所改變.)
- native to many web frameworks/platforms
- CF, Flex, Laszlo, Spring MVC, Google Web Toolkit, JSP, JSF, Struts, Java Servlets, JRuby (soon), etc.
- portable to the desktop and beyond
- e.g. Swing application that can run offline
- project called Artemis that will bridge Apollo to java on the desktop
- Oodles of frameworks libraries (大量的框架庫出現)
- Hibernate, axis, iBatis (sql/query framework), Castor, Spring, etc.
- Oodles of tools (大量的工具出現)
- Eclipse ... and friends! (plugins)
- Much tighter syntax than tags
- compiled--more bulletproof code
- downside--can't run new code immediately like you can on cf
- wicked fast on the server
- fine-grained control
So does CF suck?(所以 cf 很差囉)
- absolutely not -- cf kicks ass (並不是, cf 要打屁股)
- tag-based syntax perfect for the front-end (以標籤方式來建創前端介面是非常好的.)
- powerful, simple tags for front-end concerns (與前端介面有關的標籤,都十分強大與簡單.)
- cfdocument, cfcache, cfchart, flash forms, ajax support, cfimage, cfpdf, cffeed, json serialization, etc.
Summary - Why Java? (為什麼用 java)
- free (免費)
- portable (可攜化)
- great productivity (高產力)
- mature apis (具有完整 apis 支援)
- lots of java developers available
- runs in cf, flex, and more
- develops enterprise apps
- best combo: java on the backend, flex/cf on the frontend (最佳組合: java後端, flex/cf前端)
CF and Flex are Java
- cf tags are compiled to java (cf 編譯為 java)
- mxml is compiled to flash--with java (mxml 編譯為 flash)
- both language can talk to java on the server natively and access java objects (cf/flex 都能與 java 進行溝通)
CF Deployment(cf 發佈)
- WEB-INF folder--j2ee standard for web app
- inside here is web.xml--can add additional classpath info here
CF Invocation of Java
- good idea to write a function that is called by cf so cf isn't doing createObject("java") all over the place
Flex Deployment (flex 發佈)
- very similar to cf deployment (與 cf 發佈相似)
- uses WEB-INF directory as well, has flex, classes, and lib directories
TOOLING AND IDEs
Eclipse Kicks Ass
- java development would not be anywhere near as productive without Eclipse's Java support
- killer plugins
- integration with many popular java apis and frameworks
- amazing refactoring and debugging support
Plugin Heaven (外掛天堂)
- Free Java-Only Favorites
- JUnit
- Spring IDE
- Tomcat Debugger
- Commercial solutions
- IBM Rational tools
(框架介紹, 不翻)
Spring Framework
- ORM frameworks and persistence
- AOP transaction management/Java Transaction API (distributed transactions)
- Hibernate (versions 2+)
- TopLink
- JDO
- Java persistence API
- JDBC (SQL, stored procs, sql functions)
- iBatis (ORM for legacy systems)
- interfaces to popular java libraries
- mocking
- jasper reports
- velocity
- additional api support
- ejb
- remoting
- jmx
- jms
- jca
- jndi
- convenience coding features for
- daos
- all sorts of crazy aop for multiple aop implementations
- internationalization
Hibernate
- auto ddl
- database -> xml mappings -> java
- java -> xml mappings -> database
- java <- xml mappings -> database
- report queries
- select "flat" objects/columns using HQL (which Transfer's TQL is based upon)
- bonuses
- OO queries
- Criterion API lets you construct objects as queries
- objects like Criteria, Expression, etc.
- allows fine-grained control over fetching strategies (e.g. lazy loading)
- Query By Example
- give hibernate an object and say "find me anything like this object"
- Data versioning
- hibernate can automatically handle this for you
- simple configuration option
- if you have a conflict, hibernate can throw an exception that can be caught and managed
- this allows you to have safe optimistic locking scenarios
JMock
- automates the creation of mock objects
- all you do is specify the values you want to test against
- JMock creates objects that fully support the interface of the "mocked" classes
log4j
- logging on crack
Castor
- instant xml marshalling/unmarshalling
- auto-gens java objects from xml schemas
- good for RESTful stuff
- trim verbose xml formats
- xml to xslt (think object-oriented reporting)
Apache Axis
- web service stub/code generator
- finer control over the web service interface
- often fits the bill on services that CF's web service support can't handle (but not always)
Final Thoughts (最後省思, 可以看看)
- sometimes have java libraries that exist in cf, run into conflicts
- e.g. logging libraries (commons-logging), http libraries, etc.
- this was in early days--no problems in quite a while
- e.g. logging libraries (commons-logging), http libraries, etc.
- CF
- great for the front-end
- excellent glue language
- filled with adobe magic (pdf, image processing, beautiful integration with html, js, etc.)
- supported on most enterprise J2EE servers
- tools are coming along--CFEclipse
- Flex
- great for front end
- flash kicks ass
- data binding/event model is fantastic
- flex builder 2 is an excellent ide
- supported on most enterprise j2ee servers
- java-like syntax for AS 3 bridges the gap between AS 3 and java
- Java
- both free and commercial tools, way ahead of current cf tooling
- most cf apis are inspired by java equivalents that are significantly ahead in terms of features and power
- runs on any server, any platform
- code is portable to other web frameworks, other platforms
- code can be shared with others not using cf
- your code and skills transfer outside CF--e.g. prepare you for C# .NET development
- powerful combo--right tool(s) for the job