Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

4 June 2019

Awesome Articles and presentations about Software Developemt stuff



  1. (Java) Style Guidelines for how to use var in Java
    • http://openjdk.java.net/projects/amber/LVTIstyle.html
  2. (Java) The Future of Java / OpenJDK and how it impacts you!
    • https://www.youtube.com/watch?v=078QIrp0SD8 
    • Java 11 is coming and Java will be still free or ... is Oracle planning to follow evil game practices like EA  and spam Java with loot boxes, DLC and other money-draining activities? As it turns out 6-month release brings lots of goodness with release feature as soon as they ready rather than wait years for the next release and some challenges:
  3. (Containers) Build Containers from scratch
  4.     




29 April 2019

Where Azul Java is installed on Mac OS?

If you are not Apple acolyte but just a person who is using Mac for development, you may wonder where Azul Java is installed?

Answer is ....

JDK 11
/Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home

JDK 12
/Library/Java/JavaVirtualMachines/zulu-12.jdk/Contents/Home

I think you got pattern :)

18 August 2016

How to get difference between 2 dates ( LocalDate ) in years , months or days ?

Solution for :
Java 8 and above

STORY:

August in my month of Java 8 where I try practice various things that are new in Java 8 and I should know already. At some point , I tried to create person  with  birthday stored as LocalDate and get age in years , but I found it that there is no method on Duration to check that. I was wonder can I do it this using only Java 8 . As it turns out yes.

SOLUTION:
You need use ChronoUnit class that has a nice method to do this.
LocalDate birthday = LocalDate.of(1980,4,4);
ChronoUnit.YEARS.between(birthday,LocalDate.now()));

EXAMPLE: (To run this example you need copy these 2 classes and add junit and assertJ libraries )


Person class:
package dms.pastor.kb.java8.example;

import java.time.LocalDate;
import java.time.temporal.ChronoUnit;

/**
 * Author Dominik Symonowicz
 * Created 18/08/2016
 * WWW:    http://pastor.ovh.org
 * Github: https://github.com/pastorcmentarny
 * Google Play:    https://play.google.com/store/apps/developer?id=Dominik+Symonowicz
 * LinkedIn: uk.linkedin.com/pub/dominik-symonowicz/5a/706/981/
 */
public class Person {
    String name;
    LocalDate birthday;

    public Person(String name, LocalDate birthday) {
        this.name = name;
        this.birthday = birthday;
    }

    public String getName() {
        return name;
    }

    public int getAge(){
       return Math.toIntExact(ChronoUnit.YEARS.between(birthday,LocalDate.now()));
    }

    public int getAgeInMonths(){
        return Math.toIntExact(ChronoUnit.MONTHS.between(birthday,LocalDate.now()));
    }

    public int getAgeInDays(){
        return Math.toIntExact(ChronoUnit.DAYS.between(birthday,LocalDate.now()));
    }
}


PersonTest class:
package dms.pastor.kb.java8.example;

import org.junit.Before;
import org.junit.Test;

import java.time.LocalDate;

import static org.assertj.core.api.Assertions.assertThat;

/**
 * Author Dominik Symonowicz
 * Created 18/08/2016
 * WWW:    http://pastor.ovh.org
 * Github: https://github.com/pastorcmentarny
 * Google Play:    https://play.google.com/store/apps/developer?id=Dominik+Symonowicz
 * LinkedIn: uk.linkedin.com/pub/dominik-symonowicz/5a/706/981/
 */
public class PersonTest {
    Person person;

    @Before
    public void setup() {
        person = new Person("Dominik", LocalDate.now().minusYears(18).minusMonths(1).minusDays(1));
    }

    @Test
    public void shouldReturn18YearsTest() throws Exception {
        //When
        final int age = person.getAge();

        //Then
        assertThat(age).isEqualTo(18);
    }

    @Test
    public void shouldReturn217MonthsTest() throws Exception {
        //When
        final int age = person.getAgeInMonths();

        //Then
        assertThat(age).isEqualTo(217);
    }

    @Test
    public void shouldReturn28DaysTest() throws Exception {
        //Given
        Person toddler = new Person("Toddler",LocalDate.now().minusDays(28));

        //When
        final int age = toddler.getAgeInDays();

        //Then
        assertThat(age).isEqualTo(28);
    }
}



:) I hope, you found this useful

23 November 2015

Bookshelf of My top (Java) software development books

This is not typical "Top 10 favourite book", "Essential  or Must-Read Software Development Books" and so on .This is just selection of books that I found useful in my software development carrier so far.




1.  Eric Freeman, Elisabeth Robson, Bert Bates , Kathy Sierra  - Head First Design Patterns Paperback 
  • http://shop.oreilly.com/product/9780596007126.do
  • After this book ,if you feel bored and you fancy read legendary book on this subject then read this: Gang of four - Design Patterns: Elements of Reusable Object-Oriented Software


2.  Steve Krug - Don't Make Me Think!: A Common Sense Approach to Web Usability
  • https://www.sensible.com/dmmt.html
  • This is a simple and awesome book about user experience design basics.
  • After reading this book it is worth to see some presentation by Janne Jul Jensen


3. Michael T. Nygard - Release It!: Design and Deploy Production-Ready Software
  • http://pragprog.com/book/mnee/release-it
  • for some odd reason this is not well know book, but everybody who read this book thinks that this book is very important because it helps you understand whole life cycle of software .


4. Simon Brown - Software Architecture for developers
  • https://leanpub.com/software-architecture-for-developers/read#what-is-architecture
  • One of the newest on my shelf. Really interesting  book that shows how to  successfully  adapt  "software architecture" role into agile universe that all teams want to be in but as we know Scrum hates Architects .


5. Gregor Hohpe , Bobby Woolf - Enterprise Integration Patterns
  • http://www.eaipatterns.com/eaipatterns.html
  • This book is very useful ,if you will have a privilege to work with Apache  or Spring Integration as they based on this book.


List of book that many people mentioned that is must read book that I haven't read yet:
  • The Psychology of Everyday Things
  • Clean code
  • Colin Vipurs "Test needs love too"
  • Refactoring, Improving design of existing code
  • Effective Java
  • Agile Software Development, Principles, Patterns and Practices
  • (and I am planning read all of them next year)




I  still didn't find great book about:
  • algorithms
  • testing
I am sure they are already written ,but I just didn't read them yet.If you know any ,let me know.









14 November 2015

what is a static block of code in Java ? (with example of typical usage )


It is so funny ,but more I learn about Java then less I know about Java and sometimes I feel like less I know then better than sleep as more I discover then more I feel ashamed that I didn't know this already.

Today ,for example I discover existence of ... static block code of code.

Static block is a static initializer..It is a block of code that is run when the class is loaded to JVM. It is run after the invocation of the super constructor and before the constructor code is executed. It can be useful for example to setup some data in enum.
More about can be found here: http://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.7

Example:
package dms.pastor.kb.java.basics.staticblock;

import java.util.HashMap;
import java.util.Map;


/**
* Author Dominik Symonowicz
* Created 14/11/2015
* WWW: http://pastor.ovh.org
* Github: https://github.com/pastorcmentarny
* Google Play: https://play.google.com/store/apps/developer?id=Dominik+Symonowicz
* LinkedIn: uk.linkedin.com/pub/dominik-symonowicz/5a/706/981/
*
*/


public enum TrainStation {
    TIANJIN_RAILWAY_STATION("TJZ"),
    WROCŁAW_GŁÓWNY("We"),
    BATH_STATION("BTH"),
    YORK_STATION("YRK"),
    TOLEDO("TOO"),
    LONDON_SAINT_PANCRAS_INTERNATIONAL("STP"),
    ANTWERP_CENTRAL_STATION("ASS"),
    MILANO_CENTRALE("MIC");

    private final String abbreviation;

    private static final Map lookup = new HashMap<>();

    static {
        for (TrainStation trainStation : TrainStation.values()) {
            lookup.put(trainStation.getAbbreviation(), trainStation);
        }
    }


    TrainStation(final String abbreviation) {
        this.abbreviation = abbreviation;
    }

    public String getAbbreviation() {
        return abbreviation;
    }

    public static TrainStation get(String abbreviation) {
        return lookup.get(abbreviation);
    }

    public static String getTrainStation(TrainStation trainStation) {
        String name = trainStation.name();
        String stationName = "";
        for(String word : name.split("_")){
           String firstCharacter = word.substring(0, 1);
           String rest = word.substring(1, word.length()).toLowerCase();
           stationName += firstCharacter + rest + " ";
        }
    stationName.substring(0,stationName.length());
    return stationName;
    }

}
Happy weekend everybody !

29 April 2015

Can you run main method from Abstract Class?

Can you run below code?
package dms.pastor.abstractclassrunner;

public abstract class AbstractClassRunner {
    public static void main(String[] args) {
        System.out.println("If you see this,it means you can run main method in Abstract Class");
    }
}

Answer is ...Yes ,we can run  main method from abstract class.
It was a rather shock when I heard this,but then I asked myself. How it is possible?

I think about it and then I realised that:
  • Abstract method cannot be instantiated 
  • BUT , main(String[] args) is a static method and that means, it can be accessed without instantiation of the class to which it belongs
As result you can run main(String[] args) in abstract class.
 Simple.

18 August 2014

Displaying Chinese characters on Swing components like JTextField, JTextArea and etc.

WARNING: this is workaround , not solution for problem!
Solution for Java 6.

Problem:

I decided to write a little utility application to help me manage dictionary file that I use for one of my Android application. I was stuck  with tiny problem that  swing components like JTextField, JTextArea and etc. doesn't display .


Solution:

There are few  fonts that  contains Chinese characters,so they can be used in Swing Components:
  1. Arial Unicode MS
  2. Monospaced
Unfortunately ... Rest of them didn't work for me.

Note:
I may investigate this in future.

5 January 2014

Why String is immutable in Java?

One of the most common question(on exams,interview), which has one of  most blurry answers.

So.. Why bloody String  is immutable in Java?

There are few known to me reasons why (with explanations and resources):


  • Design decision  (immutable  Strings cause much less trouble to implement many features in Java like cache, HashMap)
  • Security 
  • Optimization
  • Concurrent purposes (multi-threading


Design decision and optimization:
James Gosling: I would use an immutable whenever I can.
Bill Venners: Whenever you can, why?
James Gosling: From a strategic point of view, they tend to more often be trouble free. And there are usually things you can do with immutable that you can't do with mutable things, such as cache the result.
Another thing about immutable objects: if you have a class that's final and whose fields are final, except for one nasty problem, the optimizers can do really cool things with them, because they don't necessarily have to allocate them in the heap. They can have pure stack lifetime. You can copy them at will. You can replicate them at will, which is what happens with primitives.
Another thing about immutable objects: if you have a class that's final and whose fields are final, except for one nasty problem, the optimizers can do really cool things with them, because they don't necessarily have to allocate them in the heap. They can have pure stack lifetime. You can copy them at will. You can replicate them at will, which is what happens with primitives.
That's one of the reasons that primitives are not objects, because it is so nice to be able to just replicate them. When you pass an integer to a method, you don't have to pass the pointer to that integer.

Security:

James Gosling "One of the things that forced Strings to be immutable was security. You have a file open method. You pass a String to it. And then it's doing all kind of authentication checks before it gets around to doing the OS call. If you manage to do something that effectively mutated the String, after the security check and before the OS call, then boom, you're in. But Strings are immutable, so that kind of attack doesn't work. That precise example is what really demanded that Strings be immutable."
 String and Cache its Hashcode:
Ryan Wang The hashcode of string is frequently used in Java. For example, in a HashMap. Being immutable guarantees that hashcode will always the same, so that it can be cashed without worrying the changes.  

Concurrent purposes (multi-threading):

(I lost sources for that :( )

So remember .It was a design decision to make String  immutable for security ,optimization and concurrent  purposes.

Sources:
http://www.artima.com/intv/gosling3.html
http://java.dzone.com/articles/why-string-immutable-java

4 November 2013

How to generate random character of alphabet in java?

Java has method for random int ,but it doesn't have method for random character,but it is not a problem.

SOLUTION:

You just need below snippet:
private static String getRandomCharacter() {
String alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int character=(int)(Math.random()*alphabet.toCharArray().length);
return alphabet.substring(character, character+1);
}


  • for small character simply replace with ABCDEFGHIJKLMNOPQRSTUVWXYZ with abcdefghijklmnopqrstuvwxyz or if you need small and capital letter then replace with ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz   
  • if you alphabet contains other characters ,just add them to alphabet :)

3 September 2013

After hours fun exercise 01: IntegerAdder for people fancy using args from main(String[] args) method.

HONEST WARNINGS:
  • I have only 3 years of experience as professional with many things to learn left,so keep in mind that this source code and program are NOT masterpiece of software engineering
  • Do not learn programming style from me. If you want good programming styles. Download source code for Apache Commons.
  • My solution as simple as possible,not as best as possible.
  • Comment can contains lots of sarcasm.
  • I do this for fun , learning or practice purposes.
ABOUT EXAMPLE
This is a very simple example of using args from main(String[] args) method.

MISSION OBJECTIVE
  1. I wanted to learn how to use GitHub ;)
  2. (I have many experience with using args,but i want to reuse one of my code)

WHAT THIS EXAMPLE DO ?
* It will take arguments and each argument is a path to file.
* Each file can have any number of lines from 1 to N.
* Each line can contain only one integer.
* All of the numbers from all of the files should be added to the final result.
* The result is just one number and it will be displayed usingS System.out.println() method


If you don't copy and paste code,then simply download from program from GitHub
https://github.com/pastorcmentarny/java.examples.integeradder

For simple  cases of  command line attributes.It is enough.
If planning to crazy things  and perfom lots of magic then I suggest to use libraries like:
http://commons.apache.org/proper/commons-cli/

:)

RESOURCES:
Java's tutorial
http://docs.oracle.com/javase/tutorial/essential/environment/cmdLineArgs.html
http://commons.apache.org/proper/commons-cli/


CODE

IntegerAdder class

package dms.pastor.integeradder;

/**
*
* @author: Pastor cmentarny
* #WWW: http://pastor.ovh.org
* #Github: https://github.com/pastorcmentarny
* #Google Play: https://play.google.com/store/apps/developer?id=Dominik+Symonowicz
* #LinkedIn: uk.linkedin.com/pub/dominik-symonowicz/5a/706/981/
* #Email: email can be found on my website
*
* This is an example of using args from main(String[] args) method.
*
*
* About program:
* It will take arguments and each argument is a path to file.
* Each file can have any number of lines from 1 to N.
* Each line can contain only one integer.
* All of the numbers from all of the files should be added to the final result.
* The result is just one number and it will be displayed usingS System.out.println() method
*/

public class IntegerAdder {
/**
* @param args the command line arguments. Each argument should be a valid path to file.
*/
public static void main(String[] args) {
int sum = 0;
Adder adder = new Adder();
if(args != null){
for (String integer: args) {
sum += adder.add(integer);
}
}else{
Utils.error();
}
System.out.println(String.valueOf(sum));
}
}
Adder class
package dms.pastor.integeradder;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;

/**
*
* @author: Pastor cmentarny
* #WWW: http://pastor.ovh.org
* #Github: https://github.com/pastorcmentarny
* #Google Play: https://play.google.com/store/apps/developer?id=Dominik+Symonowicz
* #LinkedIn: uk.linkedin.com/pub/dominik-symonowicz/5a/706/981/
* #Email: email can be found on my website
*
* Adder is response for sum of numbers from file.
*/
public class Adder {
public int add(String path){
File inputFile = readFile(path);
FileInputStream fis;
InputStreamReader isr;
BufferedReader br;
int sum = 0;
try {
fis = new FileInputStream(inputFile);
isr = new InputStreamReader(fis, "UTF-8");
br = new BufferedReader(isr);

String strLine;
while ((strLine = br.readLine()) != null) {
sum += Integer.valueOf(strLine);
}

} catch (Exception e) {
Utils.error();
}
return sum;
}
public static File readFile(String filePath) {
if (filePath == null || filePath.equals("")) {
Utils.error();
}
try {
File file = new File(filePath);
if (file.exists() && file.canRead()) {
return file;
} else {
Utils.error();
}
} catch (Exception e) {
Utils.error();
}
return null;//Yes, I know is crap,but i have done this way for simplicity reasons.
}
}


Utils class

package dms.pastor.integeradder;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
/**
*
* @author: Pastor cmentarny
* #WWW: http://pastor.ovh.org
* #Github: https://github.com/pastorcmentarny
* #Google Play: https://play.google.com/store/apps/developer?id=Dominik+Symonowicz
* #LinkedIn: uk.linkedin.com/pub/dominik-symonowicz/5a/706/981/
* #Email: email can be found on my website
*
* Adder is response for sum of numbers from file.
*/
public class Adder {
public int add(String path){
File inputFile = readFile(path);
FileInputStream fis;
InputStreamReader isr;
BufferedReader br;
int sum = 0;
try {
fis = new FileInputStream(inputFile);
isr = new InputStreamReader(fis, "UTF-8");
br = new BufferedReader(isr);
String strLine;
while ((strLine = br.readLine()) != null) {
sum += Integer.valueOf(strLine);
}
} catch (Exception e) {
Utils.error();
}
return sum;
}
public static File readFile(String filePath) {
if (filePath == null || filePath.equals("")) {
Utils.error();
}
try {
File file = new File(filePath);
if (file.exists() && file.canRead()) {
return file;
} else {
Utils.error();
}
} catch (Exception e) {
Utils.error();
}
return null;//Yes, I know is crap,but i have done this way for simplicity reasons.
}
}

30 August 2013

How to solve problem with Netbeans 7 display error Could not find or load main class ${jvm.memory} when run Play Framework application ?

Solution for:
Netbeans 7.x
Play Framework 1.2.6,1.2.7

STORY:
Recent updates for Play Framework was as one of the committer(notalifeform) described "the last two releases were a bit too sloppy ".
It happens.I am sure Play team are too excited about their brand new Play Framework 2.x ,so they do not put too much passion to ancient Play 1.x .


WHAT HAPPEN?
If you using mighty Netbeans and you updated Play to 1.2.6 or  1.2.7,then when you press Run,then you see:

Error: Could not find or load main class ${jvm.memory}
Java Result: 1


Play netbeansify is bit clumsy and do not set jvm.memory :(


SOLUTION:

What to do?
Go to conf/application.conf:

and add line:
jvm.memory=-Xmx512m

Done!
Run program and everything works as before (well almost You will also see error id doesn't exist,but solution is bit more complicated.You can ingore it as long as you do not use id to set mode for various cases ( )

For people who loves definitions:
"   Xmx - It is a Java application launcher's argument.It is used to  specify the maximum size, in bytes, of the memory allocation pool. "

It can be 128m,256m,1232m  ... any memory that is needed for your application


BIG Thanks for Luke (Mr. Late o'clock) F. for solution.(He sent fix to play ,but it was not included in 1.2.7 :( )

28 July 2013

Useful link: article James Gosling on Java, May 2001 A Conversation with Java's Creator, James Gosling by Bill Venners

James Gosling on Java. A Conversation with Java's Creator, James Gosling interviewed  by Bill Venners

Link: http://www.artima.com/intv/gosling3.html

It is very ancient article with Java's Creator,James Gosling.It cover quite few excited things like  explanation about why String are immutable and why Java has 'primitives types' instead of objects (Even if primitive types has wrapper ,so there is a Object representation of this values).It is worth to read it.

Why are "primitive types" (like int , boolean) not objects in java?

As part of looking for job I needed to do some revision about Java and learn few things which I always would like to learn about Java (like why string is immutable,why primitive types are not object and etc.)

What are reasons Java has primitive types instead of object ?
I expected that it must be something to do with performance or memory consumption .I found article with Creator of Java,  James Gosling where he answer on question.

"Bill Venners: Why are there primitive types in Java? Why wasn't everything just an object?
James Gosling: Totally an efficiency thing. There are all kinds of people who have built systems where ints and that are all objects. There are a variety of ways to do that, and all of them have some pretty serious problems. Some of them are just slow, because they allocate memory for everything. Some of them try to do objects where sometimes they are objects, sometimes they are not (which is what the standard LISP system did), and then things get really weird. It kind of works, but it's strange.Just making it such that there are primitive and objects, and they're just different. You solve a whole lot of problems. " Source: http://www.artima.com/intv/gosling313.html 

Source :

A Conversation with Java's Creator, James Gosling http://www.artima.com/intv/gosling313.html

16 July 2013

How to solve problem with Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified in play framework 2

Solution for  play framework 2,bit will works for all cases where javac doesn't work.

So you want try a BRAND NEW Play F
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified

You path to Java is wrong.
You can say as many bla bla bla as you want.You can swear on me,but ....
Your path to Java is wrong.

How is technically possible that other Java's program works ???
It can be few reasons:
For example. They do search in Java installation program directly (like somewhere in C:\Program Files (x86)\Java or  C:\Program Files\Java  as they found java and javac ,they can work.

Some programs, when they look for java in Windows Environment Variables  they look for variable in JAVA_HOME instead of Path.

Anyway,whatever reason is,there is

SOLUTION:

I used C:\Program Files\Java\jdk1.6.0_35\bin
  1. Open cmd (command line) You can do it in few ways for example: a( Press Win+R and type cmd and press enter. b) go to start menu  and press run and type cmd.
  2. type:  setx path "%PATH%;C:\Program Files\Java\jdk1.6.0_35\bin";
  3. Close Command line window and  Test it,by... Open command line again and type javac -version
You should see:
javac 1.6.0_35


Reminder.It will starts work in all new opened command lines (It will NOT WORK in currently open cmd windows)

25 April 2013

How to convert from Long to Integer object in Java ?

How to convert from Long to Integer object in Java ?

You need convert from Integer to Number and then convert from Number to Long using .longValue
Steps: Integer->Number->Long
See this silly method to find your solution ;).
(Silly as is done step by step without shortcuts)

public Long convertFromIntToLong(Integer num){
Integer numAsInteger = num;
Number numAsNumber = numAsInteger ;
Long numAsLong = numAsNumber.longValue();
return numAsLong;
}


I hope,it helps.

17 April 2013

How to copy all values from enum (enumeration) to to arraylist in java? (or anything from array to arralist)?

So you have some bunch of values of enum and you want them put to ArrayList.
What to do ?

Action plan:
  1. Get all values from enum and put them to array  MyEnums.values()
  2. Convert them to ArrayList  new ArrayList<MyEnums>(Arrays.asList(MyEnums.values()));
Solution:
Problem require 1 line of code, so go prepare coffee and enjoy reading:

ArrayList<MyEnums> enumlist = new ArrayList<MyEnums>(Arrays.asList(MyEnums.values()));

Simple :)

1 February 2012

How to set position of the text insertion on beginning of text instead of end of the text in JTextArea ?

(It is just note to myself)

To set position of the text insertion on beginning of text instead of end of the text. Do this:
 myTextArea.setCaretPosition(0);

13 January 2012

How to create meaninful toString() from Array in java ??

Reminder for myself


Normal array when you use method toString() produce nice but useless "memory adress gibberish".However if you want  meaningful representation of array as string then use this method (from Arrays class):

Arrays.toString(myAwesomeArray)  - where myAwesomeArray is  .... your array ;P

Simple and useful,but i discover that that it use more memory,so it can happen that will see this error for reallly really huge array:
Java heap space
java.lang.OutOfMemoryError: Java heap space

20 December 2011

How to solve problem with "execution error occured in template {module:crud}/app/views/tags/crud/table.html. Exception raised was NullPointerException : Cannot get property 'type' on null object."

Play framework said that it's awesome ,because they error messages are meaningful. Yeah.Right.
Acctually, they are quite often ... but in this case ... not.

Error:

"Execution error occured in template {module:crud}/app/views/tags/crud/table.html. Exception raised was NullPointerException : Cannot get property 'type' on null object."


In {module:crud}/app/views/tags/crud/table.html (around line 54)


50:
                 %{ } else { }%

51:
                     %{ if(i == 0) { }%

52:
                         <a href="@{show(object._key())}">${object[field]?.toString()?.escape()?.raw() ?: '(no value)'}</a>

53:
                     %{ } else { }%

54:
                         %{ if(_caller.type.getField(field).type == 'file') { }%

55:
                             %{ if(object[field]) { }%

56:
                                 <a class="currentAttachment" href="@{attachment(object.id, field)}">${object[field].filename} (${object[field].get().size().formatSize()})</a>

57:
                              %{ } else { }%

58:
                                 

59:
                              %{ } }%

60:
                         %{ } else { }%


What does mean in plain English:
If you see this odd error
means that you screwed up something during declere something in crud.table in your view:

Example:
in your awesome view file list.html:

#{crud.table fields:['challenge,'image','openDate','closeDate']}

so if in your model variable ... for example  'challenge'  doesn't exist (because you misspell or forgot to create ) ,then you will see above "meaningful" message.

8 December 2011

How to compare two floats values

This note is for myself.

For some reason i keep forgot about this very useful method :(
To compare 2 floats value  use method from Float class:
Float.compare(floatVariable1,floatVariable2);

Example:

float floatVariable1 = 8.88f;
float floatVariable2 = 1.14f;

int result = Float.compare(floatVariable1, floatVariable2);

if (result > 0) {
      System.out.println(floatVariable1 + " is grater than " + floatVariable2);
} else if (result == 0) {
      System.out.println(floatVariable1 + " and " + floatVariable2 + " are equal");
} else {
      System.out.println(floatVariable2 + " is grater than " + floatVariable1);
}