r/javahelp • • Dec 25 '20

List of docker images for Java developers

18 Upvotes

A list of frequent Docker images #Java developers will configure on their local Docker. Access this list here and make sure to bookmark, so next time you want to configure, follow the simple steps mentioned.

http://thetechstack.net/pages/library/docker-images-library/


r/javahelp • • Dec 22 '20

Solved Best way to design database for Calorie Counter Application

18 Upvotes

Hello. I'm wondering how to design a database for Calorie Counter Application. There will be 3 basic classes:

  • User (includes Meals)

  • Meal (includes FoodProducts)

  • FoodProduct

I'm not sure if the structure is designed by me is good. Is there a better way to do it? Will the database be stable when there will be a lot of records?

CREATE TABLE IF NOT EXISTS `users`(
	id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    username VARCHAR(45) NOT NULL UNIQUE,
    password VARCHAR(45) NOT NULL,
    age INT NOT NULL,
    email VARCHAR(60) NOT NULL,
    weight SMALLINT NOT NULL,
    height SMALLINT NOT NULL,
    gender ENUM ('male', 'female')
);

CREATE TABLE IF NOT EXISTS `meals`(
	id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
	created_at TIMESTAMP NOT NULL DEFAULT NOW(),
    user_id int NOT NULL,
    FOREIGN KEY (user_id) REFERENCES users(id)
);

CREATE TABLE IF NOT EXISTS `food_products`(
	id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    product_name VARCHAR(45) NOT NULL,
    proteins DOUBLE NOT NULL,
    fats DOUBLE NOT NULL,
    carbohydrates DOUBLE NOT NULL,
    meal_id INT NOT NULL,
    FOREIGN KEY (meal_id) REFERENCES meals(id)
);

User class:

public class User {

    private int id;
    private String username;
    private String password;
    private int age;
    private String email;
    private short weight;
    private short height;
    private Gender gender;
    private List<Meal> meals;
}

Meal class:

public class Meal {

    private int id;
    private ArrayList<FoodProduct> products;
    private LocalDate date;
}

FoodProduct class:

public class FoodProduct {

    private int id;
    private String productName;
    private Double proteins;
    private Double fats;
    private Double carbohydrates;
}

r/javahelp • • Dec 19 '20

Representing "terminated/disconnected" state

18 Upvotes

Let's say we have a Connection object

interface Connection {
  void connect();
  void doSomething();
  void disconnect();
}

After disconnet-ing, a user could still potentially doSomething.
How do you guys prefer to handle this situation?

Internally checking the object state at every method invocation is what I usually see, but I've always seen this as bad practice. Imagine having dozens of such doSomething methods.


r/javahelp • • Dec 15 '20

Tips and insights when finding a job

18 Upvotes

I recently made a post a couple of days ago on how I should continue my Java career after recently graduating with a Certification in Java Programming from college. Everyone in my post pointed to spring and Hibernate being a must so naturally I went and bought a Udemy course on the framework.

Before I get back to the books and put myself through rigorous hours of studying once again. I want to know how likely is it to find a job just knowing Java std library. I'm very comfortable using the Java Standard library and I'm really keen on finding a job as soon as possible.

is it possible to find a Job knowing just the Java std library ?

I'm more than willing to learn new libraries and frameworks, it's just that I really want hands on experience.


r/javahelp • • Dec 06 '20

(Beginner in Java) I've made a program that counts the most frequent character in a string.

18 Upvotes

My issue is that the string is "IN A RIGHT TRIANGLE THE SQUARE OF THE HYPOTENUSE EQUALS THE SUM OF THE SQUARES OF THE LEGS" and it the output always shows up blank. But when I shorten the string, the output works. If anyone could help me that would be greatly appreciated.

https://pastebin.com/pqVu7QQz


r/javahelp • • Jul 23 '20

Solved Need help understanding objects

18 Upvotes

Hello, the following code is given off a practice exam for our upcoming exam:

public class Main {
    public static void main(String[] args) {
        Test t = new Test();
        t.i = 200;
        System.out.print(Test.i + " " + t.i);
    }
}
class Test {
    public static int i;
    public Test() {
        i = 100;
    }
}

The question is asking for the output. The output is: 200 200

Why? I understand why t.i is 200, but why is Test.i 200? From my understanding, Test is the 'type' of an object. Does this mean that the variable i will change for every object of type Test? Is this because i is static, public, or both?


r/javahelp • • Jun 13 '20

ArrayIndexOutOfBoundsException: 0 error help. My code is exactly the same as the textbook I'm learning from (Algorithms by Sedgewick and Wayne).

18 Upvotes

Simple program to update count by 1 if three ints sum to 0, ints fed into program via a text file.

I understand (or I think I do) what the error means, basically the array is empty!

Here is the code:

The command I'm using in CMD to run program is: java ThreeSum < 1Kints.txt

public class ThreeSum
{
    public static int count(int[] a)
    {
        int n = a.length;
        int count = 0; 
        for (int i = 0; i < n; i++)
            for (int j = i+1; j < n; j++)
                for (int k = j+1; k < n; k++)
                    if (a[i] + a[j] + a[k] == 0)
                        count++; 
        return count; 
    }
    public static void main(String[] args)
    {
        In in = new In(args[0]); 
        int[] a = in.readAllInts();
        StdOut.println(count(a)); 
    }
}

Like I said, this is a direct copy from the textbook, the only thing I can think of is that the command to run this program and parse the file 1kints.txt to the In in = new In(args[0]) line is incorrect?

It's annoying because I have definitely had this program run in the past.

Sorry if this is really obvious, I cannot see, trying all day. This isn't even part of an exercise or anything.


r/javahelp • • Jun 10 '20

SPRING FRAMEWORK

18 Upvotes

I am learning spring framework, after a few months of trying, I also started building projects like CRUD, registration, login authentication, paypal payment, chat using socket. Now I am looking for something new and more advanced. I have searched google many times but it still revolves around basic CRUD functions or it may be because I do not know the search keyword. Any other suggestions for me? Thanks📷


r/javahelp • • Apr 13 '20

Having a hard time learning Java, need some course recommendation.

18 Upvotes

I paid a few thousand bucks to take a course which promises to land you at a QA automation testing job after 4 months. It starts with SDLC, ALM, Jira, SQL then moves on to Java and selenium. Can't seem to gasp the concept of it. It's a physical class which also uploads the recorded sessions online. I keep rewinding the recorded online sessions but still no luck. Is there a more easy to understand course online for free or cheap?


r/javahelp • • Mar 10 '20

Where do I start if I want to make an OOP based GUI game in Java?

18 Upvotes

Currently at university we have to decide what our semester project is going to be. I'm learning Object Oriented Programming in Java and that, along with GUI is supposed to be the main focus of our program.

To be completely honest, I'm still not sure what to make but I'm leaning heavily towards designing a game as opposed to a management system.

So my question is what's a good place to learn the basics for these things? I have found some tutorials on youtube but am yet to see the content they cover. So any help in this regard would be greatly appreciated . :)


r/javahelp • • Feb 16 '20

Should i bother learning JAVA 9?

18 Upvotes

I am a beginner and got a bunch of free JAVA pdfs teaching in Java 9.

Should i bother (starting with) learning Java 9 or start with learning the latest Java version? Or will learning the older version of JAVA 9 end up setting me back somehow?


r/javahelp • • Jan 11 '20

infinite loop in chess

18 Upvotes

currently i have a design problem in my chess game, im creating a functionality with means that the king cannot moved onto tiles that are being attacked for example by a rook

so i did program this as following:

0. Lets say the king has a list of 4 valid moves

  1. I create an function(isSafeSpotForKing) that is a condition during the calculating the king moves, to ensure the position is safe

  2. this functions loops through all pieces of the opponent calculates the valid moves from the opponent

  3. Then im comparing ALL the possible moves from the opponent with the possible valid moves of mine (based on x and y coords) 3.0 if compare reach true, the move is not valid ofc 3.1 if compare reach false, the move is valid

but the problem is The opponent has a king aswell, and whenever i trigger the function, it goes to the opponent pieces ( so eventuallly the opponent king (look step 2) so black player king > white player king > black player king > white player king, creating a infinite loop xd which results in a stack overflow error


r/javahelp • • Dec 29 '19

OpenJDK license

18 Upvotes

Hello,

so I'm a bit confused now regarding the licensing of the open jdk. Can I use the OpenJDK 13 in production projects or not? https://jdk.java.net/13/

And what does in "GNU General Public License, version 2, with the Classpath Exception." the "with the Classpath Exception." mean?


r/javahelp • • Dec 23 '19

Solved How can I get the time length of a video file and change the time position of a video with a slider for my Media Player?

18 Upvotes

I am trying to make a simple media player application with JavaFX that can take a downloaded video file and play it on the application. I'm able to get the video playing, but I've encountered two problems with the slider that is used to display and change the time position of the video.

  1. Firstly, I can't figure out how to get the time length of the video that is to be played. I can see the length of an individual video from the file when looking in the file properties and after converting the time to seconds, set that time as the max for the slider. But I can't find a way to get the time of a video without having to manually put the value in. There are some solutions to this problem such as using the Xuggler library, but I don't understand how/where to download the jar file. I'm not sure if there's a way to solve this without using an external library though.

  2. Secondly, I cannot change the time position of the video by using the slider. I want to be able to go to any point in a video by clicking on that position on the slider and I have figured out how to do this when the video is paused, but if the video is playing it seems that the position clicked does not register and the slider just goes back to the original position before the mouse click. When clicking the desired position rapidly many times that seems to work, but it does not work when clicking the time position only once.

Here is a link to the code

This is the Main Class with the start() method

This is the XML file

I'm new to programming and not to familiar with using tools outside of the standard library. I've been trying to solve these two problems for the past day, but cannot find any solutions. Any help would be appreciated. Thank you.

Edit:

Solution for #1: I fixed the first problem by just getting the duration of the media object in seconds. This value is used to set the max value of the time slider so that you don't have to manually put in the time length of each video.

Solution for #2: The second problem was fixed by using the Mouse Pressed and Mouse Released action events to change the time position of the slider which handles the two actions individually instead of only using the Mouse Clicked event which only respond after the mouse has been pressed and released. The Mouse Clicked event seemed to not respond fast enough and would not react in time to change the value of the slider before time position automatically changed to its new value set by the code from solution #1. By using the Mouse Pressed event which pauses the video, the time slider can adjust to any position by clicking or dragging.

This is a link to the fixed code


r/javahelp • • Dec 19 '19

Efficient way to read through a text file in java?

18 Upvotes

I am writing an adjacency array based implementation of Dijkstra for an assignment. The input is a text file containing nodes and edges, so my program needs to read throuth the lines and convert the text into ints and doubles which have to be stored into arrays.

My first implementation I used a scanner and the split method, then converted the strings into ints and doubles. It worked but the performance was very bad.

The second try was using a buffered reader and accumulating the chars into a stringbuilder. This worked way better, for a file size of 400MB it did the job in around 13 seconds. However for a file of 2.7 GB my computer crashes (the prof said it should work ok with 8GB of RAM, which is the amount I have). I've experimented with different buffer sizes but it still didn't work.

Does anyone have any suggestions for the most efficient way to do this? Maybe an ideal buffer size for my implementation or a completely new way. Thanks in advance


r/javahelp • • Dec 14 '19

Workaround How to generalize program for outside Java use?

18 Upvotes

Hello! I recently wrote a program to calculate and add the file size for some songs in my pc memory, but it only works by importing the songs to my workspace instead of (how I want it to be) opening file explorer and choosing the files it wants to calcuate.

Then end goal is to be able to send this as a downloadable program, have anyone execute it, and have it return the total file size for all of the selected files. Here is what I've written.

Github link to program code

Much thanks!

Also, please no hate. I've been coding for a little over a year now through my school, and wanted to try a little more than just Strings, Arrays, and other classes and algorithms. Thanks for your kindness.


r/javahelp • • Nov 18 '19

i'm looking for some practice

18 Upvotes

i'm learning java and want to consolidate. Any place i can look for practice?


r/javahelp • • Nov 14 '19

Difference in using WEB-INF and resources folder

18 Upvotes

After reading this tutorial on Thymeleaf I found this one. First one uses some configurations to load templates from WEB-INF folder, second approach loads them from resources folder. What is the reasoning behind these approaches and what is the difference between them in web application context?


r/javahelp • • Oct 25 '19

Homework I need to get the lowest address on an IPv6 subnet

18 Upvotes

I can use the SubnetUtils library to get the lowest in IPv4 with a subnet value handy enough. But that doesn't support IPv6 addresses. Is there any method or library in Java that will do that job?


r/javahelp • • Oct 11 '19

How do I send a SMS? Aka instant message.

18 Upvotes

I am doing an e-commerce site, and I want to add a layer of security to tie accounts to two factor verification. What is the simplest or best way to send a sms via java?


r/javahelp • • Sep 07 '19

Why does Oracle need my address?

18 Upvotes

I was just wondering Why Oracle asks for your address when you try to make An account to install Java. I know this isn’t related to the code itself but I need answers


r/javahelp • • Aug 17 '19

Easier way to do this? (Working with array)

18 Upvotes

How can I call rotate() on my orbs objects so that I do not have to type out every index of the array? Is this even possible?

And no I cannot use a for loop (I believe) because I need all indexes to be calling rotate() at the same time.

public static void rotateAll() {

    while (true) {

      orbs[0].rotate();
      orbs[1].rotate();
      orbs[2].rotate();
      orbs[3].rotate();
      orbs[4].rotate();
      orbs[5].rotate();
      
      orbs[6].rotate();
      orbs[7].rotate();
      orbs[8].rotate();
      orbs[9].rotate();
      orbs[10].rotate();
     
      orbs[11].rotate();
      orbs[12].rotate();
      orbs[13].rotate();
      orbs[14].rotate();
      orbs[15].rotate();
      
      orbs[16].rotate();
      orbs[17].rotate();
      orbs[18].rotate();
      orbs[19].rotate();
      orbs[20].rotate();
     
      orbs[21].rotate();
      orbs[22].rotate();
      orbs[23].rotate();
      orbs[24].rotate();
      orbs[25].rotate();
 
    }

  }

r/javahelp • • Jul 20 '19

How can I begin to learn machine learning with java.

18 Upvotes

Basically I have no idea about any other programming language than (core) java... Could you please help me with those machine learning tutorials that give a walkthrough for java? I tried finding but most of the tutorials I managed to find are for python. Thanks


r/javahelp • • Jul 13 '19

Are non short-circuit logical operators ( | & ) refered to as bitwise operators?

18 Upvotes

That's one thing that confuses me.

From my research online, it seems that | and & are referred to as "bitwise operators", even if they are used as logical operators between 2 boolean expressions. What do they have to do with bitwise operations, besides using the same operator symbols?

Here an example:

The non-bitwise operators && and || are short-circuit operators. In other words, with &&, if the LHS is false, the RHS will never be evaluated; with || if the LHS is true, then the RHS will never be evaluated. On the other hand, the bitwise operators & and | are non-short-circuit, and will always evaluate both the LHS and the RHS.

https://softwareengineering.stackexchange.com/questions/68183/when-is-it-appropriate-to-use-a-bitwise-operator-in-a-conditional-expression