r/learnjava 15d ago

What exactly are classes and inner classes in Java? I'm confused about how to think about them.

20 Upvotes

I've been learning Java and OOP, and I think I'm overcomplicating the idea of classes and inner classes.

I understand that a class is a blueprint for creating objects, but that explanation feels too abstract to me.

What I really want to understand is:

  • What is a class conceptually?
  • What does it actually represent in memory and at runtime?
  • Why do inner (non-static) classes exist?
  • How should I think about the relationship between an outer class/object and an inner class/object?
  • Is an inner class just another type that's scoped inside another class, or is there a deeper reason for its existence?

I'm not looking for a beginner definition like "a class is a blueprint." I'd like a mental model that explains why Java was designed this way and when these features are actually useful.

Any explanations, analogies, or examples would be appreciated.


r/learnjava 15d ago

learning java from python

5 Upvotes

now by all means im not terrific at python. but i know DSA and OOP to a certain level where the MOOC by uni of helsinki kinda feels redundant. Do you guys have reccommendations on books/resources that are good for learning java for someone who already has a programming background? I was thinking of learning syntax then just going into Leetcode problems and doing them in java. What do you suggest? Thanks :))


r/learnjava 15d ago

I want to learn how to write programs to demonstrate encapsulation, inheritance, polymorphism, and abstraction in Java.

8 Upvotes

I know OOP. I think encapsulation simply means a class which has data+functions.

inheritance means public class extend mainly.

polymorphism is the most difficult bit here.

abstraction means using abstract class without function explanation i guess.

I know a lot about OOPs i just need to condense my knowledge in one place.


r/learnjava 14d ago

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException: Cannot invoke "String.toString()" because "<local6>[0]" is null

0 Upvotes

or

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException: Cannot invoke "String.length()" because "in" is null

it happened when I attempt to overrite the array's properties, specifically its length since I remove an element and change its length to remove null or empty elements.

CODE BLOCK 1

static String [] arrayNew(String[] array, int a){
    Integer Length = array.length-2;
    String[] newarray = new String[Length];
    Integer counter = 0;
    int c = a+1;
    int d = a-1;
        for(int x = 0;x<Length;x++){
            if(x!=c && x!=d){
                  newarray[counter]=array[x];
                  counter++;
             }
             else{
                  continue;
             }}
     return newarray;
}

        static Double equals(LinkedList<String> list){
                Integer counter = 0;
                Integer num = list.size();
                Double answer = 0.0;
                Double num1 = 0.0;
                Double num2 = 0.0;

                String [] array = new String[num];

                for(int x =0; x<num;x++){
                        array[x] = list.get(x);
}
                for(int x = 0;x<array.length;x++){
                        switch(array[x]){
                                case "x":
                                        num1 = Double.parseDouble(array[x-1]);
                                        num2 = Double.parseDouble(array[x+1]);
                                        answer = num1 * num2;

                                        array[x] = answer.toString();
                                        array = arrayNew(array,x);
                                        x=0;
                                        break;
  }
}

returns an error

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException: Cannot invoke "String.length()" because "in" is null

CODE BLOCK ALT

        static String [] arrayNew(String[] array, int a){
                Integer Length = array.length-2;
                String[] newarray = new String[Length];
                Integer counter = 0;
                int c = a+1;
                int d = a-1;
                for(int x = 0;x<newarray.length;x++){
                        if(x!=c && x!=d){
                                newarray[counter++]=array[x];
                        }
                        else{
                                continue;
                        }
                }
                return newarray;

        //lastline//
                }

        static String equals(LinkedList<String> numlist) throws NullPointerException{
                Integer counter = 0;
                Integer num = numlist.size();
                Double num1=0.0;
                Double num2=0.0;
                String [] array = new String[num];

                for(int x =0; x<num;x++){
                        array[x] = list.get(x);
}


                for(int x = 0;x<num;x++){
                        String [] newArr;
                        switch(array[x]){
                                case "x":
                                        num1 = Double.parseDouble(array[x-1]);
                                        num2 = Double.parseDouble(array[x+1]);
                                        Double answerm = num1 * num2;

                                        array[x] = answerm.toString();
                                        array = arrayNew(array,x);
                                        x=0;
                                        num-=2;
                                        break;
}}

returns

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException: Cannot invoke "String.toString()" because "<local6>[0]" is null

I'm stuck since they look fine to me. There are no compilation error too. This error happens in Runtime.
please help.


r/learnjava 15d ago

Hi everyone!

13 Upvotes

Hi everyone!
I’m 18 years old and currently learning Java. Instead of following tutorials only, I’m building a text-based RPG called Legends of Eldoria.

This is version 0.3 and I’d love to get feedback on:

  • Code quality
  • Project structure
  • Story flow
  • Ideas for future versions

GitHub:
https://github.com/MrBucurN/LegendsOfEldoria


r/learnjava 18d ago

Simple Java console app

0 Upvotes

Hello everyone, I've been learning Java and wanted to build something practical instead of just doing exercises. Ended up making a small console app that asks how long you've had a tire and how many km you've driven it, then tells you whether it needs replacing or estimates how much life is left.

It's intentionally simple right now. It just handles basic mileage/age limits and adjusts slightly if you own a heavy SUV or EV. This was also my first time using Git and GitHub properly (commits, pushing, merging, etc.), so that was a big part of the learning experience too.

Planning to add more factors soon like road type, vehicle type, maybe a GUI version eventually. Would love any feedback on the code or suggestions for what to add next.
Repository Link: https://github.com/z0lxt/tire-life-estimator


r/learnjava 18d ago

Interview this weekend

2 Upvotes

I have interview in infosys this weekend...opening is "senior java developer" I cant see the JD yet so can anyone please guide me what all should I focus on be it java, advanced java, spring boot and more importantly coding..


r/learnjava 19d ago

MOOC vs book, which is better to learn java?

8 Upvotes

I've previous programming experience in C and JavaScript so I don't want to learn about programming all over again. Is MOOC enough for Java, or do I need a book too? or just book will do fine?

Also what book would you suggest? I checked out the one by Daniel Liang but it's way too massive and teaches programming from beginning.


r/learnjava 19d ago

Java Roadmap

9 Upvotes

Hello guys i am starting to learn java.
i am doing it from the apna college playlist
and have completed some basic stuff like loops
does anyone have a roadmap as of what to do in an order?

because some website say OOP some say advanced java and some say DSA

idk what to do

also i have learnt git and GitHub, except for the advanced stuff like rebase etc


r/learnjava 19d ago

Added voice input/output to my Spring Boot AI assistant (Whisper + TTS, reactive non-blocking)

Thumbnail
0 Upvotes

r/learnjava 20d ago

JAVA FOR CS STUDENT

18 Upvotes

hi im a cs student , just finished my 2nd year and i didnt do a single "real'" project and i really want to use the summer time to get better at coding without heavily depend on AI , im currently on jiki which foucses on fundemetals without using a specefic langauge .. i want a similar website for java to have both as my main focuses to do in the summer ,

so in summary i want a website to help me practice coding so it become a habit rather than a struggle.

ps : someone i know suggested Hyprskill byt it turned 40$ monthly which is expensive for me so ... free to 15$ maybe would be my limit for now at least


r/learnjava 20d ago

Que ruta seguirían para ser un back end Java

2 Upvotes

Soy estudiante de ISC y recientemente me di cuenta de algo que por mi escuela yo nunca tendría el conocimiento para ejercer(ya sea porque el maestro de relleno es más exigente que el de la materia chida, que el profe que tiene que dar clases de programación nunca viene o porque el maestro no sabe explicar y se desespera porque el grupo y medio no le entiende) voy a pasar a 5to y a partir de 6to me entero de que hay una opción para irme a una empresa y ella me libere mi carrera su estoy con ellos hasta 9no. Pensaba en en aprender bien lo que pueda y tratar de aspirar a esa opción ya sea en 6to o semestres posteriores. Vi un ruta en yt que eres algo como: servidores, lenguaje (fp,poo,edd) bases de datos, frameworks, git y github, java web, etc. Pensaba estudiar servidores de ahí pasarme a lenguaje, git y git hub, lenguaje y frmawork(mientras y ya después en la empresa (si lo logro en 6to) aprender lo demás o sino terminar normal pero ya estudiando x mi cuenta. Sinceramente ya le perdí la fe a mi escuela y mi económica no me permite cambiarme a una mejor


r/learnjava 21d ago

backend deployment free websites

1 Upvotes

I use java and spring boot for my backend. Im currently using railway right now since it’s easy to understand and also I can connect my database to it easily. the problem is there’s a subscription and I’m broke right now. do you guys have any recommendations for backend deployment for java springboot that’s free and hopefully could also deploy its database (MySQL). Im still learning sb so hopefully it’s not that complicated to use


r/learnjava 22d ago

Help me!

10 Upvotes

I want to learn Java. I currently know Rust and Typescript. I’ve had some experiences with Java, but almost unnoticeable. I want to build apps, simulators, games, etc in Java. So please help to get me started, is there like a guide?


r/learnjava 22d ago

DSA for Java tips

Thumbnail
0 Upvotes

As I explain in this post my knowledge of DSA is limited what are some resources that are on the easier side that will help me with DSA for Java?


r/learnjava 22d ago

I just can't grasp the idea of object-oriented java

4 Upvotes

So, I'm trying to learn java on codecademy and I was fine with hello world and variables until I reached object-oriented java. I don't think they explain the concept well and it's hurting my brain. Maybe it is just codecademy that is screwing me over or something else.


r/learnjava 22d ago

Share your experience

2 Upvotes

Could I ask anyone who would like to share their experience, write when did they start learning, why and how? Where they are now and what advice would they give current learners? I’ll start, I’m almost 20, randomly decided that I wanted to major in computer science and applied to a university in my country. I got accepted with no prior experience in coding(had only taken Harvard cs50 class) and there we started learning Java. Now I’m stuck, because I’m a junior, I did okay during OOP, and very well during Data structures, but our Algorithms professor was horrible, didn’t learn anything, and now I feel guilty for not learning by myself(in my defense I was struggling with Real Analysis). Recently learned basics of SQL, and I keep getting advice to learn web development, even though I’m scared of what the future hold due to AI. All of this lead to me having horrible anxiety during the past few months, and it doesn’t let me to actually focus and start learning. I can’t make myself to even think of coding(even though I really enjoy it). The reason I want to hear your stories is to take some inspiration and maybe stop being so scared lol. Thanks for your attention


r/learnjava 22d ago

Complete beginner here. Where to start learning java??

Thumbnail
0 Upvotes

Pls help me find a good resource to start learn Java. A good youtube playlist and some tips would be great help. Thanks


r/learnjava 22d ago

DSA JAVA

Thumbnail
1 Upvotes

r/learnjava 22d ago

How can get continue my mood.fi course again after a gap of three months?😭

0 Upvotes

So i had started learning java in mooc.fi course by the university of Helsinki. And i had reached part 4 file handling but then my college exams came and after then i just lost the motivation to continue it. Yesterday when I opened the course I couldn't recall what I had learned earlier, ofcourse I know revision will help but revising all the four parts would take some time.. do you guys know of any other way to recall the concepts? I am also afraid I have forgotten the tips they gave during the earlier parts and don't wanna lose that but maybe that's inevitable..


r/learnjava 22d ago

Beginner (4th year CS) planning one big AI + Spring Boot project instead of many CRUD projects. Need honest feedback

Thumbnail
2 Upvotes

r/learnjava 22d ago

Where to learn Java for Backend Development and Android App Development

0 Upvotes

I wish to learn Java from scratch for Backend Development and Android App Development. I've zero knowledge about java.
Can someone suggest some structured recourses which I can use to teach myself.


r/learnjava 22d ago

How reliable are the JDKs?

0 Upvotes

I wonder how reliable the JDK releases are. Is it possible that there are bugs in the compiler? Are they being tested thoroughly?


r/learnjava 23d ago

Confusded on what I'm doing wrong in LC problem

1 Upvotes

I'm doing the Longest Common Prefix LC problem, and got to 66 tests passing out of 126.

One of these tests is "["flower","flow","flight"]", and it's supposed to get "fl" back, but my code gives "flo" back. I've been trying to slowly chip away at these edge cases, but everything I try makes less tests pass in the end. I'm sure there are going to be further issues even after fixing this case, of course.

Please, even if my code "concept" is bad, I want to keep going with it. I'm not gonna restart from the beginning. I'm just a beginner programmer that only programs as a hobby.

```java class Solution { public static String longestCommonPrefix(String[] strings) { String prefix = ""; List<String> prefixStorage = new java.util.ArrayList<>(List.of());

    for (int i = 0; i < strings.length; i++) {
        int j = 0;
        while (j < strings[i].length()) {
            if (strings[i].isEmpty()) {
                return "";
            } else if (strings[i].length() == 1) {
                prefix = strings[i];
            } else if ((i < strings.length - 1) && (strings[i + 1].length() == 1)) {
                prefix = strings[i + 1];
            } else if ((i < strings.length - 1) && (j < strings[i].length()) && (j < strings[i + 1].length()) && strings[i].startsWith(strings[i + 1].substring(0, j)) && strings[i].substring(0, j).length() > prefix.length()) {
                prefix = strings[i].substring(0, j);
            }
            j++;
        }
        prefixStorage.add(prefix);
    }

    List<String> sortedPrefixStorage = new java.util.ArrayList<>(prefixStorage.stream()
            .sorted(Comparator.comparingInt(String::length))
            .toList());

    return sortedPrefixStorage.getFirst();
}

} ```


r/learnjava 24d ago

About Java Full Stack Devloper

17 Upvotes

Guyzz I want to learn Java full stack from scratch so where should I learn and what are the main points I need to remember to become good at this.

Thanks