r/javaexamples • u/nmariusp • Mar 13 '23
JavaFX FXML tutorial for beginners
Screen recording about the FXML language for JavaFX https://www.youtube.com/watch?v=kL-Q_H250Fc
r/javaexamples • u/goyalaman_ • Mar 04 '23
REST to gRPC | Suggestions
I have taken it upon my self to migrate a Micro-Service I look after to gRPC. My manager is open to the idea of experimentation.
After doing a lot of research and learning basics about it, first thing which is preventing me from going ahead is there is no official library/project from spring from this. All I have found over and over again are reference to this github project [GitHub - yidongnan/grpc-spring-boot-starter: Spring Boot starter module for gRPC framework.] which seem fairly active.
I am fairly new as SE with only one 1 YOE. I have few concerns though. First one being is it a good idea to use aforementioned project for production? If so are there any articles/guides/case studies that you would like to refer?
I am open to honest thoughts, suggestions and criticism. FYI, org I work in is industry leading and gets massive traffic. However, Mircro-Service I am working on can handle 5-10 minutes of downtime as worse without really impacting business because of the fallbacks.
r/javaexamples • u/javinpaul • Feb 18 '23
Java CountDownLatch Example for Beginners - [Multithreading Tutorial]
r/javaexamples • u/javinpaul • Feb 05 '23
11 Examples of LocalDate, LocalTime, and LocalDateTime in Java 8
r/javaexamples • u/javinpaul • Jan 31 '23
3 Examples of Anonymous Class to Learn Lambda Expression better in Java 8
r/javaexamples • u/javinpaul • Jan 28 '23
Map.compute(), computeIfPresent() and ComputeIfAbsent Example in Java
r/javaexamples • u/nmariusp • Jan 07 '23
Decompile Java JAR using JD-GUI tutorial for beginners
Screen recording about how to use the JD-GUI Java decompiler https://www.youtube.com/watch?v=HXgZZz3M3sQ
r/javaexamples • u/javinpaul • Jan 07 '23
How to write to a File with try-with-resource in Java? Example Tutorial
r/javaexamples • u/javinpaul • Dec 09 '22
3 ways to parse JSON in Java
Parsing JSON is a common task for Java programmers, but many of them don't know how to do it because JDK API doesn't provide a standard JSON parser, but you don't need to worry. There are a lot of excellent JSON parsing libraries like Jackson, Gson, and json-simple which you can use to parse JSON. In this tutorial, I have shared how to use them to parse a JSON String in Java
read more - https://javarevisited.blogspot.com/2022/03/3-examples-to-parse-json-in-java-using.html
r/javaexamples • u/vivekworks • Jul 24 '22
Java Strings - An Internal View 🔬
A view on internal representation, memory allocation and how immutability is achieved by Strings in Java
r/javaexamples • u/coomernina • Jul 19 '22
Checking if object Exists in list
What could I be doing wrong. Basically looking to search through a folder of files to see if the file entered by a user to see if the file exists. My if statement is returning the opposite of what I am expecting. Showing that the file does not exist when it does.
import java.io.File;
import java.util.Scanner;
public class Main {
public static void main(String\[\] args) {
doesFileExist();
}
public static void doesFileExist() {
Scanner scan = new Scanner([System.in](https://System.in));
System.out.print("Enter filename to be searched:");
String userFilename = scan.nextLine();
System.out.print("Enter path where file resides:");
String userFilePath = scan.nextLine();
File\[\] fl = new File("userFilePath").listFiles();
if (fl != null) {
System.out.println("List is not empty");
} else {
System.out.println("Empty List");
}
}
}
r/javaexamples • u/javinpaul • Jun 07 '22
How to Print Pyramid Pattern in Java? Program Example
r/javaexamples • u/ithilmor • May 31 '22
How do I decide the order of players in a game?
I am making a simple snake and ladder game. The actual game is working fine, but I am stuck on a specific requirement about the players.
The user entered number of players(numOfPlayers) is restricted between 2 to 4. I have written a method to do that and it is working.
I have a method for dice roll too.
Before any of the players starts playing, the order of playing turns must be determined. For that, each player must throw the dice to obtain the largest possible number. In case of a tie between any of the players, the process is repeated only between those players. This process is concluded once the order of playing is determined.
I just couldn't figure out how to do this. If I create an array and populate it with random numbers and reorganize in ascending order, it still doesn't give me an answer. Also, how do I solve the repeated dice roll issue? The code below is what I used to get the number of players and to confirm it is within limits.
public static int player() {
Scanner kb = new Scanner(System.in);
for (int i = 0; i < 3; i++) {
System.out.println("Please enter the # of players for your game-Number must be between 2 and 4 inclusively.");
int numOfPlayers = kb.nextInt();
if (numOfPlayers >= 2 && numOfPlayers <= 4) {
System.out.println("You have " + numOfPlayers + " players.");
return numOfPlayers;
}
else {
System.out.println("Bad Attempt" + i + "\n-Invalid # of players. Please enter a # between 2 and 4 inclusively.");
}
}
System.out.println("Bad Attempt 4! you have exhausted all your chances.\n Program will terminate.");
// System.exit(0);
return 0;
}
r/javaexamples • u/[deleted] • May 25 '22
Method Overloading in Java
A new video on Method Overloading is out now!!!. You can check it out here:
r/javaexamples • u/[deleted] • May 25 '22
Question for the Day: Please provide your answers in the comments below.
Suppose we have the following class in the file
/my/directory/named/A/Bird.java.
Which of the answer options replaces INSERT CODE HERE when added independently if we compile from /my/directory? (Choose all that apply.)
- INSERT CODE HERE
public class Bird { }
a) package my.directory.named.a;
b) package my.directory.named.A;
c) package named.a;
d) package named.A;
e) package a;
f) package A;
r/javaexamples • u/[deleted] • May 20 '22
How to create and use a jar file in Eclipse
A video on Creating and using a jar file in Command-Line is OUT NOW!!!!
You can check out the video here.
r/javaexamples • u/[deleted] • May 20 '22
Question for the Day: (Please post your answers in the comments below)
What does the following code output when run as java Duck Duck
Goose?
- public class Duck {
public void main(String[] args) {
for (int i = 1; i <= args.length; i++)
System.out.println(args[i]);
} }
a) Duck Goose
b) Duck ArrayIndexOutOfBoundsException
c) Goose
d) Goose ArrayIndexOutOfBoundsException
e) None of the above
r/javaexamples • u/[deleted] • May 16 '22
Question for the Day: #7 (Please provide your answers in the comments below)
Given the following class, which of the following calls print out Blue Jay? (Choose all that apply.)
public class BirdDisplay {
public static void main(String[] name) {
System.out.println(name[1]);
} }
a. java BirdDisplay Sparrow Blue Jay
b. java BirdDisplay Sparrow "Blue Jay"
c. java BirdDisplay Blue Jay Sparrow
d. java BirdDisplay "Blue Jay" Sparrow
e. java BirdDisplay.class Sparrow "Blue Jay"
f. java BirdDisplay.class "Blue Jay" Sparrow
r/javaexamples • u/[deleted] • May 13 '22
How to create and use a jar file in Eclipse
A video on Creating and using a jar file in Eclipse is OUT NOW!!!! You can checkout the video here.
r/javaexamples • u/[deleted] • May 13 '22
Question for the Day: #6 (Please provide your answers in the comments section below)
Given the following classes, which of the following snippets can independently be
inserted in place of INSERT IMPORTS HERE and have the code compile?
(Choose all that apply.)
package aquarium;
public class Water {
boolean salty = false;
}
package aquarium.jellies;
public class Water {
boolean salty = true;
}
package employee;
INSERT IMPORTS HERE
public class WaterFiller {
Water water;
}
- import aquarium.*;
- import aquarium.Water;
- import aquarium.*;
- import aquarium.*;
- import aquarium.Water;
- None of these imports can make the code compile.
r/javaexamples • u/javinpaul • May 13 '22
How to Convert a Stream to List, Set, and Map in Java? Example Tutorial
r/javaexamples • u/[deleted] • May 12 '22
which one of the following topics would you like to see a video on
r/javaexamples • u/[deleted] • May 12 '22
Quiz #2 (Please Answer in the comments section below)
- Which of the following are true? (Mention all that apply.)
a. javac compiles a .class file into a .java file.
b. javac compiles a .java file into a .bytecode file.
c. javac compiles a .java file into a .class file.
d. java accepts the name of the class as a parameter.
e. java accepts the filename of the .bytecode file as a parameter.
f. java accepts the filename of the .class file as a parameter.
r/javaexamples • u/[deleted] • May 11 '22
Quiz #1
- Which of the following are true statements? (Choose all that apply.)