• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Private Constructor

 
Ranch Hand
Posts: 89
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Should an entry-level developer be concerned with Reflection API?

Thanks,.
 
Sheriff
Posts: 17323
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, you should be concerned if you see it being used in anything other than low-level library/framework code. Even as an experienced developer, I don't have to deal with the Reflection API. It's something that I leave to framework and tools developers.
 
Royale Summers
Ranch Hand
Posts: 89
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Junilu -

Thanks.  Based on your response, I should at least be aware of its existence...again, thanks!
 
Bartender
Posts: 1899
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with the other postings here, but Reflection can be useful. I've used it to dynamically invoke a method and Reflection used to be used (still is in a lot of code) to load JDBC drivers (forName() method).

Check out this link: http://tutorials.jenkov.com/java-reflection/methods.html

HTH

-- mike
 
Bartender
Posts: 2908
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Even forName() is no longer recommended, have a look at this: https://docs.oracle.com/cd/E11882_01/appdev.112/e13995/oracle/jdbc/OracleDriver.html
Yes, as a beginner, I would not suggest diving into reflection yet.

OP, I didn't understand the title of your post, can you elaborate ?
 
Royale Summers
Ranch Hand
Posts: 89
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Salvin -

Sure thing.  The title came from what I read about the topic:

What is Java Reflection API? Why it’s so important to have?

Java Reflection API provides the ability to inspect and modify the runtime behavior of java application. We can inspect a java class, interface, enum and get their methods and field details. Reflection API is an advanced topic and we should avoid it in normal programming. Reflection API usage can break the design pattern such as Singleton pattern by invoking the private constructor i.e violating the rules of access modifiers.

Even though we don’t use Reflection API in normal programming, it’s very important to have. We can’t have any frameworks such as Spring, Hibernate or servers such as Tomcat, JBoss without Reflection API. They invoke the appropriate methods and instantiate classes through reflection API and use it a lot for other processing.

Read Java Reflection Tutorial to get in-depth knowledge of reflection api. https://www.journaldev.com/1789/java-reflection-example-tutorial

https://www.journaldev.com/2366/core-java-interview-questions-and-answers?unapproved=48819&moderation-hash=c820e5db115e70af61caad9bb09bafca#composition
 
Carey Brown
Saloon Keeper
Posts: 9735
80
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Royale Summers wrote:Should an entry-level developer be concerned with Reflection API?


Even though we don’t use Reflection API in normal programming...

 
Royale Summers
Ranch Hand
Posts: 89
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Carey -

Thanks.  I read that part. The  Analyst in me decided to get a second  opinion....as you are aware humans make mistakes and technology is constantly changing.

For example,  his site stated that Annotations arrived on the scene in Javs 5 and his link for additional details said  1.5.
 
Carey Brown
Saloon Keeper
Posts: 9735
80
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've been using a 3rd party library (JGoodies) for years that has a "Windows Look and Feel" for Swing that was very good. Unfortunately when Java-12 (I think) came out I started getting warnings about some reflection that the library was using and that it would be forbidden in the future. I had to abandon this LaF to make the message go away which was sad because it was far superior to Swing's standard look and feel. The take away is that restrictions on reflection are getting tighter and something that works today may break tomorrow.
 
Carey Brown
Saloon Keeper
Posts: 9735
80
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ten+ years ago I was working on something that required massive amounts of directory searching and performance was becoming a major issue. One bottleneck I found was in the retrieval of a couple of File attributes, like: exists, isDirectory, isHidden. My code was calling the File methods for each of these in turn and the system overhead was adding up. So I looked at the source code for File and found out the file system read all of these attributes in one shot as "binary attributes" but would only let you access them one at a time, and in doing so, reloading them. So I made a File wrapper class that used reflection to directly access all of the binary attributes in one shot and cache them. This almost doubled the speed of my code.

Later, I felt very uncomfortable using reflection for this because I had no control over the implementation of java.io.FileSystem. I also don't know if nio has a new wrinkle on accessing these attributes that is more efficient or whether the underlying FileSystem class is really the culprit. -- So, who gets to debug it when it breaks?
 
Royale Summers
Ranch Hand
Posts: 89
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Carey -

That story reminded me of what I learned today about "favor composition over inheritance."

Good stories...I enjoy reading them as they propel my understanding.
 
Carey Brown
Saloon Keeper
Posts: 9735
80
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:I've been using a 3rd party library (JGoodies) for years that has a "Windows Look and Feel" for Swing that was very good. Unfortunately when Java-12 (I think) came out I started getting warnings about some reflection that the library was using and that it would be forbidden in the future. I had to abandon this LaF to make the message go away which was sad because it was far superior to Swing's standard look and feel. The take away is that restrictions on reflection are getting tighter and something that works today may break tomorrow.


This example makes me uneasy because one of the foundations of new Java releases is backwards compatibility. The cracks are beginning to show.
 
You know it is dark times when the trees riot. I think this tiny ad is their leader:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic