I retrieve a JSON string from internet; like most JSON I’ve seen it includes long keys that are separated by underscores. Essentially, my goal is to deserialize JSON into java-objects, but I don’t use underscores in java-code. For instance, I might have a User class with firstName field in camel-c…
Tag: java
Java regular expression. Alphabetic, with spaces and apostrophe (‘)
what is the pattern to validate the following regular expression in java. string with only letters, spaces and apostrophes (‘) I know that for letters is this (“^[a-zA-Z]+$”) For spaces is this (“\s) I don’t know what apostrophe is. But most of all i just want a single expression…
How to remove the decimal part from a float number that contains .0 in java
I just want to remove the fractional part of a float number that contains .0. All other numbers are acceptable.. For example : Is there any method available to do that other than “comparing number with “.0″ and taking substring” ? EDIT : I don’t want ACTING FLOAT NUMBERs (like 1.…
Checking file existence on FTP server
Is there an efficient way to check the existence of a file on a FTP server? I’m using Apache Commons Net. I know that I can use the listNames method of FTPClient to get all the files in a specific directory and then I can go over this list to check if a given file exists, but I don’t think
Creating a Java Connector for Pervasive PSQL
How can I create a connector for Pervasive PSQL in Java? How can I create a connector for Pervasive PSQL? I created a sample connector, but I am not sure whether it is right or wrong. Answer Here’s a simple program I have that works for me to connect to a Pervasive PSQL database: To compile it, I use: A…
Comparing two classes by its types or class names
There is need to compare two objects based on class they implement? When to compare using getClass() and when getClass().getName()? Is there any difference between this approaches to compare two Objects class types (names)? EDIT 1 What about: ? Answer Is there any difference between this approaches to compare…
Get keys from HashMap in Java
I have a Hashmap in Java like this: Then I fill it like this: How can I get the keys? Something like: team1.getKey() to return “United”. Answer A HashMap contains more than one key. You can use keySet() to get the set of all keys. will store 1 with key “foo” and 2 with key “bar&#…
JPA: how to map SQL Server uniqueidentifier type
I’ve inherited a SQL Server database that I’m trying to map via JPA. Many of the tables have a uniqueidentifier column. I’m trying to map them like so: Hibernate complains with: Answer The data type of the primary key property in the POJO determines the data type of its mapped DB column, whi…
HQL ERROR: Path expected for join
I keep trying variations of this query and can’t seem to make this happen. I’ve also referenced this post: Path Expected for Join! Nhibernate Error and can’t seem to apply the same logic to my query. My User object has a UserGroup collection. I understand that the query needs to reference en…
Opening a full web page
Is there a way of opening a full web page using Java, I have to check the time taken in opening full web page in a Java user end application, I have tried this code: but this gives me the source code of the url… that’s useless for me! as I need to record the time taken by a webpage