Sun River
          Topics about Java SE, Servlet/JSP, JDBC, MultiThread, UML, Design Pattern, CSS, JavaScript, Maven, JBoss, Tomcat, ...
          posts - 78,comments - 0,trackbacks - 0

          Question How do you delete a Cookie within a JSP? (JSP)

          Answer

          Cookie mycook = new Cookie("name","value");

          response.addCookie(mycook);

          Cookie killmycook = new Cookie("mycook","value");

          killmycook.setMaxAge(0);

          killmycook.setPath("/");

          killmycook.addCookie(killmycook);

          Question How many types of protocol implementations does RMI have? (RMI)

          Answer RMI has at least three protocol implementations: Java

          Remote Method Protocol(JRMP), Internet Inter ORB Protocol(IIOP),

          and Jini Extensible Remote Invocation(JERI). These are alternatives,

          not part of the same thing, All three are indeed layer 6 protocols for

          those who are still speaking OSI reference model.

          Question What are the different identifier states of a Thread?

          (Core Java)

          Answer The different identifiers of a Thread are:

          R - Running or runnable thread

          S - Suspended thread

          CW - Thread waiting on a condition variable

          MW - Thread waiting on a monitor lock

          MS - Thread suspended waiting on a monitor lock


          Question What is the fastest type of JDBC driver? (JDBC)

          Answer JDBC driver performance will depend on a number of

          issues:

          (a) the quality of the driver code,

          (b) the size of the driver code,

          (c) the database server and its load,

          (d) network topology,

          (e) the number of times your request is translated to a different API.

          In general, all things being equal, you can assume that the more your

          request and response change hands, the slower it will be. This

          means that Type 1 and Type 3 drivers will be slower than Type 2

          drivers (the database calls are make at least three translations versus

          two), and Type 4 drivers are the fastest (only one translation).

          Question Request parameter How to find whether a parameter

          exists in the request object? (Servlets)

          Answer 1.boolean hasFoo = !(request.getParameter("foo") ==

          null || request.getParameter("foo").equals(""));

          2. boolean hasParameter =

          request.getParameterMap().contains(theParameter);

          (which works in Servlet 2.3+)


          Question How can I send user authentication information while

          makingURLConnection? (Servlets)

          Answer You’ll want to use

          HttpURLConnection.setRequestProperty and set all the appropriate

          headers to HTTP authorization.

          Question How do I convert a numeric IP address like 192.18.97.39

          into a hostname like java.sun.com? (Networking)

          Answer

          Question How many methods do u implement if implement the

          Serializable Interface? (Core Java)

          Answer The Serializable interface is just a "marker" interface,

          with no methods of its own to implement. Other ’marker’ interfaces

          are

          java.rmi.Remote

          java.util.EventListener

          String hostname =InetAddress.getByName("192.18.97.39").getHostName();

          posted @ 2010-10-25 17:08 Sun River| 編輯 收藏
          1.

          Question What is the query used to display all tables names in

          SQL Server (Query analyzer)? (JDBC)

          Answer select * from information_schema.tables

          Question What is Externalizable? (Core Java)

          Answer Externalizable is an Interface that extends Serializable

          Interface. And sends data into Streams in Compressed Format. It has

          two methods, writeExternal(ObjectOuput out) and

          readExternal(ObjectInput in).

          Question What modifiers are allowed for methods in an Interface?

          Answer Only public and abstract modifiers are allowed for

          methods in interfaces.

          Question How many types of JDBC Drivers are present and what

          are they? (JDBC)

          Answer There are 4 types of JDBC Drivers

          Type 1: JDBC-ODBC Bridge Driver

          Type 2: Native API Partly Java Driver

          Type 3: Network protocol Driver

          Type 4: JDBC Net pure Java Driver

          Question What is the difference between ServletContext and

          PageContext? (JSP)

          Answer ServletContext: Gives the information about the container

          PageContext: Gives the information about the Request.

          Question How to pass information from JSP to included JSP?

          Answer Using <%jsp:param> tag.

          posted @ 2010-10-25 16:07 Sun River| 編輯 收藏

           

          tomcat6配置雙向認證

          1
          、生成服務器端證書

          keytool -genkey -keyalg RSA -dname "cn=localhost,ou=sango,o=none,l=china,st=beijing,c=cn" -alias server -keypass password -keystore server.jks -storepass password -validity 3650


          2
          、生成客戶端證書

          keytool -genkey -keyalg RSA -dname "cn=sango,ou=sango,o=none,l=china,st=beijing,c=cn" -alias custom -storetype PKCS12 -keypass password -keystore custom.p12 -storepass password -validity 3650


          客戶端的CN可以是任意值。
          3
          、由于是雙向SSL認證,服務器必須要信任客戶端證書,因此,必須把客戶端證書添加為服務器的信任認證。由于不能直接將PKCS12格式的證書庫導入,我們必須先把客戶端證書導出為一個單獨的CER文件,使用如下命令,先把客戶端證書導出為一個單獨的cer文件:

          keytool -export -alias custom -file custom.cer -keystore custom.p12 -storepass password -storetype PKCS12 -rfc


          然后,添加客戶端證書到服務器中(將已簽名數字證書導入密鑰庫)

          keytool -import -v -alias custom -file custom.cer -keystore server.jks -storepass password


          4
          、查看證書內容

          keytool -list -v -keystore server.jks -storepass password


          5
          、配置tomcat service.xml文件

          <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
              maxThreads="150" scheme="https" secure="true"
              clientAuth="true" sslProtocol="TLS"
              keystoreFile="D:/server.jks" keystorePass="password"
              truststoreFile="D:/server.jks" truststorePass="password"
          />


          clientAuth="true"
          表示雙向認證
          6
          、導入客戶端證書到瀏覽器
          雙向認證需要強制驗證客戶端證書。雙擊“custom.p12”即可將證書導入至IE

          tomcat6
          配置單向認證

          1
          、生成服務器端證書

          keytool -genkey -keyalg RSA -dname "cn=localhost,ou=sango,o=none,l=china,st=beijing,c=cn" -alias server -keypass password -keystore server.jks -storepass password -validity 3650


          2
          、由于是單向認證,沒有必要生成客戶端的證書,直接進入配置tomcat service.xml文件

          <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
              maxThreads="150" scheme="https" secure="true"
              clientAuth="false" sslProtocol="TLS"
              keystoreFile="D:/server.jks" keystorePass="password"    
          />


          clientAuth="false"
          表示單向認證,同時去掉truststoreFile="D:/server.jks" truststorePass="password"2

          posted @ 2010-05-11 12:12 Sun River| 編輯 收藏
           

          ---The key thing to know is that IDs identify a specific element and therefore must be unique on the page – you can only use a specific ID once per document. Many browsers do not enforce this rule but it is a basic rule of HTML/XHTML and should be observed. Classes mark elements as members of a group and can be used multiple times, so if you want to define a style which will be applied to multiple elements you should use a class instead.

           Notice that an ID's CSS is an HTML element, followed by a "#", and finally ID's name. The end result looks something like "element#idname". Also, be sure to absorb the fact that when an ID is used in HTML, we must use "id=name" instead of "class=name" to reference it!

          Why Did They Choose Those Names??

                 ID = A person's Identification (ID) is unique to one person.

                 Class = There are many people in a class.

          ID for Layout and Uniqueness

          Standards specify that any given ID name can only be referenced once within a page or document. From our experience, IDs are most commonly used correctly in CSS layouts. This makes sense because there are usually only one menu per page, one banner, and usually only one content pane.

          In Tizag.com CSS Layout Examples we have used IDs for the unique items mentioned above. View the CSS Code for our first layout example. Below are the unique IDs in our code.

          *       Menu - div#menuPane

          *       Content - div#content

          Answer: Classes vs IDs

          Use IDs when there is only one occurence per page. Use classes when there are one or more occurences per page.

          posted @ 2010-03-16 10:14 Sun River| 編輯 收藏
          --Spring的singleton是容器級的,我們一般說的singleton模式是JVM級的。所以singleton模式中,singleton的class在整個JVM中只有一個instance,Spring的Bean,你可以一個class配置多個Bean,這個class就有了多個instance。這個singleton是指在spring容器中,這個Bean是單實例的,是線程共享的。所以要求這些類都是線程安全的。也就是說,不能出現修改Bean屬性的方法,當然除了設值得那些setter。只要滿足線程安全,這些bean都可以用singleton。而且我們在絕大多數使用上,也是這樣用的,包括dao,service。
          Beanfactory是Spring初始以靜態方式載入的,Spring的單例IOC是基于容器級的,所以這你都不用擔心與考慮.

          --應用中對象有兩種,行為對象和數據對象,行為對象都要求是線程安全的!也就是允許單例的, 不管是dao 還是 service 對象,都是行為對象,行為對象不應該引用非線程安全的對象做成員量,同時在應用外部的資源(如文件,數據庫連接,session)時,要先保證對這些東西的訪問是做了并發控制的!
            對于spring來講,<bean scope="singleton"/>或<bean singleton="true"/>都是保證對同一sesionfactory bean是單例的,也就是所謂 sessionfactory 范圍的.

          --這是一個真實的案例,我們在項目中使用Spring和ACEGI,我之所以選擇ACEGI,除了它對權限的良好控制外,
          我還看好它的SecurityContextHolder,通過代碼
          代碼
          1. Authentication auth = SecurityContextHolder.getContext().getAuthentication();   
          <script>render_code();</script>
          我可以很容易在系統任意一層得到用戶的信息,而不用把用戶信息在參數里傳來傳去,(這也是struts的缺點之一)
          但是我在每一次要得到用戶信息的時候都寫上面的一段代碼,未免有些麻煩,所以我在BaseService, BaseDao里都提供了如下方法:
          代碼
          1.  /**  
          2.  * get current login user info  
          3.  * @return UserInfo  
          4.  */  
          5. protected UserInfo getUserInfo()   
          6. {   
          7.     return getUserContext().getUserInfo();   
          8. }   
          9.   
          10. /**  
          11.  * get current login user context  
          12.  * @return UserContext  
          13.  */  
          14. protected UserContext getUserContext()   
          15. {   
          16.     Authentication auth = SecurityContextHolder.getContext().getAuthentication();   
          17.     return (UserContext) auth.getPrincipal();   
          18. }   
          <script>render_code();</script>
          這樣在其他的Service和Dao類里可以通過
          代碼
          1. super.getUserContext(), super.getUserInfo()   
          <script>render_code();</script>
          來得到用戶的信息,這也為問題的產生提供了溫床。請看如下代碼:
          代碼
          1. public class SomeServece extends BaseService implements SomeInterFace     
          2. {   
          3.     private UserInfo user = super.getUserInfo();   
          4.        
          5.     public someMethod()   
          6.     {   
          7.        int userID = this.user.getUserID();   
          8.        String userName = this.user.getUserName();   
          9.        //bla bla do something user userID and userNaem   
          10.     }   
          11. }       
          <script>render_code();</script>

           

          這段代碼在單元測試的時候不會用任何問題,但是在多用戶測試的情況下,你會發現任何調用SomeService里someMethod()方法
          的userID和userName都是同一個人,也就是第一個登陸的人的信息。Why?

          其根本原因是Spring的Bean在默認情況下是Singleton的,Bean SomeServece的實例只會生成一份,也就是所SomeServece實例的user
          對象只會被初始化一次,就是第一次登陸人的信息,以后不會變了。所以BaseService想為開發提供方便,卻給開發帶來了風險

          正確的用法應該是這樣的

          代碼
          1. public class SomeServece extends BaseService implements SomeInterFace     
          2. {   
          3.        
          4.        
          5.     public someMethod()   
          6.     {   
          7.        int userID = super.getUserInfo().getUserID();   
          8.        String userName = super.getUserInfo().getUserName();   
          9.        //bla bla do something user userID and userNaem   
          10.     }   
          posted @ 2009-04-08 12:12 Sun River| 編輯 收藏

          Architect (Java) Interview Questions

          General and general terms questions

          Architect interview is slightly different from all other interview types. Interviewer is looking for ability of the candidate to think independently on top of pure technical knowledge. Most of the questions are open-ended, prompting the interviewee to discussion about different aspects of Java development. Other side of the interview is general questions about position of the architect within the organization. Some questions do not have clear, direct or single answer and require discussion with the interviewer. On top of questions mentioned here you may be asked generic OO questions (what is class, what is polymorphism etc.)
          1. What distinguishes "good architecture" from "bad architecture"?
            This is an open-ended question. There are few aspects of "good" architecture:
            1. Shall address functional product requirements
            2. Shall address non-functional product requirements, such as performance, scalability, reliability, fault tolerance, availability, maintainability, extensibility
            3. Shall be simple and comprehendible (to support maintainability and extensibility)
            4. Shall be well structured (support multiple tiers, parallel development etc.)
            5. Shall be detailed enough to share with different levels of organizational structure (marketing, sales, development, management)
            "Bad" architecture is basically opposite to "good" architecture.
          2. How much experience do you have with Enterprise applications? Another variant of this questions is: "Tell me about projects where you worked with J2EE?" Yet another version: "What, when and how made using EJB?"
            Interviewer is looking for your experience with designing J2EE applications and your experience with J2EE technologies and general terms. This is often start of the discussion and bridge to the technical section of the questions.
          3. What is scalability?
          4. What is high-availability? How is it different from scalability?
          5. What is the fault tolerance?
          6. What resources are used to keep up to date with J2EE technology?
            You may mention design pattern books, such as "Core EJB Patterns" and web sites, such as http://www.theserverside.com

          Specific technical questions

          1. What modeling tools you are familiar with? What version of TogetherJ (Rational Rose etc.) have you used?
          2. If stateless session bean more scalable than stateful session beans?
            This is very popular questions that leads to some confusion. According to the second edition of "Core J2EE Patterns" and contrary to popular belief, stateful session beans are not less scalable than stateless session bean. The reason for that is life cycle of either type is controlled by Application Server and control of life cycle is what defines the scalability of the application
          3. What's the difference between EJB 1.1 and EJB 2.0?
            There are many differences. Some key points you want to mention are:
            1. New CMP model
            2. EJB Query Language
            3. Local interfaces
            4. EJBHome methods
            5. Message Driven Beans (MDB) support
          4. What transaction isolation levels do you know?
            none, repeatable read, read committed, read uncommitted, serializable
          5. What transaction attributes do you know?
            requires new, required, supports, not supported, mandatory, never
          6. What is the difference between optimistic lock and pessimistic lock?
            Optimistic lock is an implicit lock that tries to make best assumption about locking strategy and minimize time spent in lock of resource. Optimistic lock is usually implemented with some kind of timestamp strategy. Pessimistic lock is an explicit lock that set by client.
          7. What are entity beans. Are there any issues with them?
            Typical reaction to this question is very expressive answer that entity beans should not be used. There are many performancy implications with entity beans if used incorrectly. One of the famous problems are "n+1 call problem" Inter-entity bean call is very expensive operation and should be avoided.
          8. What core design patterns do you know?
            Architect must know at least some basic design patters used in J2EE development, e.g. Business Delegate, Session Facade, VO, List Handler, DTO, Composite Entity, etc.
          9. Where business logic should reside?
            Typical answer is "in business tier" This usually opens series of questions like: What is business logic, how to determine business logic, how business logic is different from persistent logic etc.
          10. What is JDO?
            JDO is Java Data Object - persistent framework that is alternative to idea of entity beans
          11. What is the difference between JSP and servlet? When to use what?
            JSP is compiled into servlet. JSP are better suit to view of information, while servlets are better for controlling stuff.
          12. Does the J2EE platform support nested transactions?
            No.
          13. Can you use synchronization primitives in my enterprise beans?
            No.
          14. Why all major application server vendors provide custom class loaders in addition to system jvm class loader?
            System one does not support hot deployment.

          Performance questions

          1. What are performance problems in J2EE and how to solve them?
          2. What are Entity beans performance pitfalls?
          3. What performance pattern do you know?

          Design Pattern questions

          1. Can you use singleton in EJB?
            Yes, but should not (explain why)
          2. What is MVC pattern and why M, V and C need to be separated?
          3. Describe Business Delegate pattern (or any other pattern)
          4. How to prevent double submission of the form from JSP page? (or describe Synchronizer Token pattern)
          posted @ 2009-03-17 11:51 Sun River| 編輯 收藏

          Interview Questions on UML and Design Patterns

          Why to use design patterns?
          Give examples of design patterns?
          What is UML?
          What are advantages of using UML?
          What is the need for modelling?
          Is it requiste to use UML in software projects?
          What are use cases? How did you capture use cases in your project?
          Explain the different types of UML diagrams ? sequence diagram , colloboration diagram etc
          What is the sequence of UML diagrams in project?
          What tools did you use for UML in your project?
          What is the difference between activity and sequence diagrams?
          What are deployment diagrams?
          What are the different object relationships ?
          What is the difference between composition and aggregation?
          Wheel acting as a part of car ? Is this composition or aggregation?

          posted @ 2009-03-17 11:43 Sun River| 編輯 收藏
          主站蜘蛛池模板: 团风县| 黄大仙区| 文水县| 镇安县| 德州市| 聂拉木县| 游戏| 浮梁县| 新巴尔虎左旗| 临夏市| 砚山县| 钦州市| 常宁市| 邛崃市| 余江县| 平阴县| 铁力市| 南华县| 株洲市| 固原市| 赫章县| 临城县| 信阳市| 景宁| 余姚市| 玉山县| 林周县| 阿拉善右旗| 永登县| 乌拉特前旗| 崇州市| 尼木县| 永昌县| 阜城县| 石楼县| 棋牌| 永年县| 民乐县| 游戏| 于田县| 威信县|