My first Java program

Ghost

Member
Apr 19, 2019
50
33
18
So, not too long ago I created my first program with Java.
It's a simple GUI window that shows the current prices of some cryptocurrencies & refreshes automatically.
I have plans to work on the next version, but I did have to stop temporarily.
There is currently some issues with the current version preventing people from running it unless they have a very specific version of Java. This is unfortunate, but I have not had time to compile the program again with the latest Java standard of having the JRE integrated to the program itself with modules.
I am in the process of learning how to use their newest changes, which are drastically more efficient and better for all of us... However it has been a setback due to the learning curve. I made this program a few weeks ago before starting to learn more core Java instead of developing this GUI crypto app.

I hope you all like the look of it :)

I had to learn the following to make this program... I learned on my own and it took a good bit, but was fun. I have now learned that Jframe & Jpanel, etc are all outdated so I am learning more modern ways of creating GUIs :)
  • Create window GUI (JFrame)
  • Add content to the GUI (JPanel)
  • Add labels & buttons to the panel (JButton / JLabel)
  • Fetch data from a URL (HttpURLConnection, BufferedReader, Inputstreams...)
  • Parse JSON from the URL (Gson)
  • Void / static / public / private meanings & usage
  • Create an ActionListener with actionPerformed() to trigger data refresh (replaced by the auto refresher later)
  • Refresh data from API every 30 seconds (TimerTask / Timer)
  • Update the GUI with new data (JLabel setText() )
  • Package / compile a Java program from command line (javac, jar -cvmf), which was hard due to dependency/packaging issues with Gson (Google's java parser)
  • Use Launch4j to compile the .jar file as an .exe to make it easy to share the program with everyone
Here is an image of the program with some code behind it :)
\

All in all, it took me about 10 hours total to learn everything & get Version 1 released. I will now be using my program to learn how to use NetBeans IDE. I think using an IDE will make life a lot easier, and it will be good for compiling / error catching. I'm sure my program has some possible errors, as I did not introduce anything for if the data API is unavailable or does not return the expected results. This may cause the program to crash or freeze. There's also a freeze that occurs if you do not have internet access. In Version 2 I hope to fix these things. From there I will be making a miniature panel that allows the user to input their own cryptocurrency identifiers (ex: Bitcoin's identifier is BTC) to track them. They can input the currency code or select from a list I will include by default. They will also be able to remove tracking for a specific currency by clicking a small X on the corner of the box when they hover over it (I think that's what I will do at least).

There is also a bug where if the crypto's prices get larger (more decimals), it pushes 'USDT' (Tether) on to the next line, which is hidden from view. The next version will auto adjust the elements so no element is ever hidden & the sizing remains the same.

I will also be updating the GUI to have a toolbar on the top that allows them to access these settings, etc. The next version will not have the red bar and will be a better looking toolbar.

If you are interested in using this, please note:
  • The public API I use only allows 100,000 API calls per month, for each IP Address
  • This means if you have this open on 2 computers at once on the same internet, the program will fail half way through the month
  • Unfortunately I do not have a way to resolve this currently
  • You should only open this program on one computer in your household/internet at a time to avoid the data rate limiting
  • The program auto refreshes every 30 seconds, allowing for around 89,000 requests per month
  • Version 2 will allow the user to choose how fast they can refresh, and show how many API calls they have remaining for the month
  • Version 2 will also submit data to my own server to provide historical crypto data to users of wuCrypto
  • This will allow users to view old crypto prices, even before they owned the software I created
  • This will also allow me to provide free price updates to users, even if they have used their 100,000 original requests - which allows users to receive updates faster because everyone is 'acting as one'... aka if User A requests the Bitcoin price, I can tell User B the new price even if User B has 0 requests left
You can download the file here:
https://wubur.com/cryptocurrency-development/wuCrypto.exe

The following page also has the same data as my software wuCrypto & can be refreshed manually:
https://wubur.com/cryptocurrency-development/

If you want to make sure it's safe, I encourage you to scan it on your own. Here is an online scanner results, proving it is safe:
https://www.virustotal.com/#/url/bd928d5936c1f06b3818afcc094cb959860b2eccf9d82ca9a7c58dcc0747c1a6/detection

I used Launch4j (unsigned) to generate the .exe from the Java .jar file, which may lead to some (about 1 out of 100) scans warning users because it's unsigned and an auto installer.

The only 'outgoing' request it makes is to fetch the cryptocurrency data, which is done here at an IP-address tracked public API (limiting each IP to 100,000 monthly requests):
https://min-api.cryptocompare.com/data/pricemulti?fsyms=BTC,ETH,LTC,XRP,TRX,USDT&tsyms=USD
 

TopSilver

Active Member
VIP
Mar 16, 2019
132
57
28
Interesting program @Ghost and also glad you threw some code at us so I could get a feel for what Java was like. I personally want to Learn Java over C++ sometimes as I haven't learned either yet. Been in the process of trying to grasp PHP but my next language will be Java and C++. I noticed you talked about the IDE Netbeans. You should also look into IntelliJ IDEA for a Java IDE. It's made by JetBrains and I have it myself even though I don't know Java yet. I mainly use their PHP version called phpstorm. Anyways Netbeans might get the job done but this one is highly advanced and has Java frameworks too with constant error checking. Regardless the program code has got me interested. It doesn't look all too hard to learn if you have any programming experience prior. The way I see it, once I learn PHP learning Java should be a lot easier. Just trying to start with what I'm used to and sort of work my way up. But great share the code looks really exciting.
 
  • Like
Reactions: Ghost

Ghost

Member
Apr 19, 2019
50
33
18
Interesting program @Ghost and also glad you threw some code at us so I could get a feel for what Java was like. I personally want to Learn Java over C++ sometimes as I haven't learned either yet. Been in the process of trying to grasp PHP but my next language will be Java and C++. I noticed you talked about the IDE Netbeans. You should also look into IntelliJ IDEA for a Java IDE. It's made by JetBrains and I have it myself even though I don't know Java yet. I mainly use their PHP version called phpstorm. Anyways Netbeans might get the job done but this one is highly advanced and has Java frameworks too with constant error checking. Regardless the program code has got me interested. It doesn't look all too hard to learn if you have any programming experience prior. The way I see it, once I learn PHP learning Java should be a lot easier. Just trying to start with what I'm used to and sort of work my way up. But great share the code looks really exciting.
Of course - I wanted to include some of the code in the post so that people could see it. The code you can see basically shows the end of one function that adds content to the window on the screen. The big block of code is querying the API to fetch the crypto data, then it reads the data line by line & adds it to 'totalText' which is JSON format. Then down below I have a function setValues to basically read the JSON & set all the individual variable values for each crypto symbol/coin. I used a library called GSON, from Google, to parse the JSON!

I definitely recommend Java over C++, but I should warn you that it is pretty complicated to get started.
I also recommend doing command line Java to begin with instead of doing GUI work - You can get started a LOT easier that way. You can also create bots and stuff that way to run without a visual interface.

As for an IDE, yeah - definitely use one. I did this all from scratch in Atom, without any sort of IDE. It was incredibly frustrating to debug, but I do think that it allowed me to learn things a lot faster. For PHP I use Atom as well, but I have PHP memorized to the point where I can write scripts in my head or on paper with pen/pencil, so it's not too problematic. You're exactly right about having prior programming experience making Java a lot easier. I knew JavaScript, PHP, and jQuery before doing this and that definitely helped me understand how general functions/methods work, classes, dependencies/libraries, debugging and even logic-specific things such as if-else, loops, and more.

GOod luck!
 
  • Like
Reactions: TopSilver