Win a copy of Rust Web Development this week in the Other Languages forum!

Shawn Franks

Ranch Hand
+ Follow
since May 18, 2010
Cows and Likes
Cows
Total received
1
In last 30 days
0
Total given
0
Likes
Total received
2
Received in last 30 days
0
Total given
5
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Shawn Franks

That is surprising to hear, in my opinion scala takes a fraction of code size as java, unless the developer isn't using variations.

The list is to long to say but Scala has a lot of simpler functionality than java has which should make coding much easier, smaller, and have better error handeling.

But everyone has their own opinions.

There is a link in there to convert Java to Scala.  I'd suggest throwing your java codebase in there and converting to Scala and see if the code base is really smaller in Java.  While the conversion isn't the best formatted variants you should still see at least a 1/4 size reduction in the code.


You can see a short pro con list here for spark usage, but it's more why it's better for spark.

https://coderanch.com/t/695290/languages/Scala-Java-developers-scala-big#3263783
3 years ago
Btw check out http://javatoscala.com.

Also for things like date a d long I'll use aliases.

import java.util.{Date => jDate}

This way it's I know what's java and scala.  That's just me though.
3 years ago
No, but you in most cases you wouldn't want to unless something needs a java type specifically.  For example, lists , longs, dates, some times you need java.  In a lot of cases you can add .toJava or toScala to convert from one to another.
3 years ago
There is an online one made by MIT already if interested.

http://javatoscala.com
3 years ago
I don't think a book is worth your time if your already a good java programmer, you just need to pick up the variances.

There is also an online java - scala converter.  You can throw in some of your code and see what it transforms to in scala to get a picture of how you would write it.
3 years ago
If you know Java it should be easy to pick up, just will take some time to learn the does and fonts as well as the variances.   You are not supposed to use null and that can be difficult to adapt to especially when needing to declare null variables, but you should be able to code a full project in less than a month just by looking at code examples online.
3 years ago
Other than knowing java already, not really.  Unlike python or groovy, Scala and Java are both strict types.

Benefits to using scala:

You do not need to declare types for variables, but you might want to for practical reasons.

Spark was built using scala, so you have more libraries and full access to spark libraries you won't have in java.

It takes less code than it would in Java.

Simpler more functional coding.

Import aliases and the ability to import entire classes as locally defined.  Sort of like python.

Cons to using scala:

You are basically learning a new language even know it is based off java.

Some things can be very frustrating that should be simple.

There are many formats for writing scala, it can make it difficult to read code from others if you do not know all the variences.

For example you don't a user could write abc.>6 where the . Can be confusing.   There are more complex variations too which can be difficult.



These are just my personal opinions.  I've gone from Java > Groovy > Python > Scala.

Groovy being a favorite because it is extremely flexible and allows the least code, but has overhead.

Scala/Python are my next favorites.

Scala I really hate the strict types it makes it difficult for writing UDF. While scala has an EitherOr type spark doesn't support the type even know you return StringType for example.

Groovy doesn't care what type you return, it will find the best match if you don't declare.

Imo iterating dynamic json is impossible in scala as well.  In groovy or python you don't need to know the types of key names but in scala you need to know.  There are some libraries but none are great.


Overall I'd say go to Scala.

Python is not yet supported with newer Kafka libraries, and has less support than java, which has less support than Scala.
3 years ago

Darryl Burke wrote:

edit But really, I don't see why reflection should be needed at all.



Do you know a better option for dynamically creating a menu when the menuitems are always changing and there is no known sub menu set? I am open to suggestions. I was using reflection to avoid hundereds of if statements.
8 years ago

Darryl Burke wrote:I'm confused as to what exactly you are trying to do. Field#getType() returns Class and can never return a JMenu. But you evidently know that.

Also, in Java you cannot 'get the actual object' -- you get references (or primitives, of course).

Can you post a small compilable example showing a class on which you might want to 'dynamically create a context menu' and tell us what should be in that context menu?



I already gave examples above. But basically what i need to do is be able to somehow get the JMenu object and use the add() method on it. I know how to set its value but is there any way to access its methods?
The menu options are being pulled form a live database so there could be up to a 1000 different variations of the menu which is why mapping is out of the question. Also the menus need to change on a daily basis if not more.
8 years ago

Darryl Burke wrote:You can get the value of the Field with f.get(this) -- is that what you were looking for?



No i am looking to get the actual object for example:

JMenu mymenu = f.getType()

Obviously my example is not correct but it is an idea of what im trying to do. I need the existing instance though not a new instance.
8 years ago
I am looking to dynamically create a context menu without using any mapping as the values will always be random.
The issue I am having is setting submenu groups.
I have decided to go with Java reflection for what I am looking to accomplish, but the issue I am having is I cannot seem to access the Current Object without knowing the actual Object.
The problem is having to know the object makes it loose its dynamic ability. From what I can see the only options end up being new instance or knowing the name. Does anyone know a work around to this?

Any Help would be greatly appreciated. Suggestions advising not to do it this way or use mapping ect are not an option. The menu has to be 100% dynamic without 100 if/else statements.

8 years ago
Having an issue and cannot seem to find the resolution. I was unable to find a method for copying a directory recursively to another ftp server or to another folder on the same server.
I have thrown together the following code to do so and it works fine if you create only the directories and not transfer any files.

If you transfer files the InputStream becomes NULL after the first file transfers and kills the program. I have had it check to make sure the FTP connection is still love and even know it is I always result in the same issue.

You can see from the following Output that the Stream always transfers one file successfully.
Under the output is the code I am using.

Any help would be appreciated or a better method, but it has to be able to be done using only Jakarta Libraries and java.io





06-26 21:53:25.049: INFO/System.out(1152): Creating Directoy>>>>test/
06-26 21:53:25.139: INFO/System.out(1152): Directory Created>>>>test/
06-26 21:53:25.619: INFO/System.out(1152): Sending Src and Dst>>>>test/.>>>>>>>test/.
06-26 21:53:25.619: INFO/System.out(1152): Omitting>>>test/. <<<
06-26 21:53:25.619: INFO/System.out(1152): Finished Sending Src and Dst>>>>test/.>>>>>>>test/.
06-26 21:53:25.619: INFO/System.out(1152): Sending Src and Dst>>>>test/..>>>>>>>test/..
06-26 21:53:25.619: INFO/System.out(1152): Omitting>>>test/.. <<<
06-26 21:53:25.619: INFO/System.out(1152): Finished Sending Src and Dst>>>>test/..>>>>>>>test/..
06-26 21:53:25.619: INFO/System.out(1152): Sending Src and Dst>>>>test/ArtistSetList.php>>>>>>>test/ArtistSetList.php
06-26 21:53:25.619: INFO/System.out(1152): Begin Input Output>>>>test/ArtistSetList.php>>>>>>>test/ArtistSetList.php
06-26 21:53:26.339: INFO/System.out(1152): Completed Input Output>>>>test/ArtistSetList.php>>>>>>>test/ArtistSetList.php

06-26 21:53:26.339: INFO/System.out(1152): Finished Sending Src and Dst>>>>test/ArtistSetList.php>>>>>>>test/ArtistSetList.php
06-26 21:53:26.339: INFO/System.out(1152): Sending Src and Dst>>>>test/BandSelection.php>>>>>>>test/BandSelection.php
06-26 21:53:26.339: INFO/System.out(1152): Begin Input Output>>>>test/BandSelection.php>>>>>>>test/BandSelection.php
06-26 21:53:26.439: INFO/System.out(1152): InputStream is Null

06-26 21:53:26.439: INFO/System.out(1152): Finished Sending Src and Dst>>>>test/BandSelection.php>>>>>>>test/BandSelection.php
06-26 21:53:26.439: INFO/System.out(1152): Sending Src and Dst>>>>test/Copy of check2.php>>>>>>>test/Copy of check2.php
06-26 21:53:26.439: INFO/System.out(1152): Begin Input Output>>>>test/Copy of check2.php>>>>>>>test/Copy of check2.php
06-26 21:53:26.624: INFO/System.out(1152): InputStream is Null

06-26 21:53:26.624: INFO/System.out(1152): Finished Sending Src and Dst>>>>test/Copy of check2.php>>>>>>>test/Copy of check2.php
06-26 21:53:26.624: INFO/System.out(1152): Sending Src and Dst>>>>test/check.php>>>>>>>test/check.php
06-26 21:53:26.624: INFO/System.out(1152): Begin Input Output>>>>test/check.php>>>>>>>test/check.php
06-26 21:53:26.750: INFO/System.out(1152): InputStream is Null

06-26 21:53:26.750: INFO/System.out(1152): Finished Sending Src and Dst>>>>test/check.php>>>>>>>test/check.php
06-26 21:53:26.750: INFO/System.out(1152): Sending Src and Dst>>>>test/check2.php>>>>>>>test/check2.php
06-26 21:53:26.750: INFO/System.out(1152): Begin Input Output>>>>test/check2.php>>>>>>>test/check2.php
06-26 21:53:26.930: INFO/System.out(1152): InputStream is Null

06-26 21:53:26.930: INFO/System.out(1152): Finished Sending Src and Dst>>>>test/check2.php>>>>>>>test/check2.php
06-26 21:53:26.930: INFO/System.out(1152): Sending Src and Dst>>>>test/crawler.php>>>>>>>test/crawler.php
06-26 21:53:26.930: INFO/System.out(1152): Begin Input Output>>>>test/crawler.php>>>>>>>test/crawler.php
06-26 21:53:27.069: INFO/System.out(1152): InputStream is Null

06-26 21:53:27.069: INFO/System.out(1152): Finished Sending Src and Dst>>>>test/crawler.php>>>>>>>test/crawler.php








11 years ago
Would string string map work?
11 years ago
I know how to dump the contents that's not the issue. I need to structure it
11 years ago
I understand that much but my problem is I don't understand how to do the dynamic part of the tree. For instance if I mae a tree as treemap<string, string> abc = new treemap<string,string> and add the first directores and sub directories how do I add the next set because the tree is set for string string
11 years ago