Top 50 Guides for Beginning Web Developers
Top 50 Guides for Beginning Web Developers
Top 50 Guides for Beginning Web Developers
The following code does not compile:
public class A {
public static void main(String[] args) {
int i = Integer.parseInt(args[0]);
switch (i) {
case X: System.out.println("ONE!"); break;
case Y: System.out.println("TWO!"); break;
default: System.out.println("ZERO!"); break;
}
}
public static final int X = B.getNumber("X");
public static final int Y = B.getNumber("Y");
}
class B {
public static int getNumber(String s) {
if (s.equals("X")) {
return 1;
}
else if (s.equals("Y")) {
return 2;
}
else {
return 0;
}
}
}
The compile error is:
A.java:5: constant expression required
case X: System.out.println("ONE!"); break;
^
A.java:6: constant expression required
case Y: System.out.println("TWO!"); break;
^
2 errors
I think I'll leave explaining why as an exercise for the reader. (Or for a future post. ;-)
Suite à des circonstances que je vais sans doute prochainement détailler, j'ai perdu l'un des ordinateurs que j'utilisais à la maison.
In recent projects we have used the Spring MVC integrated into OpenCms. This topic is not new to the OpenCms community, as it has already been covered a
little in the OpenCms wiki and also Bearingpoint provides an open source submodule in their Commons-Project at Sourceforge.
Nevertheless, we make our small 'getting-started' project available now - it's aimed for developers who want to integrate Spring & Hibernate into
OpenCms for the first time and would like to have a ready-to-go starting point/project setup.
The project includes Eclipse and NetBeans project files as well as the ant build file. We used it for OpenCms7.0.5 and OpenCms7.5. With these OpenCms versions, the versions of the depending lib files used by Spring and OpenCms should not
conflict. (We didn't use it with OpenCms6 yet).
SVN:
http://svn.sysvision.net:9027/svn/com.sysvision.opencms.spring/
User: anon, Password: anon
or download as zip from:
http://www.sysvision.de/en/expertise/cms/solutions/opencms_spring_integration.html
The project contains a Readme.pdf how to use it. We hope it's useful to someone and are open for any comments, suggestions and improvements.
(A note regarding Hibernate: we don't use the OpenSessionInViewPattern (OSIV), so you won't find it in the project. If you want/need it, you will
find infos about it in the opencms-wiki.org)
I subscribe to several OR blogs in Google Reader. One of them has an
interesting post
http://research-reflections.blogspot.com/2009/06/model-formulation-vehicle-routing.html
Not so much in the article itself, but the comment on Drools-solver
more so. I've done some work with meta-heuristics
and CP, and the reading I've done on Drools-solver sounds eerily
similar.
http://java.dzone.com/articles/solving-planning-problems-intr
http://downloads.jboss.com/drools/docs/5.0.1.26597.FINAL/drools-solver/html/index.html
Ce matin, Eclipse 3.5 est sorti, et je me suis dit que j'allais l'installer. Seulement, j'utilise aussi maven et subversion. Ert d'un seul coup, ça devient moins drôle à faire marcher !
I was going through some CMS and portal software implementations yesterday, and looked at them from a standards point of view. You might wonder, why are standards important ? Isn't it easier to build something minimal that will do just the job ? Well in terms of software engineering it probably seems to be, but you end up in a very proprietary system, but using standards don't necessarily mean that you will have to build more code.
One standard comparison that is often mentioned nowadays is the one between SQL and CMIS. Some call CMIS the "SQL for content", while others (like my good colleague Stéphane) view it more as the SQL for file systems :) But anyway, what do these standards really bring us, except for the hassle of implementing them and even harder testing interoperability ?
I think one of the best examples in this area is what has happened in the browser world. They would have never existed if it wasn't for standards. When Mozilla was started, there wasn't really a standard for HTML, it was written based on the implementation, but that's ok. When Mozilla became Netscape, it added a lot of extensions to HTML, like layers, that weren't part of the standard, and when Internet Explorer came to the market, it had a different implementation of layers. So basically for a while, people building web sites either had to do two versions of their websites, or just refrain from using layers until they were standardized.
So what did people gain from the standards ? Well on the end users part : choice. On the web developers side : less work. On the browser's side : a very good API to implement and especially to test against ! The last point is very important, it is one of the reasons that Java became such a success. The API was clearly a "standard", established through the Java Community Process process, to make sure that various implementations would comply to the same API. Sure there were some glitches here and there, but globally it was quite a success.
Giving customers choice is not necessarily something they will immediately understand, but it is good for them. When Internet Explorer became the dominant browser, the best way to attack it was through its less than compliant implementation of CSS. Suddenly web developers starting complaining about high development costs, were developing better looking layouts on other browsers, and Firefox became a very strong competitor.
In the CMS market, this need for standardization is still in the process of happening, but nonetheless important. Customers must understand that the investment they are doing into their content management system must imply the possibility to import and export the content easily, and especially interoperate between various content system. This is especially true when you go into the semantic web, where content systems will need to create semantic links across vendors, and that is still a bit of a pipe dream at this moment.
Some standards are de-facto standards. When these de-facto standards are actually owned and controlled by a single company, this is more of a problem. Look for example at Microsoft's Internet Explorer or the iPhone's AppStore. Both these de-facto standards are really creating frustration on both the user and developer's sides. In the iPhone's AppStore for example, the end-user cannot use applications that run in the background or fully interact with the phone, the applications only run on the iPhone or iPod Touch, and any complaints are completely ignored by the company because it cannot handle the sheer volume of customer requests. On the developer's side, the closed platform means that you can spend 6 months developing an application that will never be accepted. Again the fact that a standard is de-facto doesn't guarantee it's success.
But when the de-facto standard is established by an open-source foundation such as the Apache Foundation, things can be very different. Even in the case of SpringSource, fathers of the excellent Spring Framework, the de-facto standard can become a real strong force. So the combination of de-facto and open source is a really powerful one, especially if the implementation has a large public. But what is even better is a real standard and open-source implementations, like the Apache Jackrabbit or Apache Chemistry projects. Even if the project might still run out of steam one day, the standards on which they are based will still be there, and the legacy can be guaranteed to be understood and the interface still present to allow future developers to be able to interact with the systems.
In the aviation industry, they do the exact opposite to what most of the software industry does, they only use "old" bricks, that they know have been proven to work, and adhere very strictly to standards and specifications. This allows constructors to protect human lives from harm. This has an incidence on cost of course, but because they are doing this mostly within a single company and also because of the materials and manpower needed. But there is software running in airplanes and space shuttles, so the importance of standards and high reliability doesn't need to be incompatible with the business of building software.
The real hard part is building software quickly and reliably, without incurring too many costs, and this is where the open source community comes into play. Some projects in the Apache Foundation have been incredible in that regard. The Apache Jackrabbit project is such an example, the Spring Framework is another, and there are many such stories of high quality software, adhering to standards, that have been developed much quicker than ever before. But they wouldn't be interesting if they didn't adhere to a standard, be it de-facto (because of community size and open-source) or "real".
Jahia was born out of a proprietary content management system, and is moving all of it's sub-systems to be built on on top of both the "real" and de-facto standards. It builds value on top of bricks that have been proven to be reliable, modern and standard such as the JCR, the Portlet API 2.0, WebDAV, GWT, the Spring Framework, Log4J, and many more. We are working on integrating CMIS and possibly other new standards (such as the work being started in the IKS project). Of course the real value to the customer is not in the bricks, but in the building you have constructed using the bricks.
When you start coding, the usage of the if-clause is a vital point of learning. That is, why I want to show you on an example, how to use the if-clause correctly.
I want to show on some examples, how to use the if-clause in java. So, we assume, we have 2 variables A and B. Both can be true or false, what makes them of type boolean.
When we are finished, we want to see the following outcome:
sut.printWay(true, true); |
| Java2html |
| A is true, but B is not
|
| B is true, but A is not
|
| A is true, as B is, too
|
| Both A and B aren't true
Okay, we have read something about if-else some time ago, so we make our first attempt to get this outcome:
public class ShowIf { |
| Java2html |
Well, we just can accomplish 3 of 4 different outputs, but that code looks good. So we start our first test and now we get this:
| > A is true, but B is not
| > Both A and B aren't true
|
| > B is true, but A is not
|
| > A is true, but B is not
| > B is true, but A is not
|
| > Both A and B aren't true
As you can see, in 2 cases we don't get the output, we want to see. The first error is shown in the case where A is true and B is false. The second error you can see, when both Variables are set to true.
Why there are mistakes? If you follow the pathes through the ifs (and you really should do that, to understand what's happening), you see that if(A) and if(B) seemingly aren't connected. In both errors we get an output from if(B) where we don't want it to do any work.
Okay, now we start to nest both ifs, that only the correct one can work:
public class ShowIf { |
| Java2html |
And our output will be:
| > A is true, but B is not
|
| > B is true, but A is not
|
| > A is true, as B is, too
|
| > Both A and B aren't true
Yep. That is, what we want. Now the only problem left is that our code looks a little blown up. Let's make it more beautiful.
We have 4 different cases (true,true), (true,false), (false,true) and (false, false). We should be able to align them all, but how?
After some reading you might find out, that there is another option in an if-else statement, that gives you a more flexible handling:
the else if
| if(something == true) {
| //one path
| } else if(somethingElse == true) {
| //another path
| } else {
| //everything else
| }
And it really works like this one:
| if(something == true) {
| //one path
| } else {
| if(somethingElse == true) {
| //another path
| } else {
| //everything else
| }
| }
But, as you might agree, with else-if it looks much more beautiful and shows much clearer what we want to accomplish.
Well, try yourself a little how to use it, but hopefully you will come to something like this:
public class ShowIf { |
| Java2html |
I hope you gained some new ability, to improve your code.
The last test and we are finished for now:
| > A is true, but B is not
|
| > B is true, but A is not
|
| > A is true, as B is, too
|
| > Both A and B aren't true
Of course no-one should ever need to use these switches but here they are ...
... to disable the pmd plugin
-Dpmd.skip=true
... to disable the test phase
-Dmaven.test.skip=true
I've been meaning to "release" a clojure program into the wild. Partly,
I want to take advantage of how nice it is to be able to deploy via jar
file, and partly because I've been wanting this application.
So, without further ado, here's my hexclock (as an executable jar file).
Source is included and is covered by the GPL
http://www.gnu.org/copyleft/gpl.html
Just FYI
sha1sum: ac0b67fa8252bf06f00d627dfc3f2975b1c45a30 hexclock.jar
Here's some explanation if you're confused. The basic idea is to divide
a day into half, so now we can say if it is AM or PM; easy but, I would
say, a little too coarse of a measurement. With the AM/PM clock, you'd
only need one bit ("is it morning?"). Continuing, next we can divide our day
into 4 equal parts, now we could (using two bits) say whether it was the
first part of the morning "early morning" or the second part of the
morning "late morning." Likewise we could talk about whether it were
late or early PM. These chunks would be 6 hours long. You can see that
we can keep dividing our day like this as much as we want, with each
division we need one more bit to talk about the time and we get twice as
many (and twice as short) chunks. In fact, if you wanted to keep going
until you got something like a second, it just so happens that you'd be
using 16 bits (though, it is a pretty close call (about 32% error versus
34%)). Which just happens to work really nicely for binary arithmetic as
we'll see.
Make sense doesn't it? While I have you agreeing with me (if you are),
stop and think about this for a bit, the steps to divide up time into
hours, minutes, and seconds are not at all constant. You must divide a
day into 24 hours, then an hour into 60 minutes and then again a minute
into 60 seconds. Quick, how many seconds in a day? The answer isn't
anything in particular, 86,400 (24*60*60). A fun number for us physics
nerds to memorize as an undergrad, but just that, an arbitrary constant.
The way that the clock works is just to represent the day as a 16 bit
number (0 through 65535), if you are accustomed to hexadecimal, this is
0x0000 through 0xFFFF. Hex has the nice property that each digit is four
bits (sometimes called a nybble, half a byte, get it? Well, I like it).
Numbers go 0-9 like usual but then we use A, B, C, D, E, and F for 10
through 15. I somewhat arbitrarily (and somewhat not) divide this number
into two parts the "high" byte (two hex digits) and the "low" byte (the
last two hex digits). I separate the time with a vertical bar like this:
"AB|CD", if you are a programmer this is meant to evoke logical OR. You
can imagine that the time is 0xAB00 | 0x00CD and they get smushed
together with the or operator.
When I implemented this in Python:
http://twopoint718.blogspot.com/2008/08/hex-clock.html I talked a bit
about the scale of the digits on the clock. The last digit changes every
1.318 seconds, the next most stable digit changes just about every 21
seconds. The next (the "B" in my example above) switches once every 337
seconds or about 5 and a half minutes. The most stable digit changes
only 16 times a day, since both 24 and 16 are divisible by 4 this makes
that digit equal to 90 minutes (1.5 hour). My proposal is to talk about
the first, most stable digit as hex hours, the second as hex minutes,
and the last two digits are hex seconds. My coined terms for these are
"hexours" (HEX-zours), "hexinutes" (HEX-inuts), and "hexeconds"
(HEX-econds). There are 256 hexeconds in a hexinute and 16 hexinutes an
an hexour. Alternatively, you could just say there it is AB "in the big
byte" and CD "in the little byte". I imagine people would just call out
the time "it is ABCD." To avoid confusion, I think all digits should
always be pronounced "zero, zero, zero, one," though maybe we could all
use the English "z" sound of "zed-zed-zed-one" because it cuts down on
the syllables. But when in doubt, if fewer than four digits are
announced, we should assume that they are talking about the most
siginificant digits first (much in the way that we say "it is 3
o'clock").
You can read the post that inspired this idea here:
http://halcanary.org/vv/2007/10/31/706/
You can read more about hex time here:
http://www.intuitor.com/hex/hexclock.html (this clock is really similar
to mine, we just group the digits differently, either one is fine).
Wikipedia has an entry about it here:
http://en.wikipedia.org/wiki/Hexadecimal_time (maybe I should change my
digit grouping?)
Don't confuse this method of marking time with other binary clocks.
Often they are using binary coded decimal:
http://en.wikipedia.org/wiki/Binary-coded_decimal
Until recently this clock was an example (they added a "true binary"
switch):
http://www.thinkgeek.com/homeoffice/lights/59e0/