/r/learnjava
Resources for learning Java
Resources for learning Java
Format + Copy
, and paste the code in your post (remember to leave an empty line above the code!).Free Tutorials
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
In the MOOC, there is a static method m the class below: EDIT: I found this paragraph from the instructors on why they chose to use static:
"We can already see that code dealing with string sanitization is needed in every method that handles a book, which makes it a good candidate for a separate helper method. The method is implemented as a class method since it doesn't handle object variables. "
Is this a normal rule in writing methods/classes when a method doesn't touch any instance variables?
public class Library {
private HashMap<String, Book> directory;
public Library() {
this.directory = new HashMap<>();
}
public void addBook(Book book) {
String name = sanitizedString(book.getName());
if (this.directory.containsKey(name)) {
System.out.println("Book is already in the library!");
} else {
directory.put(name, book);
}
}
public Book getBook(String bookTitle) {
bookTitle = sanitizedString(bookTitle);
return this.directory.get(bookTitle);
}
public void removeBook(String bookTitle) {
bookTitle = sanitizedString(bookTitle);
if (this.directory.containsKey(bookTitle)) {
this.directory.remove(bookTitle);
} else {
System.out.println("Book was not found, cannot be removed!");
}
}
public static String sanitizedString(String string) {
if (string == null) {
return "";
}
string = string.toLowerCase();
return string.trim();
}
}
• Print statements
• Primitive types (boolean, int, double, char)
• Math and concatenation
• Assignment operators
• Increment and decrement operators
• Casting • If/else/else if statements
• Comparison operators
• Logical operators and short-circuiting
• DeMorgan’s Laws and boolean simplification
• While, do-while, for, and for-each loops
• Scope
• Static methods
• Math methods (abs, pow, random, sqrt)
• Escape sequences (\n, \t, \”, \\)
• String methods (charAt, equals, indexOf, length, substring, substring)
• Null
• 1D arrays
• 2D arrays
• ArrayLists (add, add, get, indexOf, remove, set, size)
• Wrapper Classes
• Classes and objects
• Fields, constructors, and instance methods
• Encapsulation, inheritance, and polymorphism
• Abstract Classes
• Interfaces
• Global variables and constants
Hi everyone. What books can you recommend for learning Docker?
And one more question, I finished learning Spring and its core modules (spring jpa, spring security, spring boot...).
The last technology I studied was Git.
Now the question is what should I study next. Is it time to start learning microservices, or is it better to familiarize myself with Docker first and then learn microservices. I had a quick look at what a microservice is and there was a mention of Docker.
Thanks
Recently started Computer Science college course and finding Java a bit tough. Are there any books or guides that I can buy as a reference to help me learn? I would appreciate any recommendations!!
Where do I type in code? Do I type in code in cmd?
Where do I type regular hello world code? In an app? Why did I install jdk21 then? 😅
Thank u so muchhhhhh <3
Hello,
Currrently learning java, I need to implement a feature that saves and resumes game,
Will below be the correct way to do it?
public void saveGameDataToFile(File file) {
try {
FileOutputStream fileStream = new FileOutputStream(file);
ObjectOutputStream objectStream = new ObjectOutputStream(fileStream);
objectStream.writeObject(gameBoard);
objectStream.writeObject(player1);
objectStream.writeObject(player2);
objectStream.writeObject(win);
objectStream.close();
fileStream.close();
System.out.println("Save game state successfully");
} catch (IOException e) {
System.out.println("Failed to save game state TicTacToe");
}
}
public void loadGameDataFromFile(File file) throws ClassNotFoundException {
try {
FileInputStream fileStream = new FileInputStream(file);
ObjectInputStream objectStream = new ObjectInputStream(fileStream);
char[][] savedGameBoard = (char[][]) objectStream.readObject();
int savedPlayer1 = (int) objectStream.readObject();
int savedPlayer2 = (int) objectStream.readObject();
boolean savedWin = (boolean) objectStream.readObject();
} catch (IOException e){
System.out.println("Caught in loadGameDataFromFile");
}
}
I've been in Net C# world, Microsoft SQL, Oracle since 2002 (Net 1.1)
I also worked with Azure, JavaScript (Angular, React) since inception, just to give you an idea about my current level for your suggestions.
I started looking into learning Java (zero experience) couple days ago, and it seems as the other cousin of C#.
Reading many users' comments on reddit recommending Hyperskill, got me convinced about the idea, not sure though if it's the best path to master Java.
Does it cover advanced topics ?
What about "spring boot" or other technologies related to Java? (no idea what 'spring boot' is, I just see it mentioned as part of many java developer jobs)
any better alternative ? suggestion, recommendation ???
Please share how you got it
I often get stuck in tutorial hell when trying to learn new frameworks. I spend too much time looking for the "perfect" course and end up making little to no progress. Btw I know Java, collections, and OOP and I'm strong in dsa. And now I really want to learn springboot for backend but I'm making no progress. I tried following it's documentation but there's just too much and I find it tough.
What strategies can I use to break this cycle and effectively learn new frameworks without getting lost in endless tutorials? Also if possible can anyone tell some resources for learning springboot for backend?
TL;DR: How can I escape tutorial hell and learn any technology effectively?. What’s the best approach?
I have built a tictactoe that works on console, I want to add a feature where users can save the game state to a file and also resume from where it stopped.
How do I implement this? I have read about serialization and deserialization but not sure on how to utilize it for this usecase.
- I know I should prompt the players if they wish to save or not then depending on that serialize
- also know that when a paused game is reloaded, the program should ask if the players which to continue or if they want to restart a new game
I have been asked not to use chatgpt as it will stunt my learning(I don't know why)
I came across this behavior by accident while I was learning about Map:
public static void mapDemo() {
Map<Long, String> fruitMap = new HashMap<>();
long id = 123;
fruitMap.putIfAbsent(id, "apple");
fruitMap.putIfAbsent(id, "dem apples!");
System.out.println(fruitMap.get(123)); // Prints "null"
System.out.println(fruitMap.get((long) 123)); // Prints "apple"
var num = 123;
}
Output:
null
apple
When I try to retrieve the value stored against the key "123" - it depends what the type of the key is along with the value.
If I retrieve it by just using a stray number "123" it retrieves the value `null`
BUT if I type cast this same magic number to "long" type then the stored value "apple" is retrieved.
I understand that for when a stray number of this size gets inferred, it is inferred to "int" type BUT why does it matter? (For example. variable `num` gets inferred to "int" type here)
Please can someone give me an explanation for why does this happen?
Why does the type of key also matter when fetching a value in Map?
I've done the whole first part of java mooc, now im learning java through a textbook. They differ in the way that they declare and initialize variables so I am here to ask
// Declare AND Initialize
String name = "John Doe";
int age = 46;
String job = "Plumber";
// Declare THEN Initialize
String name;
int age;
String job;
name = "John Doe";
age = 46;
job = "Plumber";
Hello, i am 19 and i've been working full time as a junior backend developer for about a year now and i want to get the ocp 21 certification
What i want to ask is what is a realistic timeframe to get the certification if i put about 2-3 hours to it after work and also could you share some materials i could study with and tips you might have
I am going to start with spring spring boot so before I am going to start what are prerequisites for it, to learn something or can I directly start it also which ide is better to go for . I already have eclipse and intellij in my laptop so which can I use for it
Hey, I'm working on a project with my friends, a messenger based on WhatsApp, but which is actually a hybrid of our favorite features from many of the most popular messengers. This is my first time creating something like this and I wanted to ask - what are the most optimal tools in your opinion to create a real life chat, supporting both private and group conversations, saving all messages in a Mongo database and allowing multimedia transmission. Will the combination of WebSockets + Kafka be appropriate or should I look for something else?
Hi,
I am compiling the following code:
import javax.swing.*;
public class StaticVarDemo {
static int iVal1;
static int next_a;
int iVal2;
int a;
StaticVarDemo(int iIV1, int iIV2 ){
StaticVarDemo.iVal1 = iIV1;
this.iVal2 = iIV2;
next_a = StaticVarDemo.iVal1;
}
public static void main(String[] args) {
StaticVarDemo obj = new StaticVarDemo(10, 20);
JOptionPane.showMessageDialog(null, " Static var iVal1="+StaticVarDemo.iVal1+"Non-static var iVal2="+obj.iVal2);
a = next_a;//Solution
next_a++;
}
}
When I am compiling the above code, I am getting the error, "can't make a static reference to a non-static field" on the second last line. Somebody please guide me. Zulfi.
I'm part of the project that uses jakarta ee with an application server. Is it possible to learn jakarta ee within spring. This is minly because jakarta ee applications are harder to setup?
I want to learn the @TransactionAttribute in jakarate ee but it seems like spring has its own.
Hello i just learned the basics of programming in c++ , and this semester i will be strudying the oop with java so anyone have a good recommendation for java it will be better if its like building a game and the instructor explain everything from scratch, thanks if you have any advices or comment feel free to leave it 🫶
Idk which is the proper way to list this on my resume/linkedin.
I am making a program in which I want to schedule an action to happen in 30 minutes. To be more precise, someone will call the method and type in 30(minutes), then I want the method to change a boolean variable 30 minutes later. Thanks in advance!
OOPs Concepts and Java Programming: Introduction to Object-Oriented concepts, proceduraland object-oriented programming paradigm Java programming: An Overview of Java, Java Environment, Data types, Variables, constants, scope and life time of variables, operators, type conversion and casting, Accepting Input from the Keyboard, Reading Input with Java.util.Scanner Class, Displaying Output with System.out.printf(), Displaying Formatted Output with String.format(), Control Statements
UNIT-II Arrays, Command Line Arguments, Strings-String Class Methods Classes & Objects: Creating Classes, declaring objects, Methods, parameter passing, static fieldsand methods, Constructors, and ‘this’ keyword, overloading methods and access Inheritance: Inheritance hierarchies, super and subclasses, member access rules, ‘super’ keyword, preventing inheritance: final classes and methods, the object class and its methods; Polymorphism: Dynamic binding, method overriding, abstract classes and methods;
UNIT-III Interface: Interfaces VS Abstract classes, defining an interface, implement interfaces, accessing implementations through interface references, extending interface; Packages: Defining, creating and accessing a package, understanding CLASSPATH, importing packages. Exception Handling: Benefits of exception handling, the classification of exceptions, exception hierarchy, checked exceptions and unchecked exceptions, usage of try, catch, throw, throws and finally, rethrowing exceptions, exception specification, built in exceptions, creating own exceptionsub classes.
UNIT-IV Multithreading: Differences between multiple processes and multiple threads, thread states, thread life cycle, creating threads, interrupting threads, thread priorities, synchronizing threads, inter thread communication. Stream based I/O (java.io) – The Stream classes-Byte streams and Character streams, Reading console Input and Writing Console Output, File class, Reading and writing Files, The Console class, Serialization
UNIT-V GUI Programming with Swing- Introduction, MVC architecture, components, containers. Understanding Layout Managers - Flow Layout, Border Layout, Grid Layout, Card Layout, GridBag Layout. Event Handling- The Delegation event model- Events, Event sources, Event Listeners, Event classes, Handling mouse and keyboard events, Adapter classes, Inner classes, Anonymous Inner classes.
am i cooked
Write a java program to check whether a given input number by user is a Keith number or not ? (Not use array, string and it should be applicable for any n-digit number) For example let say-197 1+9+7=17 9+7+17=33 7+17+33=57 17+33+57=107 33+57+107=197
Both are same it's Keith number
I already have experience with python frameworks like django and flask but would like to transition to java. What is the best way for a beginner to learn all the concepts?
Hi for my next computer science class I need training from a mooc site regarding x and y coordinates and method overloading can you tell me where it is?
https://gist.github.com/magn9195/1b455fb49b0a47b13f85ea401757fbc2
I am a java noob, currently in the process of trying to make a snake game as my first project, however i can't seem to get all the paintcomponents to be displayed properly. Right now as soon as i move the snake background and apple disappears. Is there another way to update JPanel, so i can get my snake moving while background and apple is visible?
Hey everyone. I’m looking for a coding partner to write Java code with me on HackerRank and review each other’s work. If you’re interested in collaborating, please DM me! I’d love to connect and learn together.
I've finished and followed along with the book "Spring Starts Here", which I enjoyed thoroughly. its my first exposure to Spring right after core java.
The contents of this books are primarily just introductions and watered down examples, Im not sure where to go from here. In particularly the book didnt cover much about Spring Security (I want to know how to implement Auth and OAuth), and other stuff like using Hibernate as an ORM or more realistic examples that aren't simplified for the sake of teaching basics. (Secret vaults?)
The book itself recommends other books such ad
Both of which I've heard are hard to follow, and not that great of a resource.
Am I ready to simply just use spring documentations and random articles from websites?
Am I in a good position to attend Chad Darby's course? Im afraid that he simply covers everything I know already
Whats the best step forward or any advice, Thanks!
This is a follow up to my post last week, I decided to go with spring starts here and was happy I did, but yet again Im lost
Hey guys, I am a class 11th student who is keen to learn java while also studying for my college entrance exams.
I studied some concepts of java in class 9th and 10th but I guess they would be considered extremely basic.
I was hoping to get recommendations for some online courses which could teach me java at a steady pace as I want to pursue being a software developer anyways.
For context: the exam is the JEE.
Thanks :D
There are 3 classes A,A1,A2.
A1 and A2 inherits A.
I am using an object of A to initialise A1 and A2,and then,
Doing object of A=object of A1.
Now any change in A reflects on A1,can i make it so that changes reflects on both A1 and A2.
Pseudo Class definition:
*class A{int a;A(int m){a=m;}}.
*class A1 inherits A{int b;
*A1(A m,int n){super(m);b=n;}}.
*class A2 inherits A{int c;
*A1(A m,int n){super(m);c=n;}}.
A ob=new A(1);
A1 ob1=new A1(ob,2);
A2 ob1=new A2(ob,3);
ob=ob1;
ob.a=69;
print(ob1.a)//prints 69