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

Discussion in 'Java' started by z.m_wu@att.net, Mar 16, 2008.

  1. Guest

    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
    , Mar 16, 2008
    #1
    1. Advertising

  2. Arne Vajhøj Guest

    wrote:
    > 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
    Arne Vajhøj, Mar 16, 2008
    #2
    1. Advertising

  3. Guest

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

    On Mar 15, 8:57 pm, Arne Vajhøj <> wrote:
    > 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
    , Mar 16, 2008
    #3
  4. Logan Shaw Guest

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

    wrote:
    > 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
    Logan Shaw, Mar 16, 2008
    #4
  5. Lew Guest

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

    Logan Shaw wrote:
    > wrote:
    >> 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.


    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.

    --
    Lew
    Lew, Mar 16, 2008
    #5
  6. Arne Vajhøj Guest

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

    wrote:
    > On Mar 15, 8:57 pm, Arne Vajhøj <> wrote:
    >> wrote:
    >>
    >> Java regex support groups. The Java code to use regex is different
    >> than Perl, but that is to be expected.


    > 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
    Arne Vajhøj, Mar 16, 2008
    #6
  7. Logan Shaw Guest

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

    Arne Vajhøj wrote:
    > wrote:
    >> On Mar 15, 8:57 pm, Arne Vajhøj <> wrote:
    >>> wrote:
    >>>
    >>> Java regex support groups. The Java code to use regex is different
    >>> than Perl, but that is to be expected.

    >
    >> 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.


    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
    Logan Shaw, Mar 17, 2008
    #7
  8. Arne Vajhøj Guest

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

    Logan Shaw wrote:
    > Arne Vajhøj wrote:
    >> wrote:
    >>> On Mar 15, 8:57 pm, Arne Vajhøj <> wrote:
    >>>> wrote:
    >>>> Java regex support groups. The Java code to use regex is different
    >>>> than Perl, but that is to be expected.

    >>
    >>> 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.

    >
    > 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
    Arne Vajhøj, Mar 17, 2008
    #8
  9. Guest

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

    On Mar 16, 9:14 pm, Arne Vajhøj <> wrote:
    >
    > 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
    , Mar 17, 2008
    #9
  10. Re: any LWP::UserAgent equivalent in java && a java regex question

    wrote:
    > On Mar 16, 9:14 pm, Arne Vajhøj <> wrote:
    >> 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.

    ....

    Have you looked at java.util.Properties?

    Patricia
    Patricia Shanahan, Mar 17, 2008
    #10
  11. Tim Smith Guest

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

    In article
    <>,
    wrote:
    > 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.




    --
    --Tim Smith
    Tim Smith, Mar 17, 2008
    #11
  12. Re: any LWP::UserAgent equivalent in java && a java regex question

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


    >> <answers involving JDBC, Derby etc>


    > 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

    --
    RGB
    RedGrittyBrick, Mar 17, 2008
    #12
  13. Guest

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

    On Mar 17, 6:09 am, RedGrittyBrick <>
    wrote:
    > wrote:
    >
    > >>> Is there any java equivalent of Perl hash/db files? I want to store
    > >>> a few pieces of data on the disk.
    > >> <answers involving JDBC, Derby etc>

    > > 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=542341http://en.wikipedia.org/wiki/XY_problem
    >
    > To store & retrieve application configuration settings see:http://java.sun.com/docs/books/tuto...se/6/docs/technotes/guides/preferences/design...
    >
    > --
    > RGB


    Ok. It seems that properties and preferences are almost what I need.

    Thanks for the replies.

    z.m.wu
    , Mar 17, 2008
    #13
  14. Arne Vajhøj Guest

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

    wrote:
    > On Mar 16, 9:14 pm, Arne Vajhøj <> wrote:
    >> 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.

    >
    > 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
    Arne Vajhøj, Mar 18, 2008
    #14
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. La Jesus
    Replies:
    9
    Views:
    1,298
    Gunnar Hjalmarsson
    Oct 27, 2003
  2. Chandra

    Problem with LWP::USERAGENT

    Chandra, Feb 25, 2004, in forum: Perl
    Replies:
    0
    Views:
    491
    Chandra
    Feb 25, 2004
  3. Vinay Gupta
    Replies:
    2
    Views:
    1,098
    Michael Schlenker
    Jul 27, 2004
  4. Playker
    Replies:
    0
    Views:
    499
    Playker
    Feb 24, 2005
  5. a

    LWP::UserAgent question

    a, Aug 14, 2006, in forum: Perl Misc
    Replies:
    39
    Views:
    341
    DJ Stunks
    Aug 15, 2006
Loading...

Share This Page