r/javahelp • • Jul 22 '19

Which way of authentication is better and safer for Angular 8 with Spring Boot backend?

17 Upvotes

So, I searched the web and I found two popular ways to do it.

The first one is in the official Spring documentation: https://spring.io/guides/tutorials/spring-security-and-angular-js/

Second one is an Auth0 blog post: https://auth0.com/blog/implementing-jwt-authentication-on-spring-boot/

Both are outdated a little. The first maybe safer, because it is official, but seems a little complicated. The second one is using JWT, which is so popular.

What do you think, which way would you do and why?


r/javahelp • • Jul 19 '19

Java for Beginners

17 Upvotes

Are there any recommended communities here on reddit for a person who is just beginning to learn the java language?


r/javahelp • • Jul 12 '19

Understanding java concept of instantiating list of list of integers object as an arraylist

17 Upvotes

What is going on in this instantiation of List<List<Integer>> p = new ArrayList<>(); I forgot what this concept was called so googling didn't give good answers. I understand the left side part of it, literally saying what p is but not the right hand side part. Why wouldn't it be new ArrayList<ArrayList<>>(); ?


r/javahelp • • Jun 22 '19

do professional java applications use swing form designer to create GUI ?

17 Upvotes

I mean do softwares likes InteliJ which are made in Swing , code all GUI in code manully ?? or they use GUI desiner with like one provided with InteliJ with Drag-and-drop ??


r/javahelp • • Jun 17 '19

Is javax.swing still being used? If not, What would be an alternative?

17 Upvotes

It's been a while since I've worked on desktop after switching to Android. Just curious if there are any developers still use Swing, or what is being used instead.


r/javahelp • • May 29 '19

Best way to manage service layer and error handling in Java Spring?

17 Upvotes

Hey guys, I have an implementation question about the service layer in a Java Spring application. We are using the repository design pattern.

In the past, I would have the service layer make calls to the repository, handle mapping the returned entities to DTOs, and then return the DTO or list of DTOs from the service layer and put them in the payload in the controller.

However, at my current job everybody wraps the response from service layers in a result class. This result class includes the possible data of a generic type, as well as some fields like "hasError", "errorMessages", and "statusCode".

My question is, is this best practice? Would it not make more sense to use something like @ControllerAdvice in Spring, and throw an exception with an associated status code?

I think they did this because they wanted the response to always be the same structure, whether or not there was an error. However, I think it might be better practice to just look at the status code that is returned, and make a decision based on that. "errorMessages" and the other fields could just be included in the exception class.

I am curious your guys thoughts on this. I have found many examples using springs error handling tools, but no examples yet that use this wrapper result pattern.


r/javahelp • • May 08 '19

How to make program usable across multiple computers?

17 Upvotes

I want to eventually compile my program into a .jar file. And ideally, I would also make .exe/.app versions so that people (specifically my grandparents and less tech oriented friends lol) can try it without having java.

I'm working on both Ubuntu and Windows, and when I switch back and forth I need to repath my images. My program ultimately needs to work on a windows computer for my final project. But I am worried because my path applies only to my computers. Our teacher recommended that we compile our program into a .jar file so we dont have to worry about little complications beforehand.

Once my program is saved into a .jar file, will I need to worry about the paths still? Sorry, I'm super naive and have not done this before.


r/javahelp • • Mar 20 '19

Backend-development tutorials for JAVA where to find great updated tutorials 2019?

17 Upvotes

Because Java is still the best and most used programming language I would like to update my knowledge and learn more about the state of the art Java programming in 2019. Do you know of any updated tutorials on Java today? That is clear and well-formatted. Looking for good and simple tutorials on Java that covers everything for backend-development.


r/javahelp • • Nov 05 '18

Handling libraries in Java (confused python programmer)

17 Upvotes

I usually code in python where downloading libraries is conveniently handled using pip or anaconda. Installing libraries is not more complicated than running a single command in the terminal.

However just starting out with libraries in Java I find myself bewildered on how to download libraries in a convenient way... So far I've tried just downloading JAR-files from my browser manually but that isn't very efficient. I've tried looking into Maven but found it a bit confusing and I'm not even sure that's where I should be looking?

Any help is appreciated!


r/javahelp • • Jul 27 '18

I want to automate my tinder account using Java. How to do it?

17 Upvotes

I am in the process of learning Java and want to take on this project. There are many resources for python but I want to get experience with Java. I could not find many resources. Any advice?

end goal: Face recognition, automating messages (chat bot), storing phone numbers.


r/javahelp • • Feb 18 '17

Which Frameworks to use to build a REST backend in Java?

17 Upvotes

Hi,

I would like to build a REST backend in Java for a software that has multiple front ends (Angular 2, Cli and APIs in other languages). The backend doesn't need to be "web-scale" as it is only used in intranets.

From my research so far, I understand that there is:

  • The Spring framework (and related stuff like Spring Boot that you need in order to use it productively)

  • The Play framework (which seems to be newer, cooler and better in general, but is actually a Scala framework .. so as a Java user, I might not have the best experience)

These two solutions are pretty fat, as they are both full blown web frameworks with many features I don't need for my goal (templating engine or incremental rebuilds for example).

I wonder if it is not better to implement the REST-backend using:

Assembling everything myself allows me to use whatever build system I want to use (Maven instead of sbt (Play forces me to use sbt)), and I know how everything in my application is put together (one less framework to learn).

Who has done this before and provide me some guidance?

Thank you!


r/javahelp • • Dec 08 '15

Unsolved Game developer here: Anyone set up a java game in Steam app admin?

17 Upvotes

Hello Community,
I'm not sure if this is correct subreddit, hope I don't break any rules.. I'm working on a Java game which was Greenlit on Steam a few months ago and Im very close to releasing it (~2 weeks). I'm having troubles with setting up the launch configuration for my game in Steam and while I've set up the config for windows easily (since I use windows myself), I have problems with Mac and Linux.
On windows the Steam can runs the game properly if I define the exectuable as 'Game.jar' or a .bat file which runs 'java -jar Game.jar'. I've got testers which have Linux and Mac, but they cannot help me with providing a proper solution for their OS and I don't want to bug them for an hour each and ask "this works? and now? how about that?". So the question is, if anyone has experience with this, what kind of script could I upload to run the .jar for Mac and Linux, or how could I configure Steam to launch the jar properly? I googled a bit but I've learned that it's not that straightforward with running scripts on Mac and Linux as it is with Windows .bat.


r/javahelp • • Nov 30 '14

I start a job as a Java developer in 6 months! What advice do you wish you had known going into the field?

17 Upvotes

I'm a student about to graduate from college and after a successful internship got a job offer. I'm not entirely sure what I will be doing until they create the dev teams but I know I will for the most part be coding in Java. I'm just looking for any general advice I probably haven't heard in my classes and would like to hear what any experienced professionals suggest I learn to better prepare for the real world.

Edit: thanks a lot to everyone for the positive feedback, I will take all of your advice to heart! Luckily nothing suggested far has been totally unheard of to me, so I hope that means I'm off to a good start! :)


r/javahelp • • Mar 26 '14

What Java blogs do you read?

17 Upvotes

I am trying to find a good reading list of Java blogs. Are there certain ones you go to daily to check out?


r/javahelp • • Jun 19 '13

When would I use interfaces?

17 Upvotes

I've recently learned about interfaces, but when would I actually use them? Thanks!


r/javahelp • • Sep 28 '24

Java and dsa is too hard..

16 Upvotes

I'm a final year student pursuing bachelor's in tech, I picked java as my language and even though its fun, its really hard to learn dsa with it.. I'm only at the beginning, like I only know some sorting methods, recursion, arrays and strings. For example, a simple java program to find the second largest element in an array is confusing to me. And I don't have much time to learn it because my placements are ongoing and I need to get placed within this year. If I go with python to learn dsa, will it be easier? And use java for web development and other technologies ofc.


r/javahelp • • Apr 22 '23

Should we prefer validation in the constructor over external validation?

16 Upvotes

This is more of a "discussion"/"asking for opinions" post, but since /r/java is so strict on what they allow, I'd thought I'd better ask here.

In a typical Java web application, we treat validation of incoming objects (for example, deserialized JSON) as an external step. By "external" I mean that the validation logic is a separate step to creating the object. For example, using the Jakarta validation API:

class User {
  private firstName;

  @NotNull @NotBlank
  private lastName;

  // getters/setters omitted
}

We could also make the class immutable and place the validation annotations in the constructor, but the point is that I can create an object while bypassing these validations.

Not a problem in a REST controller (unless you forgot the @Valid annotation and have no tests), but for example in test code you can freely create objects that violate these requirements. This has some problems:

  • the tests are less documenting. A new ISBN("I don't care") doesn't show me what a real-world ISBN number would look like.

  • Adding perfectly valid application code relying on validated properties can make tests fail that use arbitrary data. Let's say I expect an ISBN to have exactly 10 or 13 digits, and add code that does a substring() on that without a range check. If I create an object that violates this property in my test, the new code may fail.

And if you were as paranoid as the Secure Coding Guidelines for Java, each public method in each layer in your application would have to perform the validation again.

With Java putting more and more emphasis on integrity and strong encapsulation, and examples about adding validation logic to constructors like in the record JEP, I was wondering whether our approach to validation is flawed. Not having a blank "lastName" is an invariant of User, something that we should be able to rely on in every place where an instance of User is used.

So why not put validation into the constructor? For example, using a validation API like in this made-up example by ChatGPT:

public record Person(String name, int age) {

    public static final Validation<String> NAME_VALIDATION = Validation.of(new NotEmpty("Name cannot be empty."));
    public static final Validation<Integer> AGE_VALIDATION = Validation.of(new Min(0, "Age cannot be negative."));

    public Person {
       NAME_VALIDATION.validate(name).throwIfInvalid(IllegalArgumentException::new);
       AGE_VALIDATION.validate(age).throwIfInvalid(IllegalArgumentException::new);
    }
}

This prevents me from ever creating a new Person("John", -42). (The example API ignores concerns like localizing error messages, capturing the name of the field, etc. – it's just an example.)

So, what do you think?

Drawbacks I can see with this approach:

  • when adding a new constraint, old, unmigrated data in the database would not be mappable to the object. This can be solved by having different classes at API, core, and persistence layer, but you'd have to duplicate validations (or don't do them in all places).

  • you can only use self-contained validations in the constructor. If I want to check for example if a country code is in a list of codes I retrieved from a code dictionary service, I would either have to do this externally, or pass the list of valid codes to the object on construction, for example via a static factory method, which doesn't sound like clean code.

  • Theoretical performance impact by repeating validation when creating a copy, but I trust the JIT compiler in the JVM to inline as much as possible and optimize using predictive branching.


r/javahelp • • Mar 09 '23

if I want to make a 2D game, which one of Javas built-in libraries are best?

16 Upvotes

I'm learning so I want to use one of the ones built-in to Java


r/javahelp • • Jul 24 '21

Unsolved [Concurrency] What will you do if multiple users access your application at the same time?

16 Upvotes

I'm an experienced Software Engineer but very weak in concurrency because of no prior experience in that. I've been interviewing with several companies in which I was asked similar kind of questions as given below:

  1. If you are designing a fantasy sports application in which there's a contest which can handle only 100 users. If 99 users are already registered for the contest and multiple users hit the PARTICIPATE button at the same time to become the 100th user, then how will you handle this in your application?

  2. If you are designing a chess game, where multiple users are selecting the users of same level of competence to play with them. Then suppose at same time, users A and B choose the user C (to play with) at the same time, then how will you handle this?

I usually answer this by saying that I'll use synchronized block in Java or on Database side, I'll use Locking concept. But I'm not sure of either of them. So, can anyone tell here how do you answer such questions? Should one answer this in terms of Java Multithreading or DBMS or both? Please can anyone also tell me any resources to understand the theory to answer such type of questions or any website or YouTube channel where solutions are given to these kind of questions?


r/javahelp • • May 20 '21

Which udemy course for Microservices?

16 Upvotes

I want to learn about microservices but I can't decide between these two courses. Does anybody have experience with either of them? One is from in28minutes the other is from John Thompson (Spring guru)

  1. https://www.udemy.com/course/microservices-with-spring-boot-and-spring-cloud/

  2. https://www.udemy.com/course/spring-boot-microservices-with-spring-cloud-beginner-to-guru/


r/javahelp • • May 13 '21

Unsolved How to get information from the screen

16 Upvotes

Hey everyone! So I was messing around with java and I was wondering how you would get java to scan the computer screen for a specific color. Would you use a imported util or do you have to download something? Thanks!


r/javahelp • • Apr 03 '21

Solved Why does accessing an Arraylist from another class gives me an exception?

16 Upvotes

Now I know this is a very common issue, because I've seen many posts about on Stack, but I couldn't get those answers to work with my code. This is my code, shortened down to the relevant parts:

public class SeznamJedi {
    ArrayList<Jed> seznamJedi;

    public void addJed(String a, String b, double c){
        Jed toAdd = new Jed(a, b, c);
        seznamJedi.add(toAdd);
    }

    public int getSize(){
        return seznamJedi.size();
    }
}

^ This is my class, whose only purpose is to hold a list of Jed objects.

public class App extends Application {
      public SeznamJedi seznamJedi;

    @Override
    public void onCreate(){
        super.onCreate();
        seznamJedi = new SeznamJedi();
}

^ This is my App class, used to hold my global list of objects.

public class
MainActivity extends AppCompatActivity {
    App app;
    SeznamJedi tempSeznam;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        app = (App)getApplication();
        tempSeznam = app.seznamJedi;
        tempSeznam.addJed("h", "b", 12);
    }
}

^ And this is my MainActivity. The whole app crashes when I add the Jed object. Clearly it's not happy with me accessing the list and it's not allowing me to do any operations on it. I am at a loss and any help will be greatly appreciated.


r/javahelp • • Feb 01 '21

I think my teacher is wrong about checked and unchecked exceptions?

16 Upvotes

I’m not sure this is the right place to post this, but I feel like I’m going crazy so I’d appreciate any input you can give me. And just to qualify at the start here— I’m planning on just letting this one go. I can do it the way they want it for the course of the class. I don’t think I have anything to gain from making a big deal out of it.

Anyway, my understanding of checked exceptions is that they are the exceptions of the Exception superclass which are not subclasses of RuntimeException. They have the catch or specify requirement. As such, they are the exceptions we use try-catch blocks of code for. If I’m already wrong feel free to skip the rest and shame me in the comments.

That said, my teacher has been very firm that unchecked exceptions are the ones we use try-catch blocks for. I sent them an email with a link to the oracle Java tutorials that’d seemed to back up my understanding of things. At the very least, I was hoping for some guidance on why I might have misunderstood the page I linked or if there was a better place to get my supplemental information. The reply email I got just restated what I shared with you above.

Am I crazy??? I just need a little validation here. I am a novice so I’m not assuming I am more knowledgeable. However, I seem to have two conflicting sources here (the teacher and the internet) and it’s giving me a bit of anxiety. Any help you can give me would be appreciated.


r/javahelp • • Dec 02 '20

Hibernate: Does it eventually use SQL somewhere that I can see?

16 Upvotes

I'm debugging a massive application that uses Hibernate, which I am not familiar with.

I'm trying to find out why the application ( many confusing layers above Hibernate ) is sending out error messages about there being no data, when I can see the data in the database ( Postgres ).

Does Hibernate eventually somewhere deep down make SQL queries that I can see? Some other commands I can see such that I can learn what it is asking for so I can tell why it isn't finding it?