?
Solved

PropertyUtils  java

Posted on 2014-02-26
4
Medium Priority
?
348 Views
Last Modified: 2014-04-11
Hi,

I am going through below link on property utils

http://commons.apache.org/proper/commons-beanutils/apidocs/org/apache/commons/beanutils/PropertyUtils.html#getPropertyDescriptor(java.lang.Object


What for they used and why and when. How they are related to collections.
please advise
Any links resources ideas highly appreciated. Thanks in advance
0
Comment
Question by:gudii9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 21

Accepted Solution

by:
Amitkumar Panchal earned 2000 total points
ID: 39891467
PropertyUtils is written using java reflection api and provides you ability to modify properties of Java object at runtime. Hence, it make you to write highly configurable code where you can provide name of bean properties and there values from configuration rather than coded in Java program.

For more details : http://javarevisited.blogspot.com/2012/04/java-propertyutils-example-getting-and.html

Like propertyutils, Spring is also written on top of reflection api of java.
0
 
LVL 7

Author Comment

by:gudii9
ID: 39891869
PropertyUtils is written using java reflection api and provides you ability to modify properties of Java object at runtime.

In the link
 http://javarevisited.blogspot.com/2012/04/java-propertyutils-example-getting-and.html
it was mentioned as below
Remember we don’t know anything about Object on compile time. On runtime Object is provided to program along with name of property to retrieve or modify:

Read more: http://javarevisited.blogspot.com/2012/04/java-propertyutils-example-getting-and.html#ixzz2uX3g47Zr




Why we do not know anything about object at compile time but  runtime Object is provided to program along with name of property to retrieve or modify.

I am not clear on those statements.
I ran above program in the javarevisited link, I got output as below
PropertyUtils Example property value: blue

what is the meaning of output

I see we are setting and getting colr from PropertyUtils
   
  //here color and blue strings can come from variety or sources
        //e.g. configuration files, database, any upstream system or via HTTP Request
        PropertyUtils.setProperty(flexiColor, "color", "blue");
        String value = (String) PropertyUtils.getProperty(flexiColor, "color");
        System.out.println("PropertyUtils Example property value: " + value);

How is it different from regular getter and setter from a bean.

 PropertyUtils.setProperty(flexiColor, "color", "blue");

Where is this setter defined.

please advise
0
 
LVL 7

Author Comment

by:gudii9
ID: 39893860
I see code as below

    PropertyUtils.getPropertyDescriptor(obj, fieldName).getWriteMethod().invoke(obj, list);

What is the meaning of above code while parsing a text document which has not only primitives but also list kind of objects before sending to one other system.
please advise
0
 
LVL 7

Author Comment

by:gudii9
ID: 39954568
How the reflection on class, method, field are different.
Any practical example to understand this reflection concept end to end better with set up on eclipse. please advise
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses
Course of the Month8 days, 14 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question