/r/learnjava

Photograph via snooOG

Resources for learning Java


Resources for learning Java



  • No JavaScript. Please use /r/javascript instead.
  • No Android. Please use /r/androiddev instead.
  • No MineCraft Please use /r/Minecraft instead.
  • No Processing Please use /r/processing instead.
  • No links to your stackoverflow questions - we are not a second opinion to stackoverflow, nor are you going to get answers here when you didn't get satisfying ones there.
  • No Rewards: You may not ask for or offer payment when giving or receiving help.
  • Do not delete your posts! Deleting is selfish and will deprive others of existing solutions. There might be other people with similar problems who could profit from the discussion in the thread.
  • Do not ask for or reply with solutions as code, nor in plain text, rather comment explanations and guides. Comments with solutions will be removed and commenters will automatically be banned for a week.
  • No PM help requests or offers. Either ask your questions here and show your code, or you're out of luck. PM help requests or offers will be removed without warning.
  • No piracy! We do neither tolerate requests for pirated material, nor do we allow advocating pirated material (even mentioning that you could download commercial products for free is forbidden) - such content will be removed without warning and the poster will automatically be permanently banned from the subreddit.
  • No resource recommendations/promotions outside of the community resources thread Please post any recommendations and promotions of resources such as courses, websites and videos in the bi-weekly community resource thread.

  • Code posting
  • No screenshots of code!
  • Do not submit executable jar or compressed (zip, rar, 7z, etc.) files!
  • For small bits of code (less than 50 lines in total, single classes only), the default code formatter is fine (one blank line, then 4 spaces before each line).
  • Redditlint is a quick and simple code formatter for reddit code. Copy your code into Redditlint, click Format + Copy, and paste the code in your post (remember to leave an empty line above the code!).
  • Pastebin for programs that consist of a single class only
  • Gist for multi-class programs, or programs that require additional files
  • Github or Bitbucket repositories are also perfectly fine as are other dedicated source code hosting sites.
  • Codiva.io or Ideone for executable code snippets that use only the console
  • Repl.it - online IDE for many different programming languages
  • Google Drive, Dropbox, Mediafire, etc. are not suitable for code posting!

Free Tutorials

  • Derek Banas' Java Playlist
  • Marco Behler's youTube channel
  • Hyperskill is a fairly new resource from Jetbrains (the maker of IntelliJ)
  • Dev.java - Oracle's own Java learning platform

  • Where should I download Java?

    With the introduction of the new release cadence, many have asked where they should download Java, and if it is still free. To be clear, YES — Java is still free.

    If you would like to download Java for free, you can get OpenJDK builds from the following vendors, among others:

    Some vendors will be supporting releases for longer than six months. If you have any questions, please do not hesitate to ask them!


    Software downloads

    Official Resources

    Resources

    Programming ideas & Challenges

    Related Subreddits

    /r/learnjava

    152,560 Subscribers

    3

    How to upgrade my Java skills?

    New to this community. I have been working on Java for 3 years now, but mainly using SE6. I am aware of newer features like streams, lambas. What is the best way to learn them? I watched some videos, tried some hands on but don’t feel confident enough. I was wondering if there is a better way to learn by practicing on use cases. What other topics (new features) should I learn? Also some pointers to clear Java interviews?

    6 Comments
    2024/05/05
    14:24 UTC

    4

    Is there a learncpp.com for Java?

    I wonder if there's complete resource such as https://www.learncpp.com/, like a book-tutorial-best-practices-thing

    5 Comments
    2024/05/05
    02:33 UTC

    2

    How can I create a Supplier from a Stream

    I will be retrieving data from a large file (and processing that data) and would like to avoid requerying everytime I needed some data from it. Therefore, I came up with the solution of keeping the data in cache. I would like to convert the stream to a List and make all downstream methods work with the List, but, as per my assignment, I'm forced to work with streams.

    I know a stream can only be consumed once so I thought I would need to "recreate" the stream and then return a Supplier for that "recreation". Below is my bad attempt at that:

    public static <T> Supplier<Stream<T>> cache(Stream<T> src) {
        List<T> cachedList = src.toList();
        return cachedList::stream;
    }

    Thank you in advance.

    3 Comments
    2024/05/04
    23:21 UTC

    1

    Java OOP

    Hi all. I'm sorry for my English. I practice object-oriented analysis.

    Today I wrote a small project in Java.

    I tried to apply and follow the principles of OOP, although I won’t say that everything is perfect.

    Can you check my code and point out my main mistakes? And please be ruthless. It is very important for me.

    I forgot to add the full requirements to the project, but specified them in the main class.

    And yes, I forgot to add the project script. By project scenarios I mean how the program should work. I don't know what the IT people call them. Thank you in advance.

    https://github.com/Yelzhaas/firstProject

    8 Comments
    2024/05/04
    20:06 UTC

    3

    Can't add css file to javaFx app

    This is path to java file: src/main/java/webpagesbuilder/core/WebPageBuilder.java

    This is path to css file: src/main/resources/styles.css

    Output: Resource not found. Aborting.

    This is code inside java file:

    Scene scene = new Scene(root);
    URL url = this.getClass().getResource("/resources/styles.css");
    if (url == null) {
    System.out.println("Resource not found. Aborting.");
    System.exit(-1);
    }
    String css = url.toExternalForm();
    scene.getStylesheets().add(css);
    stage.setScene(scene);
    stage.show();

    This is code inside css file:

    .addContentButton{
    -fx-pref-height: 74;
    -fx-pref-width: 108;
    -fx-background-color: #FFFFFF;
    -fx-effect: dropshadow(three-pass-box, rgba(0,0,0,0.6), 5, 0, 0, 1);
    }
    .addContentButton:hover{
    -fx-effect: dropshadow(three-pass-box, rgba(0,0,0,0.6), 15, 0, 0, 1);
    }
    7 Comments
    2024/05/04
    11:14 UTC

    2

    Error while trying to run the TMC Settings in NetBeans

    Hi, I was trying to put TMC on NetBeans to start the MOOC course, only when I try to open the TMC Plugin settings, it gives me the following error:

    java.lang.NullPointerException: No 'delegate' in BinaryFileMap@4ce6a990{fo=MultiFileObject@2004f3c6[Actions/TMC/fi-helsinki-cs-tmc-actions-ShowSettings.instance]}

    could you help me solve this problem? thank you in advance

    8 Comments
    2024/05/04
    09:55 UTC

    8

    Tutorial: Spring AI app with web UI 100% in Java (4 min)

    I've had many Java developers ask me how to get started with AI in their Java apps, so I put together this quick tutorial that shows you how to set up Spring AI and build a simple web app for interacting with ChatGPT 100% in Java. I'm hoping it's a good starting point for a hobby project or just playing around with AI.

    4 min video tutorial: https://www.youtube.com/watch?v=cfm5wtgpf0k

    (Hope it's ok to post a tutorial here as there doesn't seem to have been a community resources thread in quite a while.)

    6 Comments
    2024/05/03
    22:27 UTC

    12

    What skills did you possess when you secured your initial position as a software engineer?

    With so much to learn, I'm feeling overwhelmed. It's challenging to prioritize what to learn and determine the depth of knowledge required for each topic.

    17 Comments
    2024/05/03
    19:29 UTC

    1

    Related to Java 11 and TMC (I have read the pinned post but I have other problem Rather than the mentioned one).

    The problem is that I have java 8 downloaded already on my system I have been using bluej for java programs and I also play Minecraft, so my question is that after downloading another version would it affect my game or programs that I have earlier written on bluej??

    Any help would be appreciated.

    2 Comments
    2024/05/03
    18:57 UTC

    1

    It seems that Comparator doesn't work on java stream, while it works with method Collections.sort

    Good morning everyone!

    I was making the code for this method called ordersWithStatus(). The method should return informations about the orders. Such method returns a String obtained by concatenating all orders satisfying the criteria:

    1. Only orders with a given status passed by argument to the method
    2. The orders have to be sorted by: restaurant name, customer's first name, customer's last name, delivery time.

    I don't understand why the method using the stream (the commented one) doesn't work, but the other one using Collections.sort() works. Expected: Napoli, Judi Dench : (19:00): M6->1 Napoli, Ralph Fiennes : (19:00): M1->2 M6->1 But was: Napoli, Ralph Fiennes : (19:00): M1->2 M6->1 Napoli, Judi Dench : (19:00): M6->1 I noted that using the stream, it seems that the method doesn't sort the output, it prints Ralph Fiennes first and then Judi Dench. What am I doing wrong with the stream? Could you please help me ?

    Here is my code:

    	/**
    	 * Retrieve all order with a given status with all the relative details in text format.
    	 * The list is sorted by name of restaurant, name of the customer, and delivery time.
    	 * @param status the status to be matched
    	 * @return textual representation of orders
    	 */
    	public String ordersWithStatus(OrderStatus status) {
    	/* 	
    		Set<String> outputSet = this.orders.stream()
    		.filter(o->o.getStatus()==status)
    		.sorted( Comparator.comparing(Order::getRestaurantName)
    		.thenComparing(Order::getCustomerName1)
    		.thenComparing(Order::getCustomerName2)
    		.thenComparing(Order::getTime ))
    		.map(Order::toString)
    		.collect( Collectors.toSet() );
    
    		String output = "";
    
    		for (String order : outputSet){
    			output+=order;
    		}
    		return output;
    */		
    		// Pulling out each comparision step into a local reference
    		Comparator<Order> byRestaurantName = (o1, o2) -> o1.getRestaurantName().
    		compareTo(o2.getRestaurantName());
    		
    		Comparator<Order> byCustomer1name = (o1, o2) -> o1.getCustomerName1().
    		compareTo(o2.getCustomerName1());
    		
    		Comparator<Order> byCustomer2name = (o1, o2) -> o1.getCustomerName2().
    		compareTo(o2.getCustomerName2());
    		
    		Comparator<Order> byTime = (o1, o2) -> o1.getTime().
    		compareTo(o2.getTime());
    		
    		List<Order> tempOrders = this.orders.stream().
    		filter(o->o.getStatus()==status).
    		collect(Collectors.toList());
    		
    		Collections.sort(tempOrders,
    		 	byRestaurantName
    			.thenComparing(byCustomer1name)
    			.thenComparing(byCustomer2name)
    			.thenComparing(byTime));
    
    		String res = "";
    		// for each order in the sorted orders list
    		for (Order order : tempOrders){
    			res+=order.toString();
    		}
    
    		return res;
    	}
    5 Comments
    2024/05/03
    09:59 UTC

    10

    Java streams

    I am trying to understand Streams from MOOC.fi part 10

    In the spot that is ".filter(number -> number % 3 == 0)" How does it know what the second number means? I assume that it knows that the first one is its new stream, but how does it know what the second one is?

    In ".mapToInt(s -> Integer.valueOf(s))" does the 's' in valueOf(s) just mean the stream i assume?

    In the working out the average section, how does it know what it is executing 'getAsDouble()' on?

    while (true) {
        String row = scanner.nextLine();
        if (row.equals("end")) {
            break;
        }
    
        inputs.add(row);
    }
    
    // counting the number of values divisible by three
    long numbersDivisibleByThree = inputs.stream()
        .mapToInt(s -> Integer.valueOf(s))
        .filter(number -> number % 3 == 0)
        .count();
    
    // working out the average
    double average = inputs.stream()
        .mapToInt(s -> Integer.valueOf(s))
        .average()
        .getAsDouble();
    12 Comments
    2024/05/02
    21:13 UTC

    3

    How choose direction in which go? (Not what I should learn question)

    I finish mooc java, and now I need to choose in which direction go: android development, web development or banking sector. Like of course u need different things to learn to get into each direction, but after all u still will write code, so there would be not much difference, and I should basically go in that sector which most demanded in my area, or I miss something?

    4 Comments
    2024/05/02
    14:06 UTC

    9

    Udemy: 45 Real World Java Development Projects Bootcamp Course 2024. Is it worth course to buy ? I want to start adding real projects to my portfolio.

    Here is link

    3 Comments
    2024/05/02
    06:21 UTC

    12

    Understanding the Purpose and utility of Static Methods: Why they exist in first place?

    Hey all,

    I'm learning Java and scratching my head over static methods. We've got regular methods and private methods, so why do we need static ones? What's the point?

    If you're a Java whiz, I'd love to hear your take. How do you use static methods? Any examples or tips to share for us beginners?

    9 Comments
    2024/05/02
    03:23 UTC

    6

    Spent a few years as an automation engineer (java selenium), what would you recommend me to do to become a developer

    Background: 8 years combined of testing (4 years manual, 4 years selenium automation)

    I want to gain some more stability and skills and would love to become a developer. I am just barely intermediate in java as I use as much as I need to in order to create selenium scripts and maintain repositories.

    1 - Since I have some experience in java, should I continue learning it to a more expert level and apply for junior developer positions?

    2 - Is Java the best language to learn in todays developer world?

    3 - I've started the MOOC courses on java in my off time and follow java bro code on youtube. Are these still considered great resources?

    5 Comments
    2024/05/02
    00:39 UTC

    7

    Can anyone recommend a podcast about Java, particularly the history of it?

    Looking for something to listen to at the gym

    4 Comments
    2024/05/01
    23:25 UTC

    1

    Difference between Oracle Certified Professional, Java SE 8 Programmer and Oracle Certified Professional: Java SE 17 Developer

    Hi everyone,

    I want to get certified in Java. Although I hold a 7 years of experience in IT industry but being new in states, I am struggling to get interview calls and clearing interviews. So I thought of adding some weightage to resume as well as this will help me clearing the interviews also. So, I am quite confused, which certification should be a better fit? Java SE 17 seems latest but how difficult and challenging will it be as compared to Java SE 8. Also, does curriculum of Java SE 17 include all the topics that were covered in Java SE 8 or is there any difference ? I thought the only difference should be the new features that were added in Java 17.

    Need some advices!

    4 Comments
    2024/05/01
    16:45 UTC

    2

    I'm new to vscode and I need to know something

    Hi, I'm new to vscode, I used Eclipse but now my college wants me to use vscode.
    I was writing java code and I need to see how the whole Comparable interface works, how can I open the interface?
    I tried to do right click on "Comparable" after I wrote "MyClass implements Comparable" and try all the "go to" options but It didn't work... Could you guys help me pls?

    8 Comments
    2024/05/01
    10:21 UTC

    10

    is Head first Java good book for beginners?

    I have been researching Java books for beginners, and I have found the head first Java, what is your opinion and is there any other good book for Java for beginners?

    18 Comments
    2024/05/01
    09:39 UTC

    0

    Springboot course

    Course concepts explanation is really awesome, author explains it really well, and motivates also

    course name : Master Spring Boot 3 & Spring Framework 6 with Java
    Author : Ranga
    https://www.udemy.com/course/spring-boot-and-spring-framework-tutorial-for-beginners/learn/lecture/35020010#content

    7 Comments
    2024/04/30
    18:29 UTC

    1

    PKI certificates, apiKeys, Keystore

    Hi, I want to read about what certificates are, how are they used. What is a keystore? What are API Keys ans how are they used?

    I have been given a task of Extranalizing certificates. Please can you share some resources or recommended me a good resource/course to study from. I am using springboot and openshift.

    Thanks.

    5 Comments
    2024/04/30
    12:36 UTC

    3

    Book of exercise for learn MVC and MVVC arquitecture with java?

    Someone knows some books with java exercise good for learnt MVC?

    3 Comments
    2024/04/30
    09:33 UTC

    10

    Is jsp worth learning in 2024?

    If you were in my place, would you have learn jsp and servlets? Currently I have hands on experience and learned core java, swing, javafx, Jdbc and mysql and currently learning Hibernate. My main aim is to learn spring or springboot so should I learn need to learn jsp? Also There aren't any resources on yt regarding jsp as of current scenario

    38 Comments
    2024/04/29
    11:15 UTC

    2

    What libraries do you use when doing a Java interview web server coding challenge?

    I'm relatively new to Java and while I have a solid idea of what is used in enterprise at work, I'm not sure what "best practice" is for using Java in a coding challenge.

    Is it just about using the libraries that are most concise and considered "bleeding edge"? Do you just use Spring and other libraries which are considered entreprise "standard"?

    What are your thoughts on this, if not instruction is provided on what libraries to use to build the instructed API.

    4 Comments
    2024/04/29
    09:47 UTC

    2

    Confusion in One to many relationship between two entities

    Employee has a one to many relationship with Address.

    To save the Address entity, I have to pass an 'Employee' object to address.setEmployee(). To map an existing Employee object to a new 'Address' object, first I would need to fetch that Employee object from db and then give that object to address.setEmployee(). This would require a GET (to fetch employee object) and a POST (save the address object).

    I want to skip the GET operation and I want to give 'Long empId' instead of the Employee object to address.setEmployee(). But this doesn't implement the one to many relationship between the 2 entities as I can't see the foreign key column in the Address table.

    Is giving empId instead of Employee object to address's setter method a good practice? If not, then how can I skip the GET operation to fetch the existing Employee object?

    TLDR: I want to do adress.setEmployee(Long empld) instead of address.setEmployee(Employee emp). Is this a good way to implement one to many relationships between 2 entities?

    Edit: I asked chatgpt the same. It is repeating the same thing again and again when asked about the other approach (Setting empId instead of emp instance).

    10 Comments
    2024/04/29
    06:32 UTC

    8

    Java developers, how do you decide what to learn next to advance your career?

    Hey! I have four years of experience as a Java developer. I feel like I have stagnated in my learning in the Java ecosystem. I don't know what to learn next. Often in my job, I acquire domain-specific knowledge, but I find myself implementing the same things repeatedly (such as REST APIs). What should I be learning to advance my career as a Java developer?

    Recently, I have started learning about AI/ML, and I realized that I am truly enjoying learning something new. However, I do not envision using these skills in my current job, and I am a total beginner in this field.

    My goal is to advance my career and increase my income. I feel lost and can't decide what to learn next. Ideally, I want to capitalize on my existing Java skills. Do you have any advice for me?

    7 Comments
    2024/04/28
    17:23 UTC

    0

    Unable to interact with Java program, input prompt not appearing, using Android studio as a ide

    Hi I created a Java module in Android studio because I don't have any other ide to learn Java programming. I wrote a code to take input from user and the code is executed successfully but console is not giving a prompt to take input and give exception in thread "main" Java.util.NoSuchElementException: No line found

    Code snippet: package com.example.javalib;

    import java.util.Scanner;

    public class JavaClass {     public static void main(String[] args){         System.out.println("Standand output stream statement");         Scanner input = new Scanner(System.in);         String userInput = input.nextLine();

            System.out.println("You entered: " + userInput);

        } }

    Error: successful

    :Javalib:compileJava

    :Javalib:processResources

    :Javalib:classes

    :Javalib:JavaClass.main()

    Process 'command 'C:/Program Files/Android/Android Studio/jre/bin/java.exe'' finished with non-zero exit value 1 

    2:07:30 PM: Executing task 'JavaClass.main()'...

    Executing tasks: [JavaClass.main()] in project C:\Users\AndroidStudioProjects\MyApplication2

    Task :Javalib:compileJava Task :Javalib:processResources NO-SOURCE Task :Javalib:classes

    Task :Javalib:JavaClass.main() FAILED

    Standand output stream statement

    Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0. Use '--warning-mode all' to show the individual deprecation warnings. See https://docs.gradle.org/7.0.2/userguide/command_line_interface.html#sec:command_line_warnings 2 actionable tasks: 2 executed Exception in thread "main" java.util.NoSuchElementException: No line found at java.base/java.util.Scanner.nextLine(Scanner.java:1651) at com.example.javalib.JavaClass.main(JavaClass.java:11)

    FAILURE: Build failed with an exception.

    • What went wrong:

    Execution failed for task ':Javalib:JavaClass.main()'.

    Process 'command 'C:/Program Files/Android/Android Studio/jre/bin/java.exe'' finished with non-zero exit value 1

    BUILD FAILED in 973ms 2:07:32 PM: Task execution finished 'JavaClass.main()'.

    3 Comments
    2024/04/28
    14:46 UTC

    5

    JSoup and Google

    Hey guys, I wasn't sure whether to post here or the regular /java page.

    I am creating my final assignment for my applied mathematics degree, the goal of the assignment is to create a simple gui which has a search bar, the search bar scrapes images obtained from that keyword. I have found examples simply using jsoup, but theres several warnings that automatically accessing google can result in a permaban on my ip address.

    So that led me to the google search api's. The problem with this, it directly contradicts one of the assignment requirements of using an html parser such as Jsoup.

    Is the permaban using scraping really a thing? I find mixed results when searching that. Is there a way to access the html while still using a google api? Any help or feedback would help greatly.

    4 Comments
    2024/04/28
    11:08 UTC

    3

    I want to build a basic interactive map desktop application. Would this be difficult in Java?

    Hello reddit, I am a first year programming student with very basic knowledge of Java and Python (basically most of what's covered in the W3schools Java tutorial).

    For one of my uni assignments, I need to create an diagram of a country's trade imports/exports. I could make it out of still images, like a slideshow presentation, but that would be boring. I wanna impress them. So I'm thinking of making an interactive map, which shows a map of the entire country and all the trade routes etc. but then you can click on things (for example one of the routes, or one of the shipping ports) and a pop up will show with some extra information about it. That's probably not too hard, but if possible I'd also like to animate the ships as dots, so you can see them physically travelling on the map. No idea how to do that.

    I looked up a few online interactive map generators, but they don't allow for animation, also they're not free. Then I looked up what I can use with Java, apparently there's a module (or package?) called Swing that can do basic GUI desktop applications? Sounds interesting but I've only got 2 weeks til my uni assignment is due. Can anyone tell me if Swing would work well for this? Or is there something better? Thanks.

    9 Comments
    2024/04/28
    06:16 UTC

    0

    Just started program

    Hello all, I have just started programming and currently programming in Java. My college have ended and haven't got placed. How much time I would required to get a job actually. Also which particular thing I should learn first, also suggest me some hack to get into that programming mindset. It would be really helpful for y'all if you assist me with this.

    3 Comments
    2024/04/28
    04:27 UTC

    Back To Top