What does “compare two strings lexicographically” mean? Answer Leading from answers from @Bozho and @aioobe, lexicographic comparisons are similar to the ordering that one might find in a dictionary. The Java String class provides the .compareTo () method in order to lexicographically compare Stri…
Tag: java
How to calculate the number of lines in a “Java Project”
How can I calculate the number of lines in a “Java Project”? I’m using Netbeans 6.9. Answer Have a look at the NetBeans Metrics Module. NetBeans Metric Module is a module for NetBeans that can measure your java source code and display the results in NetBeans. Or the wordcount plugin. Counts …
The purpose of interfaces continued
OK so I gather that Interfaces are a way to enforce that an object implements a certain amount of functionality, without having to use inheritance. Kind of like a contract. And I semi see the point of them. But if all you have in the interface is: and it has no implementation as such, then whoever uses your i…
Count words, java
I want to count words. I use the methods hasNextChar and getChar. The sentence may contain all kind of chars. Here’s my code: It works so far but e.g. when I have a ” . ” at the end it gives me 8 instead of 7 words. Here are some examples of sentences: *„Schreiben Sie ein Praktikanten-Vermit…
How to upload sources to local Maven repository
Suppose I have a Maven 2 Java project on my local machine. I build the project .jar file and push it to my local Maven repo, using mvn install. Question: How can I force Maven to also push the project sources jar to the local repo? This is useful if I’ll use the above mentioned project as dependency whi…
“Java DateFormat is not threadsafe” what does this leads to?
Everybody cautions regarding Java DateFormat not being thread safe and I understand the concept theoretically. But I’m not able to visualize what actual issues we can face due to this. Say, I’ve a DateFormat field in a class and the same is used in different methods in the class (formatting dates)…
How do you create a proper Epoch calendar object in Java?
I want to create a calendar object that is the epoch date. What’s the ‘correct’ (if any) way to do it? Answer The ‘setTimeInMillis()’ method would work fine and be easily understood by others. It might also be clearer if you passed it 0 instead of 1. The first method has more lin…
How do you format the day of the month to say “11th”, “21st” or “23rd” (ordinal indicator)?
I know this will give me the day of the month as a number (11, 21, 23): But how do you format the day of the month to include an ordinal indicator, say 11th, 21st or 23rd? Answer The table from @kaliatech is nice, but since the same information is repeated, it opens the chance for a bug. Such a
Bounded, auto-discarding, non-blocking, concurrent collection
I’m looking for a collection that: is a Deque/List – i.e. supports inserting elements at “the top” (newest items go to the top) – deque.addFirst(..) / list.add(0, ..). It could be a Queue, but the iteration order should be reverse – i.e. the most recently added items should…
Hibernate @ManyToOne references an unknown entity
I am receiving the following Hibernate Exception: @OneToOne or @ManyToOne on Matchup.awayTeam references an unknown entity: Team The simplified Matchup class looks like this: The simplified Team class looks like this: Notes: Both Matchup and Team have subclasses. I’m not sure if this impacts the situati…