any LWP::UserAgent equivalent in java && a java regex question

Z

z.m_wu

Hi All

I have found Perl's LWP::UserAgent and related packages useful. Does
java have any thing
equivalent i.e. that won't make me do encoding when I want to do an
http POST? I am a newbie
to java. Also, is there anything like java CPAN ?

Also, in perl, if I do /some pattern (some other pattern)/ I get "some
other pattern" in $1. I found
out that () have different meanings in Java. The only to get $1 in
Java is to write more lines.

Thanks in advance

Z. M. Wu
 
A

Arne Vajhøj

I have found Perl's LWP::UserAgent and related packages useful. Does
java have any thing
equivalent i.e. that won't make me do encoding when I want to do an
http POST? I am a newbie
to java. Also, is there anything like java CPAN ?

I think Jakarta Commons HttpClient is what you want.
Also, in perl, if I do /some pattern (some other pattern)/ I get "some
other pattern" in $1. I found
out that () have different meanings in Java. The only to get $1 in
Java is to write more lines.

Java regex support groups. The Java code to use regex is different
than Perl, but that is to be expected.

Arne
 
Z

z.m_wu

(e-mail address removed) wrote:

Java regex support groups. The Java code to use regex is different
than Perl, but that is to be expected.

Arne

Thanks. I have figured it out.

Another question. Is there any java equivalent of Perl hash/db
files? I want
to store a few pieces of data on the disk.

z.m.wu
 
L

Logan Shaw

Another question. Is there any java equivalent of Perl hash/db
files? I want
to store a few pieces of data on the disk.

If you really want literal Berkeley DB, apparently there is a
Java port of it (maintained by Oracle, the same people who now
maintain the regular/original Berkeley DB):

http://www.oracle.com/technology/products/berkeley-db/je/index.html

I have never tried it out and don't know how mature it is, but
it might be worth a look.


More generally, I would say Berkeley DB is a good solution if
your goal is to manipulate a subset of a large amount of data
(and you don't want to or can't load it all into RAM), but it
probably isn't the best solution for everything. There are
other technologies out there for Java that assist you with
loading and storing data. For example, you can serialize objects
to/from XML. One of these technologies might allow you to store
a more convenient data structure that the key/value pairs that
Berkeley DB allows for. If you give more specifics about what
you're trying to accomplish, maybe somebody can recommend one.

- Logan
 
L

Lew

Logan said:
If you really want literal Berkeley DB, apparently there is a
Java port of it (maintained by Oracle, the same people who now
maintain the regular/original Berkeley DB):

http://www.oracle.com/technology/products/berkeley-db/je/index.html

I have never tried it out and don't know how mature it is, but
it might be worth a look.


More generally, I would say Berkeley DB is a good solution if
your goal is to manipulate a subset of a large amount of data
(and you don't want to or can't load it all into RAM), but it
probably isn't the best solution for everything. There are
other technologies out there for Java that assist you with
loading and storing data. For example, you can serialize objects
to/from XML. One of these technologies might allow you to store
a more convenient data structure that the key/value pairs that
Berkeley DB allows for. If you give more specifics about what
you're trying to accomplish, maybe somebody can recommend one.

The Derby database, a.k.a. the "Java DB", comes with Java 6 and above.
PostgreSQL www.postgresql.org is an excellent choice, also. These are full,
(mostly-)SQL-compliant DBMSes.

The java.util.Properties class directly supports name-value pair serialization
to either a simple "name=value" text file or to XML.

HashMap (and other Map implementations) can be serialized using
java.io.Serializable conventions or other mechanisms.
 
A

Arne Vajhøj

Another question. Is there any java equivalent of Perl hash/db
files? I want
to store a few pieces of data on the disk.

In Java you would typical use a database through the standard
JDBC interface.

Arne
 
L

Logan Shaw

Arne said:
In Java you would typical use a database through the standard
JDBC interface.

This is not quite (or at least usually is not) equivalent
functionality. With JDBC, you typically do not have control
over where the data files are written, but with Berkeley DB,
you do. (Of course, there are some relational databases
where you can create a new instance easily and you do have
control, but not in many cases.)

Whether the original poster needs that is an unknown, though.

- Logan
 
A

Arne Vajhøj

Logan said:
This is not quite (or at least usually is not) equivalent
functionality. With JDBC, you typically do not have control
over where the data files are written, but with Berkeley DB,
you do. (Of course, there are some relational databases
where you can create a new instance easily and you do have
control, but not in many cases.)

Whether the original poster needs that is an unknown, though.

There are plenty of databases where you can specify location
of files. All the embedded ones.

The JDBC API is much different from BDB (at least that is
my impression - I have not worked with BDB myself).

But the tradition in the Java world is to use JDBC and
not any special API's.

It is usually a bad practice to try and move 1:1 from one
language to another.

Coding Java in Java and Perl in Perl is better than Java in Perl
and Perl in Java.

Arne
 
Z

z.m_wu

There are plenty of databases where you can specify location
of files. All the embedded ones.

The JDBC API is much different from BDB (at least that is
my impression - I have not worked with BDB myself).

But the tradition in the Java world is to use JDBC and
not any special API's.

Hi

The program I am writing is a small desktop app which
will be distributed to users who most likely won't have
access to a sql server. My need is just a few
key value pairs stored on disk to store the state of
the program/data. A sql server seems an overkill for this purpose.

Are you saying I can somehow use jdbc api to use some files
on disk?

Thanks

z.m.wu
 
P

Patricia Shanahan

Hi

The program I am writing is a small desktop app which
will be distributed to users who most likely won't have
access to a sql server. My need is just a few
key value pairs stored on disk to store the state of
the program/data. A sql server seems an overkill for this purpose.
....

Have you looked at java.util.Properties?

Patricia
 
T

Tim Smith

Another question. Is there any java equivalent of Perl hash/db
files? I want
to store a few pieces of data on the disk.

Google for SQLite. There are Java interfaces available for it.
 
R

RedGrittyBrick

The program I am writing is a small desktop app which will be
distributed to users who most likely won't have access to a sql
server. My need is just a few key value pairs stored on disk to
store the state of the program/data. A sql server seems an overkill
for this purpose.

Are you saying I can somehow use jdbc api to use some files on disk?

This is an example of an XY problem:
http://www.perlmonks.org/index.pl?node_id=542341
http://en.wikipedia.org/wiki/XY_problem


To store & retrieve application configuration settings see:
http://java.sun.com/docs/books/tutorial/essential/environment/config.html
http://java.sun.com/docs/books/tutorial/essential/environment/properties.html
http://java.sun.com/javase/6/docs/technotes/guides/preferences/designfaq.html
 
A

Arne Vajhøj

The program I am writing is a small desktop app which
will be distributed to users who most likely won't have
access to a sql server. My need is just a few
key value pairs stored on disk to store the state of
the program/data. A sql server seems an overkill for this purpose.

Are you saying I can somehow use jdbc api to use some files
on disk?

I believe that for what what you in other languages may
use BDB/ISAM files for you would use a database (very likely
embedded so that there are no server process) and JDBC in
Java.

You can use flat files. Properties files, XML files etc..

XML serializing/deserializing could be an option for you.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top