Java

98K

Solutions

32K

Contributors

Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.

Share tech news, updates, or what's on your mind.

Sign up to Post

#TodayILearned that #OData presents a problem for #XSLT. The #JSON element named "@odata.context" can't be translated into an #XML element with the same name, using XSLT 2 or 3 as provided in #Java by #Saxonica.
 
The problem is that XSLT uses that @ in XPATH statements to match element attributes, and in other places within curly brackets, like {@attribute}, to copy that attribute's content into the output.
 
The solution is to differentiate between nodes/attributes that do, and ones that don't contain an @-sign,  and either replace() or translate() that into something else.
 
In my case, I use fx:json-to-xml() from XSLT3, implemented by Saxonica, to transform received JSON-formatted data into raw XML. This leads to a map element that contains elements array, boolean, map, null, number, and string. The JSON element names become the XML elelements' "@key" attribute.
 
A 2nd XSL transformation produces the domain-specific XML-format. As stated above, we must take heed with producing the "@odata.context" element. This can occur, a.f.a.i.k., in either a null element or a string element. So, we differ between those with and without an "@" in the key attribute:
 
Without:
<xsl:template match="xf:string[@key][not(contains(@key, '@'))]">
<xsl:element name="{@key}">
<xsl:value-of select="text()" />
</xsl:element>
</xsl:template>
 
With:
<xsl:template match="xf:string[@key][contains(@key, '@')]">
<xsl:variable name="newName"><xsl:value-of select="translate(@key, '@', '')" …
0
 

Author Comment

by:A.E. Veltstra
Hi, Andrew Leniart. Funny, we have the same first name.
 
Thank you for your concern. I did search before I found a way to solve my problem and published it. As far as the search could tell me, I'm literally the first person to encounter and solve this problem. Hence the publication.
0
 
LVL 11

Expert Comment

by:Andrew Leniart
My apologies Andrew, I didn't read your entire post carefully enough and took it to be a problem you were still trying to solve. I think the hash tag # at the start threw me off! These new fandangled ways you younger generation have of talking can get confusing for oldies like me! lol..

Cheers :)
1
Industry Leaders: We Want Your Opinion!
Industry Leaders: 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!

#TodayILearned a #gotcha with #Predicate in #Java. You can learn, too!
 
Here's 1 way to write a Predicate:
 
static Predicate<String> isEmpty() {
    return p -> 0 == p.length();
}

And here's another way:
 
static Predicate<String> isEmpty = (p) -> {
    return 0 == p.length();
}
 
Erm. What's the difference?
 
Well. The first is a method that generates a function, and you call it like this:
 
boolean test = isEmpty().test("Hello!");
 
Or, from a stream in a method in a class named World:

.filter(World::isEmpty())
 
The second is a field with a pregenerated function, and you call it like this:
 
boolean test = isEmpty.test("Hello!");
 
Or, from a stream in a method in a class named World:

.filter(World.isEmpty)
 
Notice how the method-based Predicate still has to generate a function, and thus has to be called with parentheses.
 
The field-based predicate already generated its function by the time it gets called, and because it's a field, no parentheses are used for accessing it.
 
Why Predicates at all, rather than a simple boolean-returning method?
 
Beats the heck out of me. 
2
Apple is no longer just for the tech-savvy millennial and professional crowd. Check out today's product release, where developers as young as 7 and as old as 84 are releasing new apps to the App Store. https://www.apple.com/apple-events/june-2017/
6
 
LVL 14

Expert Comment

by:Joseph Hornsey
Wait... Apple users are "tech-savvy"?  Huh.
3
Is Java a terrible first programming language to learn? Do you agree with Stanford switching their intro course to JavaScript? Or would you have picked something else?

https://thenextweb.com/dd/2017/04/24/universities-finally-realize-java-bad-introductory-programming-language/#.tnw_AFXiESVy
2
 
LVL 10

Expert Comment

by:Jeffrey Dake
I definitely think there is something better to start with than Java, but not sure JavaScript is the answer.
1
 
LVL 6

Author Comment

by:Brian Matis
I imagine the appeal of JavaScript is how you can run it in a browser and don't need to worry about dev environment setup or learning a command line to get started.

What language would you choose, Jeff?
0
When I went to school to get my degree in SE I had the importance of Java Docs beaten into me on a daily basis. Now that I am in industry, I find that Java Docs are the last place I look - instead opting for Q&A sites or google searches for blog articles due to the specificity of the problems I come across.

I was never encouraged to do this sort of research in practice, in fact, it was often discouraged. There definitely seems to be a disconnect in school professors and their outdated methods and actual industry practices. Maybe in schools that are research oriented this is better since engineering professors are actively working in their field, but at my public university I had professors who were perplexed by syntactic sugar that is now common place such as the
for ( x : y )

Open in new window

loop.
5
 
LVL 9

Author Comment

by:James Bilous
I had an interesting situation where I earned my BS and MS in computer science from the same university in a blended program ( I earned both degrees at the same time ). My school prided itself in project based learning, in fact the motto of the school was "Learn by Doing". I definitely got a great education because of this philosophy and most of the professors were great, but the ones that taught fundamentals (read 101, 102, 103 programming courses) were absolutely horrific.

By the time I hit graduate level coursework the professors were, again, fantastic. These were all instructors who were very active in industry and research and many had side companies they worked on. I think the critical missing piece from the earlier instructors was their lack of participation in the real world. Of course, all of these professors were tenured, so that should tell you something.
3
 

Expert Comment

by:Daniella Barion
I believe that when we study the theories, we can develop better and also discuss and bring new contributions.
2
Used Jsoup for the first time this week on trying to load in an html page and parse it.  It was really handy to use for parsing the dom.  Really cool to be able to use more CSS like selectors to do what I needed.

https://jsoup.org/
5
 
LVL 6

Expert Comment

by:Brian Matis
@kyle: I love the idea of being able to share it more! But I don't understand the "convert to article" idea... Isn't this a little short for an article?
0
 
LVL 16

Expert Comment

by:Kyle Santos
It is if you're following Jeff.
0
Ever write code that you look at, and think "no language should let me do this".


private void createURLButtonAction() throws Exception
      {
            m_view.m_loadURLButton.setOnAction(e -> {
                  try{
                        loadURL(m_view.m_urlField.getText());
                  }
                  catch (Exception exception)
                  {
                        
                  }
            });
      }
0
 
LVL 16

Expert Comment

by:Kyle Santos
*plane flies over my head*
2
 
LVL 9

Expert Comment

by:James Bilous
*no framework
Don't blame the lambdas
0
Do you think endorsements will be well moderated?
2
 
LVL 16

Expert Comment

by:Kyle Santos
*downvote*

:3
0
 
LVL 6

Expert Comment

by:Craig Kehler
Sure, but in this case I can just walk out my office door and "moderate" the user personally :P
2

Java

98K

Solutions

32K

Contributors

Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.