r/javahelp • • Oct 04 '20

Codeless Help me choose a framework for a pet project

16 Upvotes

So before starting:

  1. I want to learn a new (human) language which has been troubling me for some time.

  2. I know how to program.

  3. I would like to refresh my Java knowledge (As I am not well versed in all the framework ecosystem available as for 2020).

So I thought it would be nice to program the grammar rules of this (human) language, which will help me understanding how they work and how to use them. Then I realized it would be nice to program it and offer them through an API so I can later on use them from some other project, which is a fantastic opportunity to use Java (Which I cannot do at work) and learn some framework (Spring maybe?).

Which framework or technology should I choose for this project that is interesting and will be useful for my career development and would fit my plan? Which Java version and flavour (Maybe Corretto or OpenJDK) should I jump in? Last time I wrote something in this programming language Java8 was all the rage, so...


r/javahelp • • Sep 19 '20

Remove a List of items from a List?

16 Upvotes

Let's say you have

OrderA { int id; ..... }

OrderB { int id; ..... }

(orderA & orderB are different types)

List<OrderA> ordersA... List<OrderB> ordersB...

Is it possible to take out ordersB from ordersA where the id's match in an elegant way with streams? Something like:

ordersA.stream().filter(...some magic...).collect(...


r/javahelp • • Sep 13 '20

Homework I'm trying to create java program to calculate compound interest, what is my errors ?

16 Upvotes

I think the problem was about double and int but don't know how to fix it.

https://i.stack.imgur.com/3rEpC.png


r/javahelp • • Jul 14 '20

Creating a webhook in springboot?

16 Upvotes

I need to create a webhook that allows me to send a gzip link to another server, but the term webhook confuses me, can someone help me?


r/javahelp • • Jun 14 '20

Why is it so difficult to find OpenJDK 12 Packages on Linux?

16 Upvotes

I'm currently trying to setup a linux (ubuntu) environment for our software which requires JDK 12 (don't ask...). I was hoping I could just simply use apt-get to install 12, but for some reason it seems like I cannot find any hosted packages anywhere, even on other repositories. I end up having to download a tar onto my machine and install it "manually". It's like all packages disappeared. Is there a specific reason for that?


r/javahelp • • May 15 '20

how reference variables are passed as method arguments in Java

16 Upvotes

Hello, I am struggling to understand what this question is asking for, I know in C++ for pass by reference the address of the variable is passed and altered before returning unlike pass-by value(correct me if Im wrong) but in java I thought all values were automatically pass by reference? struggling to make sense of the question so any help at all will be greatly appreciated:)

Explain the difference between how pass-by-reference operates in C++ and how reference variables are passed as method arguments in Java. A good answer will include a simple example of each


r/javahelp • • Apr 21 '20

Basic algorithm

16 Upvotes

I'm actually reading Java Software Solutions - Foundation of Program Design from Lewis & Loftus for the school and on the polymorphism chapter it shows selection sort, insertion sort, linear search, binary search and comparing search.

I really liked those little part of code and explanation, and I was wondering if someone know a good website or a good book with pseudo-code of basics algorithm? If it is with code it is okay, but I think it will be more easier to learn with pseudo-code that I can translate in Java by my own and than use it for different situation... If it have both, pseudo-code and Java code it's even better!

Thank you very much in advance !


r/javahelp • • Nov 28 '19

Math.Random keeps generating the same Value

16 Upvotes

I'm generating a 12 digit number for a Credit card. it must be 12 digits but random. have this line for code here :

debitCardNumber = (int) (Math.random() * Math.pow(10,12));
But, it keeps generating this value over and over: 2147483647.

In addition its 10 digits and not 12!


r/javahelp • • Oct 13 '19

Homework How to format a String into rows and columns using a single JOptionPane.showMessageDialog window?

16 Upvotes

Hello! I am learning Java at university and am having trouble with formatting the output in the way that my lecturer wants. In the question below, I have no problems with parts 1 and 2 but am completely stuck on how I should get my output into 5 columns using JOptionPane.showMessageDialog (here is a link to how he wants it to look).

Question:

  1. Write a program that will calculate and output multiples of a particular value up to a particular limit.

  2. Your program must firstly ask the user to enter a positive integer value followed by an upper limit (in separate input dialog boxes).

  3. It should be noted that the format of your output must correspond exactly to the format of the output of mine (note that the multiples appear in 5 columns).

My lecturer suggested making a new variable 'output', setting it to an empty string, and then putting my output from the for loop into this variable. I have tried using ...

  • "\n"

  • "\n\t\t\t"

  • " " + "\t\t\t" + " " + "\t\t\t" + "\n" //etc, etc

... to no avail. We must use a for loop for this exercise. Could anyone offer me any suggestions? Thank you.

import javax.swing.JOptionPane;
public class Exercise3
{
    public static void main( String[] args )
    {
        String output = "";
        String posInt = JOptionPane.showInputDialog( "Please enter a positive whole number:" );
        int pos = Integer.parseInt( posInt );
    
        String upperLim = JOptionPane.showInputDialog( "Please enter an upper limit:" );
        int uLim = Integer.parseInt( upperLim );
        
        for( int i = pos; i <= uLim; i += pos )
        {
            output += i;
        }

        JOptionPane.showMessageDialog( null, "The multiples of " + pos + " between " + pos + " and " + uLim + " are: " + output );
    }
}

r/javahelp • • Jul 17 '19

Looking for good tutorials/online classes for UI and software design principles

16 Upvotes

Hi javahelp,

I'm a current student working on a side project (as the necessity for them in this job market seems growingly apparent), and I've just recently finished working on most of the primary functions, but it's still only a command-line interface. I want to start working on developing a solid user interface (and then ultimately add more functions) but I keep finding myself overwhelmed with all of the possible UI frameworks and how to organize what I imagine will be a rapidly expanding source code in a way that won't hinder me in the future.

I'm having a lot of trouble getting started with the actual coding for this stage of the project because I don't want to start making something that will be very difficult to manage and add features later on. A lot of advice I've read was to just "start coding and focus on pushing a prototype and worry about that stuff later", which I think is decent advice, but I want least have a good template to follow or something along those lines.

I'm not a super experienced programmer, but I can solve most isolated programming problems and 'fill in' the functions from the assignments I get in class. What I'm finding though is that my classes aren't teaching me how to organize functions or design a solid program, as all the assignments I'm doing right now have structures already laid out for me. I'm looking for somewhere where I can learn to properly *design* a program's structure on a larger scale.

If anyone has any suggestions, please let me know.

PS. The software I'm working on is only going to be a local .exe program. I figured that's a good place to start.


r/javahelp • • Jul 07 '19

My very first Java / Raspberry Pi project is almost complete!

Thumbnail
self.learnjava
16 Upvotes

r/javahelp • • Jun 26 '19

Want to learn streams and collections, help!

16 Upvotes

what is the Best way to learn and implement streams in Java?


r/javahelp • • Jun 14 '19

How can I practically enforce my java knowledge?

16 Upvotes

I've been reading about Java and going through this book for a while and I just realised that I can't learn everything and then finally start to code. I was just looking for some way to reinforce what I've learned so far and try something very practical. What do you guys suggest?


r/javahelp • • May 03 '19

Homework How exactly do I make a GUI? (Java)

16 Upvotes

Hi guys, for the end of the year I need to make a GUI. The teacher doesn’t tell you how but wants you to do it on your own and gave us basic instructions but didn’t tell me WHERE I actually make it. Do I use netbeans to do it or Alice? That’s all I need honestly. From there i can manage by myself. Thank you.

Also this is an intro to java class so nothing fancy.


r/javahelp • • Apr 29 '19

Java internship but not ready?

16 Upvotes

My internship starts in a few weeks and I'll be working with Java most likely, but I don't know what else I'll be using. I've done a little bit of coding in Java (syntax stuff like hash tables, loops, some recursion, the 101's, etc), but nothing really else. What should I learn in the next few weeks so I can hit the ground running and maximize my initial velocity? I don't want to lag behind too much because I heard it goes by fast and I want to do really well


r/javahelp • • Jan 15 '19

Help to structure simple java game to MVC

16 Upvotes

I am doing this project and want to structure it as the MVC model, i just cant to seem to understand how, help would be appreciated

my code here : https://github.com/tegstbesged/snake-simpel.git


r/javahelp • • Jan 04 '19

Solved When is a loop o(1)?

16 Upvotes

I'm super confused about when a for loop/while loop is o(1).

For instance if I have an array A= {1,2,3,4,5};

for(int i = 0; i< A.length; i++){
//append to string or something
}

This loop would be O(n) ? I understand if I loop: for(int i = 0; i< 100; i++){ //append to string or something }

This is constant time but when else is a loop constant time?


r/javahelp • • Mar 19 '13

Some tips when asking for help

16 Upvotes

I see a lot of folks asking for help in this sub as well as /r/java. Allow me to give a few words of friendly advice.

Use a concise, descriptive title. What if I titled this post omg u guise! read this! would you read it? Me neither.

Indent all of your code to properly format it. To trigger "code mode", every line must be indented a minimum of 4 spaces. Each level of further nesting should be 2 additional spaces.

This line is indented 4 spaces.
  This line is 6.
    Here is 8.
  Six again.
Now 4.

public class ThisEnsures {
  private final String yourCode = "Looks like this.";
}

If it seems tedious to type 4 spaces at the front of every line, type all of your code into a code editor like eclipse, highlight it and hit tab until you get the 4 spaces you need.

I strongly recommend using 2 spaces additional indent for each level of nesting, but that's a style thing. At least make it readable for us to help you.

Use descriptive variable names. You should be doing this anyway as a matter of writing self-documenting code. But especially if you're posting here for help, your code should be easy to read. This includes your main class name, even if it's the only class in your code sample.

Include all relevant code. It's very difficult to help you if you post something like: Hey guys, I need help with this code snippet, can anyone find the bug?

String foo() {
  funiculate(bar);
  String desc = "I don't even.";
  for (int i = bar; i< 2*bar; i--) { System.out.println(desc); }
}

Where on earth are all these things being referred to defined?

Don't put all your code in your main() method. I see lots of beginners do this, but you should get out of that habit. Also, don't just create a bunch of static methods and variables and have main() call those either.

Instead, take advantage of all that OO has to offer by creating an instance of your application, configure it with IO stuff, and then run it.

public class ExampleApp implements Runnable {
  private final Scanner in;
  private final PrintStream out;
  private final PrintStream err;

  public ExampleApp(InputStream in, PrintStream out, PrintStream err) {
    this.in = new Scanner(in);
    this.out = out;
    this.err = err;
  }

  @Override
  public void run() {
    // write code for your app here
  }

  public static void main(String[] args) {
    new ExampleApp(System.in, System.out, System.err).run();
  }
}

Never, ever repeat code. If in the implementation of your run() method you notice that you are typing the same three lines of code over and over again, make a new private method and call it instead of typing that code over and over again. If that code doesn't require access to any instance state, make it static.

This is a great idea because it allows you to write short, easily understandable methods and give them (and their parameters) good descriptive names. Easy to understand, self-documenting code. This will also help you avoid bugs.

When you get a handful of methods that all seem to be operating on some subset of state, consider encapsulating that state with those methods into a new class. This is great practice for doing real programming, and helps you structure your thinking by clumping problems into high level chunks.

For example, in the example app above, I would consider letting the ExampleApp class create a class that handles all interaction with the user (maybe called UserInterface) and another class that does the actual business logic of whatever problem you're trying to solve, and then coordinate interaction between the two. This way, the flow of data between the user and the code that does the crunching is all encapsulated by the application class, and the code that does the crunching is separate from the code that does the interaction with the user.

Write unit tests before asking for help. If you have a bug, and you've written a lot of small, easy to understand methods, try writing JUnit tests for all those methods that exercise them in basic ways. Use a mocking framework like Mockito or EasyMock (I prefer Mockito) to configure your classes if needed.

You'll be surprised how often you don't need to post your question in the first place.

Good luck!