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 20 '20

Opinions on Java OCA / OBP oracle certifcation?

16 Upvotes

I was going to order this package from amazon https://www.amazon.com/OCA-OCP-Java-Programmer-Certification/dp/1119272092/ref=sr_1_1?dchild=1&keywords=java+oca+ocp&qid=1595222090&s=books&sr=1-1

Is this obsolete now that we are past java 8 (i.e. java 11) and does anyone recommend it? I know Java pretty decent (conditionals, loops, OOP, generics, data structures, mediocre with concurrency, jdbc, lambdas) , but I really want master over the areas I am currently mediocre with.


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 25 '20

AdventOfCode Need help with spring boot roadmap

16 Upvotes

I am planning to start studying for spring boot and I have no idea about. If you can help me with the learning path or the resources which you have come across while studying that concept would be extremely helpful. Please help


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 • • Feb 13 '20

What the freak are buffered readers?

16 Upvotes

Can someone help me and tell me what exactly it does? Thanks


r/javahelp • • Jan 14 '20

Recursion with Lambda Expressions

16 Upvotes

Hello everyone!

I'm having a bit of trouble understanding the lambda expressions. My code snippet should be using a position of a tree and do the traversal with the code. I think I might be looking it at the wrong way. Maybe logic or lack of syntax knowledge of the lambda expressions is what's stopping me of doing what I want.

Any help would be greatly appreciated. Below my code snippet:

@Override
 public void traverseInOrder(Consumer<Position<E>> visit) {
                         visit = p -> {
                        inOrder(p);
          };
           visit.accept(root);
 }

 private  void inOrder(Position<E> p) throws InvalidPositionException {

     BinaryTreeNode<E> t = (BinaryTreeNode<E>) p;
     pt ->  {
                 inOrder(t.left);
                 System.out.println(t.element());
                 inOrder(t.right));
            };
}

r/javahelp • • Nov 06 '19

Going crazy, need help with a program

16 Upvotes

Hi guys, I'm an ansipring java developer. My developer friend gave me an exercise and I can't for the life of me figure out how to do it. If you guys could help I would be so grateful.

This is the exercise:

Given a weather.dat file, write a program that given the file in input returns the day with the biggest and lowest temperature range. In this file there are 30 days and there's a lot of data for these days, but the temperature columns are the second and third one. So it's like : Day | Max Temp | Lowest Temp| ecc | ecc | ...

I understood I have to use Java Arrays and I managed to have the program read all the file but I don't know how to proceed. Help, thanks lol


r/javahelp • • Aug 05 '19

I'm creating a trading card game and I think I'm doing something wrong.

16 Upvotes

Here's an example of a card in my game.

as you can see I am initializing a lot of objects for each card that is in a deck. is this going to lead to memory issues down the line? each deck can only consist of a predetermined amount of cards anyway and its not like the objects contain a huge amount of data. this way of organizing my classes just makes sense to me but I feel like there's probably a smarter way of doing it, perhaps using interfaces... any help would be appreciated.

package com.thalanaar.base.packs.bloodbath.f.epic;

import com.thalanaar.base.ElementalDamage;
import com.thalanaar.base.classes.CardClassBase;
import com.thalanaar.base.classes.Summoner;
import com.thalanaar.base.elements.Ritualistic;
import com.thalanaar.base.classes.classabilities.SummonDemon;
import com.thalanaar.base.races.Human;
import com.thalanaar.base.races.Race;
import com.thalanaar.base.races.racialpassives.WillPower;
import com.thalanaar.base.rarities.c.VeryRare;

public class BB24 extends VeryRare {

    public BB24(String name, int hp, int damage, int tier, Race race, ElementalDamage element, CardClassBase cardClass) {
        super("human", 13, 3, 4, new Human(new WillPower()), new Ritualistic(), new Summoner(new SummonDemon()));
    }
}

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 • • Jan 16 '19

[Humor] Interview with Object Reference[source: HeadFirst Java]

16 Upvotes

HeadFirst: So, tell us, what's life like for an object reference?

Reference: Pretty simple, really. I'm a remote control and i can be programmed to control different objects.

HeadFirst: Do you mean different objects even while you're running? Like, can you refer to a Dog and then five minutes later refer to a Car?

Reference: Of course not. Once I'm declared, that's it. If I'm a Dog remote control then I'll never be able to point(oops - my bad, we're not supposed to say point) I mean refer to anything but a Dog.

HeadFirst: Does that mean you can only refer to only one Dog?

Reference: No. I can be referring to one Dog, and five minutes later I can refer to some other Dog. As long as it's a Dog, I can be directed(like reprogramming your remote to different TV) to it. Unless... never mind.

HeadFirst: No, tell me. What were you gonna say?

Reference: I don't think you want to get into this now, but I'll just give you the short version - If I'm marked as final, then once I'm assigned a Dog, I can never be reprogrammed to anything else but that one and only Dog. In other words, no other object can be assigned to me.

HeadFirst: You're right, we don't want to talk into this now. OK, so unless you're final, then you can refer to one Dog and then refer to a different Dog later. Can you ever refer to nothing at all? Is it possible to not be programmed to anything?

Reference: Yes, but it disturbs me to talk about it.

HeadFirst: Why is that?

Reference: Because it means I'm null, and that's upsetting to me.

HeadFirst: You mean, because you have no value?

Reference: Oh, null is value. I'm still a remote control, but it's like your brought home a new universal remote control and you don't have a TV. I'm not programmed to control anything. They can press my buttons all day long, but nothing good happens. I just feel so...useless. A waste of bits. Granted, not that many bits, but still. And that's not the worst part. If i am the only reference to a particular object, and then i'm set to null(deprogrammed), it means that now nobody can get to that object i had been referring to.

HeadFirst: And that's because...

Reference: You have to ask? Here i've developed a relationship with this object, an intimate connection, and then the tie is suddenly, cruelly, severed. And i will never see the object again, because now it's eligible for[producer, cue tragic music] garbage collection. Sniff. But do you think programmers ever consider that? Sniff. Why, why can't i be a primitive? I hate being a reference. The responsibility, all the broken attachments...


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 • • Jun 26 '18

What would you like to learn about Java Virtual Machine (JVM)?

16 Upvotes

I am working on a video course for Java Virtual Machine. I wanted to take feedback on what are some of the things people find challenging about JVM. I would request 30 seconds of your time to contribute to this survey.

https://goo.gl/forms/3QOQBfjedNVpxhOl2


r/javahelp • • Jun 12 '18

Can't wrap my head around Polymorphism

16 Upvotes

Read some and watched some about it, but I can't seem to quite get it, and the people of javahelp never disappoint.

I don't even think I understand it well enough to ask a proper question about it. But, is it only useful for method overriding?

And what is the difference between referencing a superclass while making a new instance of subclass, rather than just going 1:1?

as in

Superclass class1 = new Subclass(); // this is considered polymorphism

Subclass class2 = new Subclass(); // What is the advantage of the above?

The way i Interpret this, is that method overriding wont work on class 2, since if you don't override Superclass method, it wouldn't have anything to fall back on? But a class2 method would still override the superclass method right?

I'm just really confused about this topic still, so I can't explain very well what I don't understand.


r/javahelp • • Mar 20 '18

JDK10 and Maven: found issues and how to solve them

16 Upvotes

Hi there all,

I just downloaded the new JDK and I wanted to try it with a silly-test-project with Maven immediately. However I found some issues in the maven-compiler-plugin that I want to share and how to solve them.

First of all: plain compilation. If you're going to use the default maven-compiler-plugin (that is the version 3.1 even if you use Maven 3.5.3) you have to specify a different target version from the source version:

<maven.compiler.source>10</maven.compiler.source>
<maven.compiler.target>1.10</maven.compiler.target>

with JDK9 was the same (target 1.9). After that the project compiles correctly.

The second issue was a little bit more complicated to understand, since after I upgraded the maven-compiler-plugin to version 3.7.0 the project was compilable, but when I tried to require a module (for instance java.xml), maven throws an exception «IllegalArgumentException». If you try to downgrade the Java version, from 10 to 9, everything is fine, but not vice-versa. After some investigation (by enabling the maven debug log) I found that during the testCompile phase, maven-compiler-plugin uses cglib and ASM (I didn't know that) and since I found a similar issue on reading the module definition (https://gitlab.ow2.org/asm/asm/issues/317794) I tried to upgrade the plugin-dependency.

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>3.7.0</version>
      <configuration>
        <jdkToolchain>
          <version>${java.version}</version>
        </jdkToolchain>
      </configuration>
      <dependencies>
        <dependency>
          <groupId>org.ow2.asm</groupId>
          <artifactId>asm</artifactId>
          <version>6.1</version>
        </dependency>
      </dependencies>
    </plugin>
  </plugins>
</build>

And it worked! :)

I hope it helps someone! Enjoy!