Posts Tagged ‘ java

Snow Leopard下的JDK链接有问题

今天在SL下build JRex,在执行ant make的时候总是出现以下错误:

compile:
[javac] Compiling 86 source files to /Users/ijay/Projects/mozilla/embedding/JRex/classes
[javac] /Users/ijay/Projects/mozilla/embedding/JRex/src/java/netscape/javascript/JSObject.java:38: ?????? sun.plugin.javascript ??????
[javac] import sun.plugin.javascript.JSContext;
[javac] ^
[javac] /Users/ijay/Projects/mozilla/embedding/JRex/src/java/netscape/javascript/JSObject.java:172: ?????? sun.plugin.javascript ??????
[javac] if (c instanceof sun.plugin.javascript.JSContext)
[javac] ^
[javac] /Users/ijay/Projects/mozilla/embedding/JRex/src/java/netscape/javascript/JSObject.java:174: ?Ҳ???????
[javac] ???ţ? ?? JSContext
[javac] λ?ã? ?? netscape.javascript.JSObject
[javac] JSContext j = (JSContext) c;
[javac] ^
[javac] /Users/ijay/Projects/mozilla/embedding/JRex/src/java/netscape/javascript/JSObject.java:174: ?Ҳ???????
[javac] ???ţ? ?? JSContext
[javac] λ?ã? ?? netscape.javascript.JSObject
[javac] JSContext j = (JSContext) c;
[javac] ^
[javac] 4 ????

BUILD FAILED

检查了一下build.xml引入的JRex.properties,其中有一行内容如下:

classpath =${build};${java.home}/lib/plugin.jar;${java.home}/lib/deploy.jar;${java.home}/lib/jaws.jar

于是又挨个去找那几个jar包(其中“plugin.jar”最像),最终发现了问题:/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home/lib/plugin.jar(即“${java.home}/lib/plugin.jar”)是一个符号链接,指向“/System/Library/Frameworks/JavaVM.framework/Versions/A/Resources/Deploy.bundle/Contents/Home/lib/plugin2.jar”,而plugin2.jar不存在……
把原先的符号链接删除,重建链接指向…/plugin.jar,问题解决
已向apple提交该bug

  • Share/Bookmark

java.net论坛被黑(有图有真相)

从今天中午开始java.net论坛被黑,所有标题、内容变成了“RED EYE OWNZ – by Z4i0n”,一直到现在都没恢复,Sun在干啥呢?

  • Share/Bookmark

Apache给EJB 3.1(JSR #318)投了否决票

刚才在Glassfish的Google Group上收到有关Apache在EJB 3.1 JSR表决上投了否决票的消息。过去看了一下,发现只有Apache投了否决票,Eclipse、Spring弃权,而且Apache的理由相当牛逼:

On 2009-11-30 Apache Software Foundation voted No with the following comment:
The Apache Software Foundation’s vote is based on the point of view that this spec lead – Sun – is in violation of the JSPA

http://www.apache.org/jcp/sunopenletter.html

and therefore shouldn’t be allowed to lead other JSRs until the above matter is resolved.

This vote is not a comment on the technical merits of the JSR. If not for the issue of the spec lead, the ASF would have otherwise voted “yes”.

于是又围观了一下那封公开信,不亏是Apache,邮件的口气都不一样,比如开头:

My name is Geir Magnusson Jr, and I’m the officer of the Apache Software Foundation (ASF), a 501(c)3 public charity, charged with matters relating to our participation in the Java Community Process (JCP). I am also the VP of the Apache Harmony project. In this matter I represent the ASF.

还有结尾:

We expect you to offer an acceptable, JSPA-compliant license to us within 30 days, or provide a public explanation of why you cannot do so.

继续关注EJB 3.1的相关发展……

  • Share/Bookmark

10 things all JAVA developers should know [zz]

原文在这里

Since JAVA (I know it’s not an acronym, but it stands out like that) was officially introduced in 1995, it has changed the way most of us look at the Operating System. Bill Gate (how ironic) once said that it was not about the hardware but the software which will be the future. A decade or more later, the fifth employee of SUN, John Gage said “The Network is the Computer”. Fast-forwarding to the 21st century and John seemed to be right. Anyway, JAVA was built not to depend on an Operating System and deployed through the network. JAVA through its applet technology gave birth to Rich Network Application aka Rich Internet Application (RIA). JAVA is not perfect; or we would not have various releases and more on the way, but JAVA has given birth to a wide range of programming language (just Google it to find out more). Without further ado, I am going to get back to subject. This is a brief
article on what I believe that every Java developers should know regardless of their experience. I do not personally believe that someone with 5 years experience is not as good as someone with 10 years experience. We all develop our own methods of working but as a developer you need to stay abreast of your technology. So, here are my top 10 not in order of importance (or?):

  1. Remember the basic of JAVA language and OOP paradigm.Most experience developers seem to forget the theory behind the language. I am not saying that they are not good at their job but can they explain to junior developers why they have used interfaces instead of abstract classes or why implement a pattern over another one? As a programmer, you become very arrogant as you believe that you write the best code but in the real world, people work in teams with different skill set and experiences. It is important that you can backup your actions/ codes. A very simple question such as; when should I use a String object instead of a StringBuilder/ StringBuffer? You might take this question lightly but can you actually tell someone else the
    difference?
  2. Know your technology stackAll developers have to know their technology stack. What does it mean? JAVA is not like other languages; JAVA has subsets such J2ME and superset such as Java EE. We have our own area of expertise but it is important to know the differences between the various sets of JAVA. Some basic questions such as the differences between SWING, Applet,
    Servlets, EJBs and JAVAFX will boost your confidence. Most developers do not know how to tweak the JVM and the differences between the JRE and the SDK environment. Do you know why you need the SDK to be installed to run Tomcat but you only need the JRE to run an application?
  3. Experiment with various Java EE frameworkI am not asking you to be an expert in every single Java EE framework but it will make the difference if you are familiar with Spring and EJB. That should actually be the de facto framework that should be on every developers CV. Developers should know the difference between Java EE 5 (soon 6) and Spring. Hibernate is also brilliant and it’s used for data access but all developers should have moved to JPA by now. Hibernate also comply with JPA therefore there is no more excuses.
  4. Know a scripting languageJAVA can be heavyweight for some simple tasks which can be implemented using a simple dynamic language such as Python, Perl(?) and others. I would also recommend to developers to learn shell scripting on their target OS.
  5. Know how to develop web servicesThe network is the computer, therefore it is important to know the different web services framework available. Data are integrated through web services and opening your services to the “cloud”. SWING developers will probably not develop web services but I am sure that they will be connecting to data through web services clients. Understanding the difference between the standardised SOAP and non-standardised ReST will help you choose which is best to implement your services.
  6. Know how and when to multithread your applicationI have to put that in there. Developers should know when and why to multithread an application, thread inter-communication and monitoring. All developers, junior or not, should know how to write a multi-threaded application.
  7. Database development using JDBC and JPAThis should be a development law. All developers should know how to write SQL queries and how to create databases. All enterprise applications store data in some sort of relational database systems and it is therefore imperative that this knowledge should be of second nature. Java EE 5 introduced JPA (JDO was there before) but it is not
    applicable to all situation. Hence, knowing the difference and when to implement one instead of the other is important.
  8. Know a client side scripting language and what is AJAXThe network is the computer and Internet is the deployment platform. Java EE and its various framework are server side executiong which can put extra “load” on the server. If you are looking to move a cloud based system where the providers charges you per resources used, it might be wise to move some of the execution to the client side. AJAX
    has been buzzing the scene for the last 3 years and more. This is not a technology but a new way of doing something that already existed. There are numerous JAVA AJAX framework such as GWT and DWR which makes it easy to develop AJAX based application which are compiled to JavaScript. Developers should also know what is the AJAX theories.
  9. Know your competitors and do not take part on “what is the best IDE” discussionJAVA is not the only language that can do what it does. I think that JAVA is more mature and complete as opposed to other languages. Knowing the difference between JAVA and .NET or JAVA and Ruby is a good asset to have. You also need to know when and why to use one instead of the other. Please please please, do not get into “my IDE is better than x because…” discussion as it is good for the JAVA community to have multiple IDEs and framework available to use. Every tools have their place as for example JDeveloper is better than x if you are going to solely develop on an Oracle stack and etc…
  10. Know ANT (MAVEN?), TOMCAT and any other mainstrean application serverANT is the de facto build script for JAVA and its IDE-based development. Maven is becoming popular and soon can be as popular as ANT (not sure of its popularity in the financial sector). TOMCAT should be immortalised as the based servlet container that all developers should be familiar with.

There are alot more to add but this is just some of the basics that I think all developers should have in their repertoire. Feel free to add to this list in the comments box. If I could had another one to this, would be; all developers not just JAVA, should know how to search the web and Google is your best friends (now support my advertisers by clicking on the links on the right ;) ). I hope you enjoyed the entry and feel free to comments good or bad!!! are welcome.

  • Share/Bookmark

BlockingQueue与InterruptedException

感谢Blader同学的抛砖

首先,这段代码会编译成功吗,运行起来会有异常吗,他会打印什么?

1
2
3
4
5
6
7
8
9
10
11
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
 
public class Foo {
   public static void main(String[] args) throws InterruptedException {
       BlockingQueue q = new LinkedBlockingQueue();
       q.put(1);
       Thread.currentThread().interrupt();
       System.out.println(q.take());
   }
}

运行后结果如下:

Exception in thread "main" java.lang.InterruptedException
	at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireInterruptibly(AbstractQueuedSynchronizer.java:1135)
	at java.util.concurrent.locks.ReentrantLock.lockInterruptibly(ReentrantLock.java:312)
	at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:354)
	at Foo.main(Foo.java:9)

看了一下源代码,阻塞队列的访问方法(take、put、poll、offer)会在执行之前检查Lock对象的中断标记,而Lock对象则是检查当前线程的中断标记

  • Share/Bookmark