Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Java My first Java program

Ghost

Platinum Coder
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 :)
3qEfmp9.png
\

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/bd...959860b2eccf9d82ca9a7c58dcc0747c1a6/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
 
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.
 
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!
 
Any specific reason that you are going to use Netbeans? I suggest IntelliJ IDEA it's the best all-around Java IDE these days.

IntelliJ: https://www.jetbrains.com/idea/

IntelliJ has a nice plugin also to convert Java code to Kotlin (which is a language created by Jetbrains and gaining a lot popularity.) :cool: Why not learn some Kotlin too while at it!

JavaFX is also great - is styled with CSS and has incredibly good builder (scene builder) and uses FXML instead of java code it also has two way databinding and cool UI libraries ;)
 
Last edited:
Awesome, thanks for sharing!

Would you be interested in making the source available on GitHub?

I've been working in Java lately, but on a project that's infrastructure is well established. I'd be interested to see how you set up your project ... I'm currently looking into the tools available for Java that's supposed to make that kind of thing easier to get off the ground (gradle, maven, spring).

I haven't yet had a chance to work with the latest Java releases. Planning to get stuck into Java 11.

I think IntelliJ is where it's at. The last time I tried to use something else (eclipse), it wasn't as free flowing as what IntelliJ will let you do. I haven't really had a chance to try netbeans.
 
Any specific reason that you are going to use Netbeans? I suggest IntelliJ IDEA it's the best all-around Java IDE these days.
IntelliJ: https://www.jetbrains.com/idea/
IntelliJ has a nice plugin also to convert Java code to Kotlin (which is a language created by Jetbrains and gaining a lot popularity.) :cool: Why not learn some Kotlin too while at it!
JavaFX is also great - is styled with CSS and has incredibly good builder (scene builder) and uses FXML instead of java code it also has two way databinding and cool UI libraries ;)
I never really decided on an IDE for Java. I put my Java learning on hold for a bit to learn Python instead. I got annoyed with Java's JRE requirement to run on other computers and then tried to upgrade to the newest Java which packages itself into the final project so that it can run on any computer... but I ran into so much trouble that I took a break from the language and didn't end up going back to it - YET.

Awesome, thanks for sharing!
Would you be interested in making the source available on GitHub?
I've been working in Java lately, but on a project that's infrastructure is well established. I'd be interested to see how you set up your project ... I'm currently looking into the tools available for Java that's supposed to make that kind of thing easier to get off the ground (gradle, maven, spring).
I haven't yet had a chance to work with the latest Java releases. Planning to get stuck into Java 11.
I think IntelliJ is where it's at. The last time I tried to use something else (eclipse), it wasn't as free flowing as what IntelliJ will let you do. I haven't really had a chance to try netbeans.
I am definitely willing to consider sharing the source code, but I would want to relook at this project & upgrade it a bit before doing so.
I never jumped into the things like Maven for development, but it would be incredible to learn. The newest Java is very cool, but I had trouble figuring out their new way of doing things and packaging final products.
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom