Tag Archives: java

Round, Floor and Ceiling in Expression Language

Expression Language makes working with Java Server Pages a slightly less pain in the behind. But, its functionality is very limited, there is for instance no way to round off a number, neither as floor, ceiling or to the closest integer

Floor(foo) -> ${foo - ( foo % 1 ) }
Ceiling(foo) -> ${foo + ( 1 - (foo%1)) % 1}
Round(foo) -> ${foo +0.5 - ((foo+0.5) % 1) }

This still gives you a float, so to get an integer, you must either use the <fmt:formatNumber>-tag

<fmt:formatNumber value="${foo - ( foo % 1 ) }" var="fooAsInt" maxFractionDigits="0"/>

(really, this returns a string, representing the number without the decimals. But as EL automatically casts between strings, floats and integers, this is mostly OK.)

or you can hack it using fn:replace():

${fn:replace(foo - ( foo % 1 ),'.0','') }

(Yes, you may use singlequotes for strings in EL, even though this is supposed to be Java….)

Merging two lists

Lets say you have two lists, one of them containing the values [1,2,3] and the other one containing the values [4,5,6], and you want to combine these two lists into one list, like this one: [1,2,3,4,5,6].

Let’s see how this can be done in different (high level) programming (or scripting or templating) languages.

Java

Java has multiple list implementations, lets start with the most basic one, the builtin array.

int[] A = {1,2,3};
int[] B = {4,5,6};
int[] C = new int[A.length + B.length];
int counter=0;
for(int e : A){
  C[counter]=e;
  counter++;
}
for(int e : B){
  C[counter]=e;
  counter++;
}

or with an ArrayList:

/*Dropped importing the correct classes, 
and constructing the ArrayLists A and B, since thats not the focus here...*/
List<Integer> C = new ArrayList();
C.addAll(A);
C.addAll(B);

PHP

So, how is the same done in PHP?

$A=array(1,2,3);
$B=array(4,5,6);
$C=array_merge($A,$B);

Python

And at last, how does the Pythonistas do this?

?View Code PYTHON
A=[1,2,3]
B=[4,5,6]
C=A + B

Note: the rubyists use the same approach.

Static typing VS. Unit tests

Okay. It’s kind of stupid to put static typing up against Unit tests. Even so, lots of people does so a lot of times in the discussion between dynamic and static programming languages.

Static typing provides you with a security net when it comes to typos. Alhough, it doesn’t give you any security against logical errors.

Read more »

WeSIP – SIP application server

WeSIP seems like an interesting project, or at least there might be built lots of interesting applications on top of it. WeSIP is for SIP what Jboss, Tomcat and others are for HTTP.

For the uninitiated, SIP stands for Session Initiation Protocol, and is used to set up sessions for VoIP, games, IM and more. The SIP protocol is very similar to another successful protocol you might have heard of, http.

valgets kvaler

I morgen holder en kamerat (og kollega) av meg (Christer Solkogen) et foredrag om pakkesystemer i regi av BLUG. Det har jeg lyst til å få med meg, men jeg har også lyst til å få med meg JavaBin foredraget “Improving Test Maintainability” som hendig nok foregår på samme tidspunkt.

Jeg har nok størst sosialt utbytte av å gå på BLUG-foredraget, men sannsynligvis størst intellektuellt utbytte av JavaBin foredraget.

Hva skal jeg velge?

JavaBin 2. April 2008: Concurrency & performance

Foredragsholder: Kirk Pepperdine (http://kirk.blog-city.com/)

Kirks eget abstract for foredraget:

 

“Both Intel and Microsoft have recently said that we, as developers, need to start delivering more concurrency in our applications. What does this mean? How did we get to this point?

In this talk, we will look at the trend towards more and more cores and and what this means for Java programmers. Can we expect that our Java applications will automatically take advantage of the extra processors, or will we need to become more aware of the hardware aspects of our system?

In this session, you will learn:

  • What’s behind the trend towards concurrency;
  • What developers must be prepared for with concurrency moving forward;
  • What concurrency looked like in earlier JDKs, and how it’s evolved today;
  • How you can tell if you have a performance bottleneck because of concurrency.

Fri programvare – pain solution?

 

Snart klart for Javazone – IDG.no

Fri programvare. Første gang Javazone ble arrangert hadde Javabin hentet inn selvskadesirkuset Pain Solution. En gjeng som ikke står i veien for smerte. De henger seg opp i kroker festet til huden. Etterpå spilte Jaga Jazzist.

Kan noen fortelle meg hva som er sammenhengen mellom første ledd og resten av avsnittet?

Sun slipper Java under GPL

Fra i dag av er Java lisensiert med GNU Public Licence versjon 2. Dette er en Fri Programvare-lisens, som sikrer at alle kan videreutvikle, og videredistribuere Java, forutsatt at de gir andre samme muligheter med deres videreutviklede versjon. Programmer som er skrevet i Java derimot må ikke være fri programvare eller åpen kildekode.Digi.no om saken

Dette må feires!

HOWTO: Java i firefox under Linux

Denne howtoen er noe utdatert

her er en nyere

Selvfølgelig, hvis du bruker Ubuntu Gutsy, alt du trenger å gjøre er å klikke her

Java er en av de innstikkene til Firefox som ikke kan istalleres med innstikk-behandleren i Firefox. Java-innstikket må installeres manuellt (eller gjennom systemets pakkesystem). Jeg vil her ta for meg hvordan en installerer dette på en RedHat-basert og en Debian-basert distribusjon. Framgangsmåten for Debian-baserte distribusjoner vil sannsynligvis fungere i alle typer distribusjoner, men jeg skriver Debian her fordi jeg bruker Ubuntu selv.

Edit(2006-06-25): I Ubuntu 6.06 kan Java installeres langt enklere, apt-get install sun-java5-plugin
Read more »

99%

Woha! Dette blir en liten skrytepost. Jeg fikk nettopp tilbake evalueringen av min forrige oblig-innlevering i INF101, og fikk 99 av 100 poeng. Jeg fikk ett poeng i trekk fordi jeg hadde glemt å legge ved et kjøreeksempel av programmet. Akkurat det var litt surt. Men 99 av 100 er likevel rimelig ok.

My bookshelf

I took a picture of my new laptop the other day. It was then I saw how geeky my bookshelf was, containing these books:

  • Web Database Applications with PHP and MySQL
  • Learning XML
  • Learning XSLT
  • Python – how to program
  • MySQL reference manual
  • Programming Languages – concepts and constructs
  • HTML 4.01 Specification
  • Conputer Networks
  • A history of modern computing
  • A brief history of the future – The origins of the Internet
  • Learning Java
  • Data Structures and Algorithms in Java
  • Designing with web standards
  • On to Java
  • Java network programming and distributed computing
  • Windows ME annoyances
  • Java som første programmeringsspråk
  • Java software solutions
  • Learning WML and WMLScript
  • Human computer interaction