r/javahelp • • Oct 05 '20

Workaround How would I shorten my Constructors?

21 Upvotes

I have this user class that contains a long list of constructor params. I also need usage for both smaller Users with less info, I don't want to explicitly write all those constructors. Anything I can do?


r/javahelp • • Oct 01 '20

Is this the place I need to go?

21 Upvotes

So im really struggling with my java 1 coding class right now and my professor is getting more and more tired of answering my questions. Can I get some help here?


r/javahelp • • Jul 18 '20

Solved I'm a beginner in Java. How can I access the value of a variable (declared inside nested if) outside nested if?

21 Upvotes

If I declare the variable outside the nested if its value will change, right?


r/javahelp • • Jul 04 '20

Java Technical Interview Advice

21 Upvotes

Hey Guys, I have a technical interview for Java next week, the interviewer will be asking me some concepts about Java. Could you guys give me some general tips and also if you had a previous java technical interview, what general Java questions did they ask you?

Thanks guys!!


r/javahelp • • May 08 '20

help, i pressed a wrong button in eclipse and now my side bar, the console and everything except the window to write code in is gone!

21 Upvotes

i dont know what i pressed but ill put a link to a picture in the comments

edit: ok its worse now, i clicked on a button that said restore, now theres just a bunch of windows i dont understand. is there an option to restore ut to default?


r/javahelp • • Mar 23 '20

Parsing a CSV file - finding a specific field in the same row

21 Upvotes

Hello guys,

So I'm searching for a way to find a specific string in my CSV, and once found, search another item in that same row. For example:

itemIDitem namequantity
001item13
002item22

I have this piece of code:

import java.io.BufferedReader;  
import java.io.FileReader;  
import java.io.IOException;  

public class CSVParser {
    static void findProduct(String keyword) {
        String line = "";  
        String splitBy = ",";  
        try {
        BufferedReader br = new BufferedReader(new FileReader("c:\\temp\\test.csv"));  
        while ((line = br.readLine()) != null) {
            String[] prod = line.split(splitBy);
            if (prod[1].contains(keyword)){
                System.out.println(keyword + " exists");
                return;
            }
            else{
                System.out.println(keyword + " is not in stock");
            }
            }
            br.close();
            } 
            catch (IOException e) {  
            e.printStackTrace();  
            }
    }
    public static void main(String[] args) {
        findProduct("item1");
    }
}

This code will return that item1 exists, because it searches for it in prod[1]. Once found, I'd like to know the quantity of item1 by skipping to the next field. So I can do prod[2] right?

My question is, how do I parse the rest of the items? The for loop goes over everything, and my if (contains()) can find the existence of an item, but then what? How do I access other fields in that same row where the String was found?

Thanks :)


r/javahelp • • Aug 15 '19

How do I sort() an ArrayList<MyObject>

21 Upvotes

I have a Class (POJO) for a transaction that has a LocalDate field among other fields:

public class Transaction implements Comparable<Transaction> {

    private LocalDate date;
    // other fields
}

If I understand things correctly, I need to implement the following method within my Transaction class:

@Override
public int compareTo(Transaction transaction) {
    
    // Here is where I need a hand    
    // I think I do something like this:

    int compare = transaction.getDate().compareTo(this.date);
    return compare;

}

How should this method be implemented to sort in ascending order?

Once done, how do I execute the actual sort?


r/javahelp • • Jul 16 '19

Student from Ukraine need a Java helper

21 Upvotes

I am a student from Ukraine. Now I am learning the Java. I am familiar with Java Core, JDBC, MySQL, JSP + Servlet and MongoDB. Now I am improving my knowledge about collections, IO and design patterns. And I would like to ask for help in learning and structuring knowledge of this language. If someone can tell in which order to study the technology, what needs to get attention, and what you can just skip or share your own experience, I will be very grateful.


r/javahelp • • Mar 01 '19

How to Javafx on jdk 11

21 Upvotes

Hello,

I see a lot of people trying to asking about how to create a javafx app under jdk 11.

I would like to refer you to the community page, where you can find tutorials and quick guides.

https://openjfx.io/

Also, feel free to contact for any question.


r/javahelp • • Nov 30 '17

Beginner at Java

21 Upvotes

Is there any place that I can find a helpful guide on everything about Java? Thank you!


r/javahelp • • Aug 07 '26

New JDK 28 EA build is available! (Vahalla now)

20 Upvotes

Value Classes, Strict Field Init… everything is finally in. Time to play with the future of Java.

https://jdk.java.net/28/release-notes


r/javahelp • • Oct 12 '25

Which free Java IDE/Editor is the best for an absolute beginner?

20 Upvotes

Internet privacy is the new gold. I mass deleted all of my posts on Reddit using Redact. It also supports databrokers, Instagram, Twitter, and all major social media platforms.

expansion like scale encourage special future wide absorbed history sulky


r/javahelp • • Aug 16 '24

Codeless Considering coming back to Java after 10 years of not using it. What are some of the things developers use today they didn't use then?

20 Upvotes

Sometime around 10 years ago I switched paths and have been blessed to be able to use functional programming almost exclusively in my professional endeavors (mostly Clojure and Elixir). Currently looking at jobs and realizing that my talents with Java are probably so rusty as to be nearly useless.

What are some of the biggest day-to-day changes?


r/javahelp • • Aug 06 '24

Free Book - Java in a Nutshell

20 Upvotes

Hey folks - I'm super-pleased to announce that my book "Java in a Nutshell" (8th Edition) is being made available for free download for another 6 months, courtesy of Red Hat - https://red.ht/java-nutshell-free

Hope you like it and find it useful!


r/javahelp • • Aug 14 '22

Basic Java questions thread

20 Upvotes

Hello, I'm coming from C++ and having to learn some Java pretty quickly. I have some questions, and wanted to post in a single thread, so that I'm not flooding /r/javahelp.

I'll post my questions in the comments. Anyone else is free to answer or ask qs of their own. Thank you.


r/javahelp • • Jun 29 '22

What is Spring actually?

20 Upvotes

Hey everyone,

I once asked where to find good ressources for Spring development and came through an answer that has said that Spring is not for designing a website but for dynamically getting data onto said website. So I wanted to know what is Spring actually and hope that someone could explain it in an easy way.

Thanks in advance.


r/javahelp • • Apr 25 '22

How do I learn to think in an Object-Oriented Way?

20 Upvotes

I have 6y of professional experience from not so great organization. Everyone at my workplace has the "get-things-done" mentality, because of which code-quality took a serious hit. I'm no different, I meet business requirements but my code is fundamentally bad.

Our codebase is very difficult to work with because :

  1. We're writing our code in a procedural fashion

  2. Its just a ton of classes with static methods. Lots of ifs and switches to handle conditional behaviour.

  3. Ofcourse no unit-tests.

  4. Some methods are monsters with 8-9 parameters and 1000-1500 lines long.

I've been this high-productivity programmer at my org, but recently I've gotten several rejections from good organizations because I kept bombing low-level design rounds in my interviews(Eg: Design Chess, Design grep in Java etc..).

I've decided to change it, I want to transform from a feature-monkey into someone who puts a thought into the code they author. I want to become a better object-oriented programmer.

I searched through various subreddits / Stackoverflow questions and compiled their recommendations:

  1. Head First Object-Oriented Analysis and Design : Brett McLaughlin

  2. Practical Object Oriented Design in Rudy : Sandi Metz

  3. Growing object oriented software : Steeve Freeman

  4. Refactoring by Martin Fowler : Martin Fowler

  5. Enterprise Integration Patterns : Gregor Hohpe

  6. A Philosophy of Software Design : John K. Ousterhout

  7. Object Design : Rebecca Wirfs-Brock and Alan McKean

My Goals:

  1. Learn Object Oriented Design

  2. Implement these learnings in an existing code base (refactoring)

  3. Write modular testable code using DI containers like Spring/Dagger etc. I've learnt gone through various talks and I understood that a good object-oriented code lends itself to unit-testing very easily. So, I think even before diving into various testing methodologies (mock objects etc..) I want to strengthen my OOD bone.

Questions:

  1. How do I improve/train myself into Object-based thinking.

  2. Have you ever been in such a sitation, how did you make the shift from procedural style coding to object oriented style coding?

  3. I've read lot of good things about these books. Given my goals and background, what order would you recommend? If you have any other recommendations (blogs/videos/courses/github-repos similar to spring-pet-clinic but for learning OOD) please let me know.

I know this is a long post, if you've reached here kudos you're a wonderful human being :) My attention span would've failed me in the mid-way. Genuinely, I thankyou for reading this.


r/javahelp • • Mar 12 '22

Unsolved Am I a dinosaur if I use Swing instead of JavaFx to make a Java desktop application GUI?

20 Upvotes

I'm thinking of writing a Java desktop application and I instinctively started looking at Swing since that is what I used when I first learned Java in 2004. I've occasionally made simple Java programs with Swing since then but never something with a production quality GUI. I just learned about JavaFX a few days ago but I'm getting conflicting information about which GUI toolkit to use. I'm hearing both that Swing is deprecated and that JavaFX is lacking in completeness compared to Swing.


r/javahelp • • Jun 20 '21

How to become professional developer in Spring Framework? Looking for Spring Roadmap.

20 Upvotes

I am very beginner in this java world. And Ii am looking for guidance. I am interested to learn Spring framework want to become pro on it.

Can some on give me advice on spring framework roadmap.


r/javahelp • • May 28 '21

I'm new to java and this was one of the questions my teacher gave me. please tell me if this is correct

20 Upvotes

Question - Write a program to input two unequal numbers.

Display the numbers after swapping their values in the variables

without using a third variable.

Sample Input: a = 76, b = 65

Sample Output: a = 65, b = 76

--------------------------------------------------

 import java.util.*;
public class Q6
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("put number a");
int a=sc.nextInt();
System.out.println("put number b");
int b=sc.nextInt();
System.out.println("a="+b);
System.out.println("b="+a);
}
}

I believe this is correct since it swaps the numbers but I think this might not be accepted as the correct answer in my exams.


r/javahelp • • May 18 '21

Spring Boot: Best way to alert the front end that username already exists when trying to sign up?

20 Upvotes

I have a Spring Boot backend API and a completely separate Angular front end. In the backend if someone makes a POST request to the /register endpoint with an email address that's already in the user repository, I send back a ResponseEntity<String> with the message "User already exists with that email".

The problem is in the Angular front end I'm using this to capture that error

  registerUser(user: User) {
    this.http
      .post(`$apiUrl/auth/users/register`, user)
      .subscribe(()=>{}, err => {
        if (err.status === 409) {
          // do something since account with email already exists
        }
      });
  }

When I do the above, I do capture the 409 error and I'm able to see the "User already exists with that email" message, but it gives a red "POST 409" error in the console. That doesn't happen when you try to sign up with an existing email address on a real website.

Any ideas for a more elegant way of doing this?


r/javahelp • • Apr 18 '21

OOP Project

20 Upvotes

First of all i am sorry if you have a hard time understanding me since English isn't my first language and also i am a beginner so i might have a hard time explaining stuff properly but please bear with me. I am doing an Object oriented programming course this semester using java and i have been assigned the project "Simulating operations of a Museum such as National museum" using oop and our faculty told us to find 5 users and 5 goals for each of the users along with the workflow. And i am having a hard time understanding who will be the core users of a museum and what their goals will be and how i can do those from a software perspective. He gave us an example which might help in Understanding.

He gave example for the users of a university such as faculty, student and admission officer.

User-1: Faculty

Goal-1: Submit grade for a course taken in current semester

Goal-2: Take attendance for the class

Goal-3: Give assignments to students

Goal-4: ...

Goal-5: ...

User-2: Student

Goal-1: Register Course for upcoming semester

Workflow (sequence of background as well as user-initiated events)

e-1: user must login as 'Student'. If login is successful, 

	homeScene of that user will be loaded

	else, ......

e-2: choose 'register course' option. It will:

	\- validate date, time, creditsCompleted, facultyEvStatus, 

		probationStatus, docsPending,... of the student

	\- if validation is successfull, list of offeredcourses applicable to the 

		student will be loaded

else,.....

e-3: select courses one-course at a time. While adding a course need to check:

	\- time clash with already selected courses

	\- capacity overflow

	\- prerequisite done

	\- If retake, rekate policy compliance

	\- ...

	\- repeat e-3 as multiple times
e-4: Proceed for registration. Need to check:

	\- Once again check capacity for ALL selected course

	\- Minimum & Maximum credit range

	\- If paired course, Course+Lab both are selected, 

		or one is completed and the other is retake

	\- Minimum foundation requirement is fulfilled or not

	\- ....

	\- if fails,.....

	

e-5: Commit to database & generate bill

For my project i could think of "Visitor" as a user and the goals would be

  1. Make bookings for the ticket.

What type of bookings would you like?

*Individual tickets For the museum.

*Audio guide bookings.

* Guided Tours- 1h 30- tour with a guide in English or in French.

* Group Tickets for the museum.

2. Explore museums online collection and information

Which section would you like to see?

*The palace?- Divided in 3 places.

*The gardens.

*Our recommended Visitor trails

3. Check out Museum Boutique

What would you like to purchase?

* Snow globe jar-11.90 $

* Winged Victory of Samothrace- 265$

--If purchase- Yes then ENTER

Enter Contact Information-Name, number,Country,etc

Shipping Address...

Continue to shipping or return to cart

4. Become a Member

Are you a current member?Yes-> then would you like to renew your membership?

No then-> become a member

Which package would you like?

Memberships Benefits-

  1. Unlimited entry to exhibitions.

  2. Members room

  3. Members events

  4. Discounts

Membership levels.

Members Count-110

Patron Circles-1500

The Apollo Circle-1200

Choose anyone then is this a gift or buying for yourself?

Enter billing Information.

If you could give me some more insight or advice it would be extremely helpful. Thank you.


r/javahelp • • Apr 12 '21

How can I prevent SQL injection?

20 Upvotes

I have to concatenate the SQL expression because some variable values come from a XML file so that leaves me open to SQL injection. I was thinking of verifiying if the value of the variables is only a single word(if the value doesn't have spaces). Would it be viable?

@Override
    public void execute(Database database) throws CustomChangeException {

        try {
            //check if there are any errors in the changelog file
            checkArgumentsNumber();

            boolean tablesFound = false;
            boolean columnsAdded = false;
            String sqlStatement = "ALTER TABLE NAME ADD COLUMN " +this.getColumnName()+" "+this.getColumnType();

            if(notNull){
                sqlStatement+=" NOT NULL";
            }

            if(defaultValue!=null){
                sqlStatement+=" DEFAULT ?";
            }

            if (this.after != null) {
                sqlStatement += " AFTER " +this.after;
            }

            System.out.println("The statement is: "+sqlStatement);

            //get tables in the database
            JdbcConnection connection = (JdbcConnection) database.getConnection();
            DatabaseMetaData metadata;
            metadata = connection.getMetaData();
            String[] types = {"TABLE"};
            ResultSet rs = metadata.getTables(connection.getCatalog(), null, "%", types);

            //if the user chose to use a regex
            if (this.getRegex() != null) {
                Pattern pattern = Pattern.compile(this.getRegex());

                while (rs.next()) {
                    String tableName = rs.getString(3);
                    Matcher matcher = pattern.matcher(tableName);
                    boolean matches = matcher.matches();
                    if (matches) {
                        tablesFound = true;
                        String addStatement=sqlStatement.replaceAll("NAME",tableName);
                        PreparedStatement s = connection.prepareStatement(addStatement);
                        if (!checkColumnsExists(s, tableName)) {
                            if(this.defaultValue!=null){
                                s.setString(1,this.defaultValue);
                            }
                            System.out.println("REGEX:"+s.toString());
                            s.executeUpdate();
                            columnsAdded = true;
                        }
                    }
                }
            }

            checkInvalidInfo(tablesFound, columnsAdded, "All the matching tables already had that column");
        } catch (InvalidArgumentsNumberException | SQLException | InvalidInfoException | DatabaseException e) {
            throw new CustomChangeException("Error enabling trigger: " + e);
        }
    }

r/javahelp • • Mar 23 '21

Building a POS (points of sale)

20 Upvotes

Hello,

I was asked to build a POS for a personal project and don't really know where to start.

I am a second year Comp. Engineering student and have done multiple code-based projects already but I'm not very familiar with POS.

Questions : How do I get started? Is building a POS a complex/long project ? What language / software should I be running it on? Tips?

Thanks for your help!