r/javahelp • • Oct 29 '20

Is AdoptOpenJDK 11 safe to use on Mac and is it better than Oracle JDK?

19 Upvotes

I am just starting to take a Java course to begin my programming journey and would like to download the correct software right off the bat so I don’t have to uninstall and re download later.

I have heard negative things regarding Oracle JDK, so I am thinking of using the AdoptOpenJDK 11 instead for OS. Is this a good idea, and what would the difference be?

Should I use Hotspot or Openj9 as the JVM?

Also, I am just curious. Is AdoptOpen JDK also free for commercial use?

Thank you and sorry for all the questions?


r/javahelp • • Oct 28 '20

Java seems redundant for a complete beginner when creates new objects

19 Upvotes

I'm sorry if this question seems stupid, I'm a complete beginner and the way Java constructs new objects seems redundant for me. Using the rectangle package for example:

import java.awt.Rectangle  
Rectangle box = new Rectangle(5,10,20,30) 

So why do we write Rectangle twice? just writing

box = new Rectangle(5,10,20,30)

or

var box = new Rectangle(5,10,20,30)

isn't enough? writing this way it's clear that my object will be created from the Rectangle constructor


r/javahelp • • Oct 24 '20

Creating a .jar file of a java program w/ JavaFX

19 Upvotes

new to programming, more or less, this is my first time trying to compile a program... let alone one that uses javafx... and I'm not sure what I need to do. I'm trying to create a runnable .jar file that I can then distribute to others and they can use to run the program. I'm having trouble finding out what I need to do to make this work simply by googling it, it seems like there's different answers and I'm not really sure what I need to be doing to make this work. If someone could walk me through it that would be appreciated.

I can post a link to the .java file if you want it, and also I'm using Intellij for whatever that's worth. If you need more information let me know, I'm not sure what all info I'll need to provide.

The program runs perfectly fine if I build & run it through Intellij so there's that.

Please advise.


r/javahelp • • Sep 18 '20

I want to use a method from a different Java file in Visual Studio Code but it says MyUtils cannot be resolved Java(570425394).

19 Upvotes

I want MyUtils to work from a different Java file. Help is appreciated.

package SomeOtherPackage;
import Learning_Java1.MyUtils;<-----------also says cannont be resolved.
public class ExampleClass {
private static void doSomething() {
      MyUtils.printsomejunk(87)//------------------MyUtil cannot be resolved.

  }

}


r/javahelp • • Sep 10 '20

Unsolved Help with brute force program (don't worry it's just for fun)

19 Upvotes

I want to make a program that brute forces your "password" (the password is basically a string of text u enter when the program runs) I don't know how to go about doing the a b c d... aa ab ac ad.. zz algorithm


r/javahelp • • Jul 22 '20

There is a general sub consensus that the Helsinki MOOC is a great learning resource. What makes it so great?

19 Upvotes

I don't have much to compare it to. What does it do well?

Personally, I'm thankful I don't have to watch any videos!


r/javahelp • • Jul 21 '20

How to release a Java GUI application in Github?

19 Upvotes

Hi,

I have created a JavaFX application on Github and my next problem is how to create properly releases.

For the current moment, I have discovered a few options:

  • Git-flow

  • maven release plugin

  • Github release from the web interface

The first thing that I've tried was git-flow. It works. Github recognizes tags in the master branch and automatically create releases but does not build and attach artifact to the release. So, I have to build and attach an artifact manually. What of cause I do not like.

And I have a feeling that maven release plugin and Github web UI will not help me with that.

So, can someone point me how to configure Github to create releases completely automatically?


r/javahelp • • Jul 16 '20

Can't find the error in my code (Password Criteria Checker)

19 Upvotes
public class chapter5e527 {
    /*
    Program to check if a password contains
    At least 8 characters
    1 number
    1 uppercase letter
    1 lower case letter
     */
    public static void main(String args[])
    {

    System.out.println("Please enter a valid password: ");

    Scanner in = new Scanner(System.in);

    String password = in.nextLine();
        if (password.length() > 7)
        {

            boolean validPassword = false;

            validPassword = checkPassword(password);


            if (validPassword = false)
            {
                System.out.println("That password is invalid. ");
            }
            else if (validPassword = true)
            {
                System.out.println("That password is valid. ");
            }
        }
        else
        {
            System.out.println("This password is invalid. ");
        }
    }

    public static boolean checkPassword(String password) {
        
        boolean hasUpper = false; boolean hasLower = false; boolean hasNum = false; boolean allTrue = false;
        char c;

            for (int i = 0; i < password.length(); i++)
            {

                c = password.charAt(i);
                if (Character.isDigit(c))
                {
                    hasNum = true;
                }

                else if (Character.isUpperCase(c))
                {
                    hasUpper = true;
                }

                else if (Character.isLowerCase(c))
                {
                    hasLower = true;
                }

                if (hasNum && hasUpper && hasLower)
                {
                    return true;
                }

            }

        return false;}

}

Hi! I'm working on a homework program and am having trouble. The program is supposed to check if a password meets certain criteria. I'm almost finished, but the problem is I keep getting that the passwords are valid (even if they clearly aren't). The only time I get invalid is if it's under 8 characters. I've looked over multiple times and I can't see what I'm doing wrong? Any help would be appreciated!


r/javahelp • • Jul 05 '20

How do I make a label in Java GUI (intelliJ) using code only?

19 Upvotes

I want to make something like a report card where I ask the user to input their name, address, etc... in a GUI form. I made the GUI, but I'm not sure how to make the label and text field for the user input. In the GUI, I want the form to be something like this:

Name: (user input box)

Address: (user input box)

etc....

How do I go about this? Thank you.


r/javahelp • • Jun 15 '20

Need help understanding this.

19 Upvotes

Hi! I'm reading java for dummies 7. I came across something that doesn't makes sense to me, would you help me out?

This is my code:

int i = 20;

i = i++ + i++;

System.out.println(i);

The output is 41. But it doesn't make sense in my head. I know that if the ++ operator is at the end, then it keeps the original value until the end of the sentence, and after the expression is evaluated, it adds 1. So for me this would be like:

i = 20 + 20;

And once the sentence is over, it turn to 42, for I'm using ++ two times. I understand its something like i=20(+1) + 20(+1).

So why the result is 41? I can't understand it. Hopefully I've explained my self! Thanks for the help!

EDIT: Thank you very much for all your answers! I understand now!


r/javahelp • • May 20 '20

Wouldn't the Eclipse's auto generated hashcode method go above max int value way too quickly?

19 Upvotes
@Overridepublic int hashCode() {
	final int prime = 31;
	int result = 1;

	result = prime * result + a;
	result = prime * result + b;
        result = prime * result + c;
	result = prime * result + d;

	return result;
}

Say a,b,c,d are only above 100, it would already return a number way above the max integer value. Does this hash function only have very limited uses or am I missing something?


r/javahelp • • Apr 24 '20

What to learn after the OOP basics?

19 Upvotes

I just finished my first year of a college program. I took two java classes this year that covered all the basic object oriented programming stuff and I also did some GUI development with javafx.

I want to keep learning over the summer. What are some good resources (courses, textbooks etc.) that go beyond the basics of OOP?

I'm interested in learning stuff like network programming, algorithms, AI, but I would like any resources for stuff that's good to learn after going through the basics. I'm clueless about where to go next!

Thanks in advance.


r/javahelp • • Apr 22 '20

Function return type error

19 Upvotes

I'm relatively new to Java but and I'm trying buy I'm still experiencing errors that I do not know how to solve. I apologize for any crude formatting.
The error is "This method must return a result of type PVector[]"

The code is

PVector[] create(int mx) {

  for (float i = 0; i < mx; i++) {
    PVector x = new PVector(i, 0);
    PVector[] l = new PVector[mx];
    return l;
  }
}

The code itself looks fine but I'm unsure.


r/javahelp • • Apr 12 '20

Some Questions about the Oracle Java Certification

19 Upvotes

So I had some doubts regarding the exam and I wanted to get it answered by someone who is expert in java or has taken the exam.

  1. How does the whole exam hierarchy works? Like do I have to take the OCA first and then OCP?

  2. In 2020, what would you recommend getting certified in? Java 8 or 11?

  3. What resources were the best according to you for preparing for this exam?

  4. I have played with Java for a long time now and I still have to cover some ground with some APIs such as the Date Time API and File I/O as well. Do you recommend taking the exam in such case or just in general?

  5. Is it worth in 2020?

Sorry I had so many questions but I have 2 months summer holidays and I was thinking about the certification as well and preparing for it.

Many many thanks in advance!


r/javahelp • • Mar 25 '20

I’m looking to write a program that modified another source file, recompiles that file, and uses the new functionality.

19 Upvotes

I’ve tried using ToolProvider’s getSystemJavaCompiler() method but I’m still not noticing the new functionality after I recompile. Has anyone done something like this and could offer suggestions?


r/javahelp • • Mar 22 '20

Homework Due to COVID- 19, my options are limited. Class however is still in session.

19 Upvotes

Allow me to briefly explain my issue: So I began an intro to java class earlier in the semester and I had trouble understanding the fundamentals of Java. Going to see my professor in person proved useful, however now with the university on lockdown, I don't know where else to turn to help me with my code.

Despite this, I still have assignments to do and I have no idea on how to do them because classes have been canceled! It's a mess. I have the assignment on hand however I don't want to cheat. I guess my question is, where should I go to learn Java? YouTube has been confusing, CodeAcademy doesn't help much, I don't know here to turn. For those who are willing to help me, my question for my current assignment is this: What must I include in my getData class? The assignment is to make a grocery list for a cashier. Here is the test class currently:

String name = GetData.getWord(“Enter name of item”);

double price = GetData.getDouble(“Enter price of item”);

c.add(name, price);

name = GetData.getWord(“Enter name of item”);

price = GetData.getDouble(“Enter price of item”);

c.add(name, price);

// Add a two more entries of your own

// Now average the price of the items

c.average();

// Make payment

double amount = GetData.getDouble(“Enter amount of money for payment”);

c.tendered(amount); // For example twenty dollars were tendered

c.makeChange();

generateReceipt(c);

}

static void generateReceipt(Cahier c)

If anyone can help, that would be great. Otherwise, where should I go to further practice Java and improve myself in this coding language? Thanks!


r/javahelp • • Mar 09 '20

Netbeans is driving me nuts!!

19 Upvotes

I'm trying to utilize images with my JLabels via the icon property but they fail to load after a few run cycles when I'm double checking things work with other components of my JFrame. I have not altered anything in the code directly correlating to the images or labels either. Anyone know if there's anything I can do to stop this from happening?


r/javahelp • • Mar 06 '20

Help getting started with a constructor method

19 Upvotes

Hey, all! This is my first time working with anything involving a GUI and I'm stuck on where to begin with the constructor for this class. The goal is to initialize a 2D boolean array for a nonogram puzzle, where the only parameter is the solution for the puzzle. I feel like I'm overthinking things here, but I'd like a nudge in the right direction.

Thanks!

Here's the code in question:

public class Nonogram {

    public int height;   // The number of rows in the puzzle.
    public int width;    // The number of columns in the puzzle.
    public int maxRowGroups;  // An upper bound on the number of groups in any one row.  
    public int maxColGroups;  // An upper bound on the number of groups in any one column.  
    // Note: the above fields are used by the GUI classes, so don't eliminate them.
    // Do ensure that they are initialized to appropriate values.
    boolean[ ][ ] guess;   // A rectangular array to hold the user's solution to the puzzle.
    // The next two arrays are the heart of the puzzle.
    int[ ][ ] rowGroupLength;   // The group sizes for each row.  rowGroupLength[i][k] is the k'th group in row i.
    int[ ][ ] colGroupLength;   // Same, but for columns.  colGroupLength[j][k] is the k'th group in column j.
    
    public Nonogram(boolean[ ][ ] targetSolution) {
        //this.height = targetSolution.height;
        //this.width = targetSolution.width;
        guess = new boolean [height][width];

        
    }

    // The next constructor is provided for you.  It builds off the constructor above.
    public Nonogram(String s) {
        this(stringToBooleanArray(s));
    }
    
    
    // The next method is provided for you.  It converts a string to a 2D boolean array.
    static boolean[][] stringToBooleanArray (String s) {

        String[ ] lines = s.split("\n");
        boolean[][] rv = new boolean[lines.length][];
        for (int i=0; i<lines.length; i++) {
            String line = lines[i];
            rv[i] = new boolean[line.length()];
            for (int j=0; j<line.length(); j++) {
                rv[i][j] = (line.charAt(j)!='.');
            }
        }
        return rv;
    }
    
    int[ ] findGroupLengths (boolean[ ] data) {
        // figure out the groups in data, and record their
        // lengths in rowGroupLengths and colGroupLengths
        // TODO: your code here
        int [] trash = {};

        return trash;
                    
    }
    
    public String toString( ) {
        // print out the nonogram as a string.
        // this should include the group lengths
        // as well as the current guess.
        
        // this will be mainly used as an debugging tool, as 
        // the GUI will be better for interacting with the user.
        
        // For the guess, we will represent the "EMPTY color" by the '.' char, 
        // and the "FULL color" (black) by the 'X' char.

        // TODO: your code here.
        String garbage = "";

        return garbage;
    }
    
    boolean isGuessCorrect ( ) {
        // return true iff the guess has all the correct row/column
        // group lengths.  It does not have to match the "solution" field.
        // TODO: your code here

        return false;    // you will replace this.
    }
    
    // The next 4 methods are callback methods that will be invoked by the GUI when appropriate.
    // You need to fill them in to provide the correct functionality.
    public void handleMouseClickAt(int i, int j) {
        // Add code here to handle a "mouseClick" event at row i, column j.
        // You should toggle the guessed color for the cell at the clicked location.
        // You will need to handle the possibility that (i,j) is out of bounds (negative or too big).
        // TODO: your code here

    }
    
    public void handleMousePressAt(int i, int j) {
        // Add code here to handle a "mousePress" event at row i, column j.
        // You should record the location of the press in an instance variable.
        // Don't display anything until the mouse is released.
        // You will need to handle the possibility that (i,j) is out of bounds (negative or too big).
        // TODO: your code here

    }

    public void handleMouseReleaseAt(int i, int j) {
        // Add code here to handle a "mouseRelease" event at row i, column j.
        // If there was a previous mousePress event, you should now check whether the "release" cell is
        // in the same row or column as the "press" cell.  If it is, you should flip the color of the 
        // "press" cell, and color all the other cells between the "press" and "release" cells to match.
        // You will need to handle the possibility that (i,j) is out of bounds (negative or too big).
        // TODO: your code here

    }

    public void handleResetButtonClick( ) {
        // Add code to handle a click of the "reset" button.
        // You should reset all cells to be empty (white) again.
        // TODO: your code here
    }
    
    // main method: you can put your own test code in here.
    public static void main(String[] args) {
        
        String pic = "..XXX..\n.XX.XX.\nXX...XX\nX.....X\nXX...XX\n.XX.XX.\n..XXXX..";
        Nonogram nono = new Nonogram(pic);
        
        System.out.println(pic);
        System.out.println();
        System.out.println(nono);
        
        NonogramGUI gui = new NonogramGUI(nono);   // starts up a GUI interface for the puzzle passed to it.
    }

}

r/javahelp • • Feb 21 '20

What are some Java efficiencies you know of?

19 Upvotes

I want to know more about how to optimise Java code to produce generally better quality and performing code. One of the main optimisations I know of is using StringBuilder instead of concatenating Strings.

What are some other optimisations you know about, and where could I find out more about them?


r/javahelp • • Dec 31 '19

Support the Emoji with the personal font on the Swing application.

19 Upvotes

Hi guys,

I have a question on adding the support of the Emoji to my personal look-and-feel, I'm the developer of material-ui-swing and I'm using the "Noto Sans" for font and it doesn't support the emoji (like ♥).

I'm loading the font, Noto Sans, with code like this

try {
     GraphicsEnvironment ge = 
         GraphicsEnvironment.getLocalGraphicsEnvironment();
     ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File("A.ttf")));
} catch (IOException|FontFormatException e) {
     //Handle exception
}

This is the actual visive effect https://i.ibb.co/HB5m7Kf/Selection-087.png

Well, now I want to add "Noto Color Emoji" inside the look-and-feel but I don't know a method for using "Noto Sans" and "Noto Color Emoji" together.

PS: I know only one method for support this, and I must join the file fonts described inside this question on stack forum.

Exist another solution to this problem with Java?

Thanks your help.

This question on coderanch


r/javahelp • • Dec 16 '19

Voice recognition algorithm

19 Upvotes

Hello,

I've been searching for an algorithm or library of some sort that i could implement in my java code that recognizes a specific persons voice.

Basically iam making a voice controlled app, and i want the app to only follow my voice. What is the easiest way to do this?

I've tried:
Alizée
Recognito
Azure(failed the configuration)
Kaldi

Any answer is appreciated!
Thanks


r/javahelp • • Dec 07 '19

Solved I am trying to write the name & address of 10 students in a text file, but I don't know how to organize it in a particular pattern where it doesn't look a complete mess.

19 Upvotes

I have managed to write upto this and don't know what else to do. Thought about this like two hours. The file is created but it doesn't write all names and addresses for some reason.

package Exam;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

class Tester{
    public static void main(String args[]) throws IOException {
        Scanner sc = new Scanner(System.in);
        for(int i= 0; i<10; i++) {
            System.out.println("Enter name of student: ");
            String x = sc.next();
            System.out.println("Enter address of student: ");
            String y = sc.next();
        FileWriter file = new FileWriter("/home/pranav/Desktop/student.txt");
        file.write(x);
        file.write(y);
        file.close();
    }
}}

r/javahelp • • Nov 24 '19

Solved Coding Bat

19 Upvotes

Coding Bat solutions

If anyone needs solutions to the their work regarding Coding Bat, or needs help with Coding Bat, I’m compiling a repository of solutions on GitHub.


r/javahelp • • Oct 13 '19

Can you explain to me like I’m five about what indexes and arrays are in Java?

19 Upvotes

Basically, I just need some help understanding what indexes and arrays are.