锘??xml version="1.0" encoding="utf-8" standalone="yes"?> Question
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: JavaRemote 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 ofissues:
(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 parameterexists 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 whilemakingURLConnection?
(Servlets)Answer
You’ll want to useHttpURLConnection.setRequestProperty and set all the appropriate
headers to HTTP authorization.
Question
How do I convert a numeric IP address like 192.18.97.39into a hostname like java.sun.com?
(Networking)Answer
Question
How many methods do u implement if implement theSerializable 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();Question
What is the query used to display all tables names inSQL Server (Query analyzer)?
(JDBC)Answer
select * from information_schema.tablesQuestion
What is Externalizable? (Core Java)Answer
Externalizable is an Interface that extends SerializableInterface. 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 formethods in interfaces.
Question
How many types of JDBC Drivers are present and whatare they?
(JDBC)Answer
There are 4 types of JDBC DriversType 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 andPageContext?
(JSP) Answer ServletContext: Gives the information about the containerPageContext: Gives the information about the Request.
Question
How to pass information from JSP to included JSP? Answer Using <%jsp:param> tag.tomcat6閰嶇疆鍙屽悜璁よ瘉
1銆佺敓鎴愭湇鍔″櫒绔瘉涔?/span>
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鍙互鏄換鎰忓箋?/span>
3銆佺敱浜庢槸鍙屽悜SSL璁よ瘉錛屾湇鍔″櫒蹇呴』瑕佷俊浠誨鎴風璇佷功錛屽洜姝わ紝蹇呴』鎶婂鎴風璇佷功娣誨姞涓烘湇鍔″櫒鐨勪俊浠昏璇併傜敱浜庝笉鑳界洿鎺ュ皢PKCS12鏍煎紡鐨勮瘉涔﹀簱瀵煎叆錛屾垜浠繀欏誨厛鎶婂鎴風璇佷功瀵煎嚭涓轟竴涓崟鐙殑CER鏂囦歡錛屼嬌鐢ㄥ涓嬪懡浠わ紝鍏堟妸瀹㈡埛绔瘉涔﹀鍑轟負涓涓崟鐙殑cer鏂囦歡錛?/span>
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銆佹煡鐪嬭瘉涔﹀唴瀹?/span>
keytool -list -v -keystore server.jks -storepass password
5銆侀厤緗?/span>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銆佸鍏ュ鎴風璇佷功鍒版祻瑙堝櫒
鍙屽悜璁よ瘉闇瑕佸己鍒墮獙璇佸鎴風璇佷功銆傚弻鍑?/span>“custom.p12”鍗沖彲灝嗚瘉涔﹀鍏ヨ嚦IE
tomcat6閰嶇疆鍗曞悜璁よ瘉
1銆佺敓鎴愭湇鍔″櫒绔瘉涔?/span>
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"琛ㄧず鍗曞悜璁よ瘉錛屽悓鏃跺幓鎺?/span>truststoreFile="D:/server.jks" truststorePass="password"榪?/span>2
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!
ID = A person's Identification (ID) is unique to one person.
Class = There are many people in a class.
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
Use IDs when there is only one occurence per page. Use classes when there are one or more occurences per page.
榪欐浠g爜鍦ㄥ崟鍏冩祴璇曠殑鏃跺欎笉浼氱敤浠諱綍闂錛屼絾鏄湪澶氱敤鎴鋒祴璇曠殑鎯呭喌涓嬶紝浣犱細鍙戠幇浠諱綍璋冪敤SomeService閲宻omeMethod()鏂規硶
鐨剈serID鍜寀serName閮芥槸鍚屼竴涓漢錛屼篃灝辨槸絎竴涓櫥闄嗙殑浜虹殑淇℃伅銆俉hy?
鍏舵牴鏈師鍥犳槸Spring鐨凚ean鍦ㄩ粯璁ゆ儏鍐典笅鏄疭ingleton鐨勶紝Bean SomeServece鐨勫疄渚嬪彧浼氱敓鎴愪竴浠斤紝涔熷氨鏄墍SomeServece瀹炰緥鐨剈ser
瀵硅薄鍙細琚垵濮嬪寲涓嬈★紝灝辨槸絎竴嬈$櫥闄嗕漢鐨勪俊鎭紝浠ュ悗涓嶄細鍙樹簡銆傛墍浠aseService鎯充負寮鍙戞彁渚涙柟渚匡紝鍗寸粰寮鍙戝甫鏉ヤ簡椋庨櫓
姝g‘鐨勭敤娉曞簲璇ユ槸榪欐牱鐨?
闈㈡槸鑷繁鑷姩璋冨害鐨勪竴浜涘涔犮?/span>
榪欓噷鍙噰鐢?/span>jdk鑷甫鐨?/span>timer榪涜鐨勶紝鍑嗗鍦ㄤ笅綃囨枃绔犱腑鐢?/span>Quartz璋冨害鍣ㄣ?/span>
棣栧厛寤虹珛浣犺嚜宸辮榪愯鐨勭被銆?/span>
package com.duduli.li;
public class Display {
public void disp(){
System.out.println("鑷姩鎺у埗嫻嬭瘯");
}
}
涓涓畝鍗曠殑java bean錛屽叾涓湪榪欓噷浣犲彲浠ユ浛鎹㈣嚜宸辯殑浠誨姟銆?/span>
鐒跺悗灝辨槸緙栧啓璋冨害紼嬪簭錛岃繖閲岃緇ф壙jdk涓殑TimerTask綾伙紝澶嶅啓浠栫殑run鏂規硶銆?/span>
package com.duduli.li;
import java.util.TimerTask;
public class AutoRan extends TimerTask {
//set鏂規硶鏄?/span>spring鐨?/span>DI
private Display display;
public void setDisplay(Display display) {
this.display = display;
}
@Override
public void run() {
display.disp();
}
}
鐒跺悗灝辨槸閲嶈鐨勪竴姝ワ紝緙栧啓applicationsContext.xml浜嗐?/span>
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="display"
class="com.duduli.li.Display">
</bean>
<bean id="atuoRun"
class="com.duduli.li.AutoRan">
<property name="display" ref="display"></property>
</bean>
<bean id="aR"
class="org.springframework.scheduling.timer.ScheduledTimerTask">
<property name="timerTask" ref="atuoRun"></property>
<!--
period澶氶暱鏃墮棿榪愯涓嬈★紝delay琛ㄧず鍏佽浣犲綋浠誨姟絎竴嬈¤繍琛屽墠搴旇絳夊緟澶氫箙
-->
<property name="period" value="5000"></property>
<property name="delay" value="2000"></property>
</bean>
<bean id="test"
class="org.springframework.scheduling.timer.TimerFactoryBean">
<property name="scheduledTimerTasks">
<list>
<!--
榪欓噷浣跨敤list錛屽彲浠ヨ皟搴﹀涓?/span>bean錛?/span>
-->
<ref bean="aR"/>
</list>
</property>
</bean>
</beans>
鍐嶆潵灝辨槸瀹㈡埛绔皟搴︿簡銆?/span>
package com.duduli.li;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Client {
public static void main(String[] args) {
BeanFactory factory = new ClassPathXmlApplicationContext("applicationContext.xml");
factory.getBean("test");
}
}
spring涓庤嚜鍔ㄨ皟搴︿換鍔?/span>(浜?/span>)
浣跨敤quartz鍜?/span>spring鑷姩璋冨害銆?/span>
鍏蜂綋瀹炵幇bean錛?/span>
package com.duduli.li.quartz;
import java.util.Date;
public class Display {
@SuppressWarnings("deprecation")
public void disp(){
System.out.println(new Date().getSeconds());
System.out.println("鑷姩鎺у埗嫻嬭瘯");
}
}
緇ф壙quartzjobbean綾伙細榪欎釜綾誨拰緇ф壙Timer綾葷被浼?/span>
銆?/span>
package com.duduli.li.quartz;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;
public class AutoRun extends QuartzJobBean{
private Display display;
public void setDisplay(Display display) {
this.display = display;
}
@Override
protected void executeInternal(JobExecutionContext arg0)
throws JobExecutionException {
display.disp();
}
}
spring閰嶇疆鏂囦歡錛?/span>
<!-- quartz榪涜鑷姩璋冨害 -->
<!-- 鍏蜂綋瀹炵幇綾?/span> -->
<bean id="display2" class="com.duduli.li.quartz.Display"></bean>
<!-- spring瀵?/span>quartz鐨勬敮鎸侊紝Auto綾誨疄鐜?/span>quartz鐨?/span>job鎺ュ彛鐨勭被錛?/span>jobDataAsMap鏄皢瀹炵幇綾繪敞鍏ュ叾涓?/span> -->
<bean id="quartz" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="com.duduli.li.quartz.AutoRun"/>
<property name="jobDataAsMap">
<map>
<entry key="display" value-ref="display2"></entry>
</map>
</property>
</bean>
<!-- spring瀵?/span>quartz鐨勬敮鎸侊紝瀵瑰叾鍊肩殑璁懼畾 -->
<bean id="simpleTask" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
<property name="jobDetail" ref="quartz"></property>
<property name="startDelay" value="2000"></property>
<property name="repeatInterval" value="2000"></property>
</bean>
<!-- 鍚姩鑷姩璋冨害 -->
<bean id="quartzTest" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="simpleTask"/>
</list>
</property>
</bean>
client璋冪敤錛?/span>
package com.duduli.li.quartz;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Client {
public static void main(String[] args) {
BeanFactory factory = new ClassPathXmlApplicationContext("applicationContext.xml");
factory.getBean("quartzTest");
}
}
The basic functionality of each one of them is as under:
鈻?wait( ) acts as a intimation to the calling thread to give up the monitor and go to sleep until some other thread enters the same monitor and calls notify( ).
鈻?notify( ) is used as intimator to wake up the first thread that called wait( ) on the same object.
鈻?notifyAll( ) as the term states wakes up all the threads that called wait( ) on the same object. The highest priority thread will run first.
public class WaitNotifyAllExample { public static void main(String[] args) { try { Object o = new Object(); Thread thread1 = new Thread(new MyOwnRunnable("A", o)); Thread thread2 = new Thread(new MyOwnRunnable("B", o)); Thread thread3 = new Thread(new MyOwnRunnable("C", o)); // synchronized keyword acquires lock on the object. synchronized (o) { thread1.start(); // wait till the first thread completes execution. // thread should acquire the lock on the object // before calling wait method on it. Otherwise it will // throw java.lang.IllegalMonitorStateException o.wait(); thread2.start(); // wait till the second thread completes execution o.wait(); thread3.start(); } } catch (InterruptedException e) { e.printStackTrace(); } } } class MyOwnRunnable implements Runnable { private String threadName; private Object o; public MyOwnRunnable(String name, Object o) { threadName = name; this.o = o; } public void run() { synchronized (o) { for (int i = 0; i < 1000; i++) { System.out.println("Thread " + threadName + " Count : " + i); } // notify all threads waiting for the object o. // thread should acquire the lock on the object // before calling notify or notifyAll method on it. // Otherwise it will throw java.lang.IllegalMonitorStateException o.notifyAll(); } } }