【xml】parser解析器 基本介紹

現今所有的遊覽器皆有內建如果想要讀取或者修改xml,而延伸出解析器,其中較常討論的有以下幾個:

  1. Dom Parser - 將整個xml文件讀入內存,並構造一個含有繼承關係的樹狀結構
  2. SAX Parser - 基於事件方式的解析器,不需要將整個文檔讀入內存。
  3. JDOM Parser - 以類似於DOM解析器的方式解析文檔,但更容易使用。 (http://www.jdom.org)
  4. StAX Parser - 以類似於SAX解析器的方式解析文檔,但是以更有效的方式。
  5. XPath Parser - 基於表達式解析XML,並與XSLT結合廣泛使用。
  6. DOM4J Parser - 一個使用 XPath 和 XSLT 和Java 集合框架解析XML文件的庫,並提供對DOM, SAX 和 JAXP 的支持。 (http://dom4j.sourceforge.net)
  7. Digester - xml和Java對象之間進行的轉換器。
  8. JAXB - xml和Java對象之間進行的轉換器。
  9. XStream - xml和Java對象之間進行轉換的轉換器。

而當中最常拿來比較討論到的是:DOM v.s. SAX


  1. DOM(DOM導覽-EN)W3C極力推薦
    DOM parser parses the entire XML document and loads it into memory; then models it in a “TREE” structure for easy traversal or manipulation.
    Dom解析功能強大,可增刪改查,操作時會將xml文檔以文檔對象的方式讀取到內存中,因此適用於小文檔。
  2. SAX (SAX導覽-EN) OSS()自由軟體
      (Simple API for XML) is an application program interface (API) that allows a programmer to interpret a Web file that uses the Extensible Markup Language (XML)
    Sax解析是從頭到尾逐行逐個元素讀取內容,修改較為不便,較適用於大文檔。



 From: xml解析器介紹 , 四種xml操作方式的比較 , 使用sax解析xml , 详解Java解析XML的四种方法 , XML DOM Tutorial-EN

【MVC】SSH三大框架的基本介紹



MVC經常與SSH綁在一起的熱門搜尋字,SSH分別代表:
  1. Spring 
  2. Struts 
  3. Hibernate。
為何要使用MVC?是因為在使用Java撰寫Web應用程序過程中,將請求先使用Servlet(如:web.xml),可以將邏輯分開放、維護較容易等等。
而框架是指三個功能面的總和架構,包含數據(例:使用者登入及密碼)、頁面展現(login.jsp)、處理需求的場所,這也是  Model -數據、 View-頁面展示、Control-處理需求的場所的來由,而在Controller中的設計,攸關於請求跟回應,也就是在遊覽器跟伺服器之間的處理場所,各個框架在Controller使用的都是以一串URL為中心,並以參數為輔的設計,也就是在Cotroller中交互Http訊息。


【Hibernate】何謂hibernate?


Data Access Layers
Hibernate, as an ORM solution, effectively "sits between" the Java application data access layer and the Relational Database, as can be seen in the diagram above. The Java application makes use of the Hibernate APIs to load, store, query, etc its domain data. Here we will introduce the essential Hibernate APIs. This will be a brief introduction; we will discuss these contracts in detail later./div>
Hibernate,作為ORM ( Object-Relational Mapping,將關聯式資料庫映射至物件導向的資料抽象化技術),能有效地設立在將Java應用程式數據訪問層和關連式資料庫之間。如圖片所示,Java應用程式可以利用Hibernate API來下載、儲存、查詢等行為於自身的數據域



As a JPA provider, Hibernate implements the Java Persistence API specifications and the association between JPA interfaces and Hibernate specific implementations can be visualized in the following diagram:
作為一個JPA(Java Persistence API,Java持久化應用程式接口;API:Application Programming Interface)提供者,Hibernate實現JPA的規範,並提供JPA界面的接口,兩者關係可以透過下方圖中看到:

image
SessionFactory (org.hibernate.SessionFactory)
A thread-safe (and immutable) representation of the mapping of the application domain model to a database. Acts as a factory for org.hibernate.Session instances. The EntityManagerFactory is the JPA equivalent of a SessionFactory and basically those two converge into the same SessionFactoryimplementation.
SessionFactory is very expensive to create, so, for any given database, the application should have only one associated SessionFactory. The SessionFactory maintains services that Hibernate uses across all Session(s) such as second level caches, connection pools, transaction system integrations, etc.
一個表示應用領域模型映射到資料庫的線程安全(及不可變的)。為運作 org.hibernate.Session 的實例工廠。 而EntityManagerFactory相當於SessionFactory 的APJ(Java Persistence API,Java持久化應用程式接口;API:Application Programming Interface),基本上這兩個會匯集成同樣的 SessionFactory 實作。
SessionFactory創建成本非常昂貴,所以對任何給予的資料庫,應用程序應該只有一個SessionFactorySessionFactory的Hibernate使用所有Session(s),像是 二級緩存、連接池、交易系統集成等等的 維護服務。
Session (org.hibernate.Session)
A single-threaded, short-lived object conceptually modeling a "Unit of Work" PoEAA. In JPA nomenclature, the Session is represented by an EntityManager.
Behind the scenes, the Hibernate Session wraps a JDBC java.sql.Connection and acts as a factory for org.hibernate.Transaction instances. It maintains a generally "repeatable read" persistence context (first level cache) of the application domain model.
是一個單線程、生命短暫的物件去概念地模型出一個“工作單位”企業應用程式架構模式(PoEAA,Patterns of Enterprise Application Architecture)。在JPA(Java持久化應用程式接口:Java Persistence API;API:Application Programming Interface)的命名中,Session 被 代表為一個 EntityManager。 
在幕後,Hibernate Session 包裝一個 JDBC java.sql.Connection 並 運作像一個 org.hibernate.Transaction  的實例工廠,他可以維護一般地 “可重復性閱讀”的應用程序域模型中的持久性脈絡(一級緩存)。
Transaction (org.hibernate.Transaction)
A single-threaded, short-lived object used by the application to demarcate individual physical transaction boundaries. EntityTransaction is the JPA equivalent and both act as an abstraction API to isolate the application from the underlying transaction system in use (JDBC or JTA).
一個單線程、生命短暫的物件被使用在應用程式去劃定出個別的物理交易界線。 EntityTransaction是 JPA 的相等物,且兩者都作為一個抽象API去隔離使用中的基礎交易系統(JDBC or JTA)。

【MVC】 何謂MVC?

model-view-controller(MVC)


In object-oriented programming development, model-view-controller (MVC) is the name of a methodology or design pattern for successfully and efficiently relating the user interface to underlying data models. The MVC pattern is widely used in program development with programming languages such as Java, Smalltalk, C, and C++.
在物件導向設計(面向對象程序設計,縮寫:OOP)中,是一種方法或設計模型將使用者介面成功與有效率地連結給底層資料模型,便是MVC模型。而MVC模型也大量用在於Java, Smalltalk, C, and C++等程式語言的開發中。

The MVC pattern has been heralded by many developers as a useful pattern for the reuse of object code and a pattern that allows them to significantly reduce the time it takes to develop applications with user interfaces.
許多開發者已經將MVC模型視為可重複使用目的碼(目標代碼),並能大量減少使用者界面開發應用程式的有用模式。



The model-view-controller pattern proposes three main components or objects to be used in software development:
在MVC模型當中,提出三個主要提出三個主要組建或對象被使用在軟體開發當中:

A Model , which represents the underlying, logical structure of data in a software application and the high-level class associated with it. This object model does not contain any information about the user interface.
模型,代表在軟體應用程式中數據的基礎邏輯結構,以及與其相關的高級類別。此物件模型不包含任何關於使用者介面的訊息。

A View , which is a collection of classes representing the elements in the user interface (all of the things the user can see and respond to on the screen, such as buttons, display boxes, and so forth)
視圖,代表使用者界面元素中的類別集合(使用者在螢幕上可以看到與回應的所有事情,像是按鍵、顯示框等等)

A Controller , which represents the classes connecting the model and the view, and is used to communicate between classes in the model and view.
控制器,用於類別與視圖的溝通,亦即代表一個類別連結模型與視圖。

【Hibernate】撰寫程式對資料庫Table 筆記流水帳



在方法public static void main (String[]args)內才能作用。
老師再三告誡要記住的
SessionFactory sf=HibernateUtil.getSessionFactory();
Session ss=sf.getCurrentSession();
Transaction ts=session.beginTransaction();

因為begin需要commit
get跑完就會close,可寫出來也可不必
而最外圍的sf需要放置在finally之內,確保可以關閉程式

【Java】基礎練習 :if....else.....

利用if...else...語法結構將學生的分數按照標準分成「優、良、中、差」四個級別。