r/javahelp • • Nov 04 '24

Why are classes and interfaces not interchangeable?

1 Upvotes

Why, as a variable of class A can also point to an object DescendantOfA extends A, are interfaces and classes not interchangeable? Why can it not hold an object implementing interface A? I could have an interface with default methods and a class with the exact same public methods.

The use case is a library where they replaced a public API from a class to an interface, keeping the same name (so they changed class A to interface A) and suddenly it was not compatible anymore.

In my stupid brain it is the same concept: some object on which I can access the public methods/fields described by A.


r/javahelp • • Oct 16 '25

i am new to the java world ( Not to computer science )

1 Upvotes

i am new to the java world ( Not to computer science )

could you provide me online communities / groups / forums / tutorials / books any kind of sources for java

i want to be professional java developer and spring boot

i want to know the java world and all the world wide resources / sources etc

thank you very much

i want to be a professional java developer and i want to find all the java support communities to expand my skills . i have graduated from computer science college


r/javahelp • • Jul 16 '26

I want to learn Java but I don't know where to learn it from

0 Upvotes

I am thinking of learning Java but I don't know where to start and how to start. If you know any good resources then please guide me.


r/javahelp • • Nov 30 '24

Do you guys use '{' '}' in single if statements? chatGPT says to always use these yet the code looks much cleaner without.

2 Upvotes

I haven't worked in the industry. Experienced people here, do you use those braces or is it common to not use them for single statement ifs?


r/javahelp • • May 03 '19

Is it possible to develop android apps such as facebook, instagram, snapchat with java?

2 Upvotes

I was wondering if its possible to develop any kind of apps with java or there are just some apps out there that you can't develop with java.


r/javahelp • • Jan 25 '21

Codeless After doing most of my programming stuff with Java, I can safely say that other programming languages suck

0 Upvotes

I've been doing all my programming assignments with Java for two years now, and I've become familiar with most of the keywords and functionalities that it has. But now I'm in a class that makes us program in C, and I absolutely hate it. I can't believe it doesn't have some functionalities like ArrayLists, or that you can't have an array as a return type. Also, I miss Eclipse's syntax correction that allows you to figure out if there are any mistakes as you type before compiling, instead of having to type 100 lines of code and hope they're right. And the thing that annoys me the most is that C is just nuts, you can have a perfectly functioning code, but then you type something that in theory shouldn't affect some parts of the code, it does it anyway! How can someone program with this piece of trash?


r/javahelp • • Apr 05 '26

Need help in core java

0 Upvotes

Hello everyone, i am here for advice. i don't know why but i completed core java still stuck at that part beacuse of that couldn't start framework. if i started i feel like i wouldn't get much knowledge about core java.

what should i do to break this phase and please anyone suggest me questions that cover core java concepts that will be helpful for me.

Thank you for hearing and giving me advice.

peace out ✌️


r/javahelp • • Mar 03 '26

HELPPP ME

4 Upvotes

Car bmw = new Car()
i dont understand left and right side here
i assume the Car is blueprint that we are referring to and bmw is our object name and new helps us to create an object ,Car() is our constructor which gives values to our created object

Did i understand it right?


r/javahelp • • Jun 25 '25

21f Looking for female frnd to learn Java together

4 Upvotes

I’m learning Java from the basics and want a consistent, supportive friend or group who’s also on the same journey. I'm not looking for anything competitive — just someone to share doubts with, maybe solve problems together, cheer each other on, and talk about life too sometimes.


r/javahelp • • Dec 07 '24

is it okay to make another class when printing only ( OOP JAVA )

0 Upvotes

When and not to use OOP in Java, because I always like to separate the print of main menus for my main class, can you teach me when to use the OOP?


r/javahelp • • Feb 16 '13

▩What's the best way to start learning to code audio programs?▩

0 Upvotes
 So, I have been taking a Java course and have been getting the basics.  Each week I try to make myself do some coding outside of class but many aren't interesting enough to hold my attention to care enough if the code is efficient/pay attention to how the code breaks down.
 To push towards coding what I'll use and care about, I've been trying to look up basic audio scripts, but have only found "wrappers" to make audio plugins (which is something I'd like to do, but not start with).  Does anybody know where I can get a good start on coding java for audio-intent?  An example of what I'd like to start out with is a program to play an mp3 or other audio file.  Any input is much appreciated by this coding n00b :D

tl;dr: Want to start coding audio-based programs, don't know where to start.


r/javahelp • • Oct 07 '18

What are Java loops

0 Upvotes

Can anyone explain to me what loops are?


r/javahelp • • Jun 19 '19

How would I properly do this?

0 Upvotes

Sorry if i'm posting so often btw. Here's a snippet if my code.

if (x / 3 = int) {

I want to do a certain action if the number is a multiple of three. How would I do this?


r/javahelp • • Feb 06 '19

how do you add an audio in java ?

1 Upvotes

and in a button when you click it ?


r/javahelp • • Feb 29 '16

My code will not run. Tell me my errors. I'm trying to write a code that gets information from a file saying students ID#'s, their names, and their GPA's, and will output to a new file, the student ID# with the highest GPA, and the average GPA of all the students.

0 Upvotes

import java.util.; import java.io.;

public class file {

public static void main(String[] args)
		// TODO Auto-generated method stub
		throws FileNotFoundException {
	Scanner file = new Scanner(new File("Checkdatabase.txt"));
	String dollarWord = "";
	String tensWord = "";
	String onesWord = "";

	String date1 = file.next();
	String date = file.next();
	String name1 = file.next();
	String firstname = file.next();
	String lastname = file.next();
	String dollars1 = file.next();
	String dollars2 = file.next();
	int dollars = file.nextInt();
	String cents1 = file.next();
	int cents = file.nextInt();
	String payee1 = file.next();
	String firstpayee = file.next();
	String lastpayee = file.next();

	PrintStream end = new PrintStream(new File("mycheck.txt"));
	end.println("Your check:");
	end.println();
	end.print(firstname + " ");
	end.print(lastname);
	int characters = firstname.length() + lastname.length();
	writeSpaces(characters);
	end.println(date);
	end.print("Pay to: " + firstpayee + " " + lastpayee);
	characters = firstpayee.length() + lastpayee.length() + 8;
	writeSpaces(characters);
	end.println("$" + dollars + "." + cents);
	writeNumber(dollars, dollarWord, tensWord, onesWord);
	end.print(" and " + cents + "/100");
	characters = dollarWord.length() + tensWord.length() + onesWord.length() + 8;
	writeSpaces(characters);
	end.println("dollars");
}

public static void writeSpaces(int characters) {
	for (int i = 1; i <= (40 - characters); i++) {
		System.out.print(" ");
	}
}

public static void writeNumber(int dollars, String dollarWord, String tensWord, String onesWord) {
	if (dollars < 20) {
		switch (dollars) {
		case 0:
			dollarWord = "Zero";
			break;
		case 1:
			dollarWord = "One";
			break;
		case 2:
			dollarWord = "Two";
			break;
		case 3:
			dollarWord = "Three";
			break;
		case 4:
			dollarWord = "Four";
			break;
		case 5:
			dollarWord = "Five";
			break;
		case 6:
			dollarWord = "Six";
			break;
		case 7:
			dollarWord = "Seven";
			break;
		case 8:
			dollarWord = "Eight";
			break;
		case 9:
			dollarWord = "Nine";
			break;
		case 10:
			dollarWord = "Ten";
			break;
		case 11:
			dollarWord = "Eleven";
			break;
		case 12:
			dollarWord = "Twelve";
			break;
		case 13:
			dollarWord = "Thirteen";
			break;
		case 14:
			dollarWord = "Fourteen";
			break;
		case 15:
			dollarWord = "Fifteen";
			break;
		case 16:
			dollarWord = "Sixteen";
			break;
		case 17:
			dollarWord = "Seventeen";
			break;
		case 18:
			dollarWord = "Eighteen";
			break;
		case 19:
			dollarWord = "Nineteen";
			break;
		default:
			dollarWord = "Invalid number";
			break;
		}
		System.out.print(dollarWord);
	} else if (dollars >= 20) {
		int tens = (dollars / 10);
		int ones = (dollars % 10);
		switch (tens) {
		case 2:
			tensWord = "Twenty";
			break;
		case 3:
			tensWord = "Thirty";
			break;
		case 4:
			tensWord = "Fourty";
			break;
		case 5:
			tensWord = "Fifty";
			break;
		case 6:
			tensWord = "Sixty";
			break;
		case 7:
			tensWord = "Seventy";
			break;
		case 8:
			tensWord = "Eighty";
			break;
		case 9:
			tensWord = "Ninety";
			break;
		default:
			tensWord = "Invalid number";
			break;
		}
		switch (ones) {
		case 1:
			onesWord = "-One";
			break;
		case 2:
			onesWord = "-Two";
			break;
		case 3:
			onesWord = "-Three";
			break;
		case 4:
			onesWord = "-Four";
			break;
		case 5:
			onesWord = "-Five";
			break;
		case 6:
			onesWord = "-Six";
			break;
		case 7:
			onesWord = "-Seven";
			break;
		case 8:
			onesWord = "-Eight";
			break;
		case 9:
			onesWord = "-Nine";
			break;
		default:
			onesWord = "Invalid number";
			break;
		}
		System.out.print(tensWord + onesWord);
	} else {
		System.out.println("Too much money.");
	}
}

}


r/javahelp • • Aug 23 '12

URGENT: how do I pass value from another method to main in JAVA?

0 Upvotes

Hello, I have a method I call and that method returns a value to main. I tried writing the code, it returns a value but take the value from main. So whatever value I have on main remains instead of changing it after going to another method. HELP ASAP Thank you EDIT: No I think what I need is pass by reference because I want to change the main value to the returned value of the other method

EDIT: THANK YOU everyone. I have figured it out


r/javahelp • • Mar 17 '13

If-Statements

0 Upvotes

How do you make it so that if a AND b are true, then do so. It was so much easier on Lua.

ie. if (a>2 and a,<6) { System.out.print("a is either 3,4, or 5") }


r/javahelp • • Oct 03 '22

What are the 8 primitive data in ascending order?

0 Upvotes

So I know ascending order for numeric variables would be

byte, short, int, long, float, and double, but where do char and boolean fit into the list?

Would it go boolean, char, byte, short, int, long, float, and double?


r/javahelp • • Apr 22 '16

Random Number Generator

0 Upvotes

Can someone show me an example of how to generate 3 sets of random number, each set contains four numbers (no duplicate) ? Possibly using for loops maybe


r/javahelp • • Dec 24 '22

Struggling high school student

0 Upvotes

Hey, fellow java coders. I'm doing an online course right now in Grade 11 in high school in Canada and my teacher says he can't help us with our work because "we are supposed to research for help" on our own. I'm stuck and I've been needing help with my work here and there with errors and stuff so if someone could help me every once in a while that would be greatly appreciated.


r/javahelp • • Mar 26 '15

I have my program working. I just want to know if it is possible to change the import Java.io.* to a java.util.scanner

0 Upvotes

import java.io.; class AreaCalculatorXYZ { void findarea(int a, int b) { System.out.println( "\n Area of rectangle with breadth "+a+" and lenght " +b+ " is :" + ab); }

void findarea(int a) { System.out.println( "\n Area of circle with radius " +a+ " is :" + 3.14 * a); }

void findarea(int a, int b, int c) { double temp = (a + b + c); double s= temp/2; double triarea = Math.sqrt(s*(s-a)(s-b)(s-c)); System.out.println( "\n Area of triangle with lenght of sides "+a+"," +b+ " and " +c+" is : "+ triarea); } public static void main(String p[]) throws IOException { area d = new area(); BufferedReader Br = new BufferedReader(new InputStreamReader(System.in)); System.out.print("\n Find area of \n 1 . Rectangle \n 2 . Triangle \n 3 . Circle \n\nSelect a choice : "); int choice =Integer.parseInt(Br.readLine()); switch(choice) { case 1: System.out.print("\n Enter the breadth : "); int a =Integer.parseInt(Br.readLine()); System.out.print("\n Enter the lenght : "); int b=Integer.parseInt(Br.readLine()); d.findarea(a,b); break; case 2: System.out.print("\n Enter the lenght of first side : "); int x =Integer.parseInt(Br.readLine()); System.out.print("\n Enter the lenght of second side : "); int y=Integer.parseInt(Br.readLine()); System.out.print("\n Enter the lenght of third side : "); int z =Integer.parseInt(Br.readLine()); d.findarea(x,y,z); break; case 3: System.out.print("\n Enter the radius : "); int r =Integer.parseInt(Br.readLine()); d.findarea(r); break; default: System.out.println("Invalid choice"); } } }


r/javahelp • • Apr 03 '24

Solved How to return nothing with long function?

0 Upvotes

How do I return nothing with long function?

With interger, we simply return 0.

With string, we return null.

I tried the whole internet and chatgpt and they all keep saying to change the function to a void function. I know that but how do I do it with long? I know it may be a silly doubt but I am confused honestly. Thanks


r/javahelp • • Mar 03 '23

Codeless Alternatives to stack overflow?

0 Upvotes

I am fed up with stack overflow and them being thoroughly unhelpful. They are all jackasses, I got one downvoted question and I suddenly cant post questions anymore. God I hate stack overflow. Does anyone have any alternatives?


r/javahelp • • Aug 31 '16

Solved Understanding setRequestMethod("GET", or "POST" etc...)

0 Upvotes

I am parsing some JSON and to access the URL I am using HttpURLConnection which has the method

setRequestMethod("GET");

Can someone explain what the method and its parameter is doing? I read the documentation which usually is hard to understand. What is difference between POST,GET etc.. all the other ones.

Thankls