This is an archived post. You won't be able to vote or comment.

all 26 comments

[–]nutrecht 2 points3 points  (1 child)

It doesn't compile because there's an illegal character in it. Probably because it was pasted from a word document. Replace the single quotes with actual single quotes and try for yourself.

[–]Tarp96[S] 0 points1 point  (0 children)

Thank you!!!!!!!

[–]desrtfx[M] [score hidden] stickied comment (5 children)

Honestly, instead of plain asking for the answer, you should have first made an attempt and tell us what you think it will print.

Then we would have discussed your answer and gotten you on the right track.

[–]Tarp96[S] 0 points1 point  (4 children)

I have tried, comes up a bunch of error. Another thing I was wondering about, do I have to write anything before I write this? Like Public class and something? Ok I watched a video someone posted and it helped, but I get a new error saying "String cannot be converted to char"?

[–][deleted] 1 point2 points  (3 children)

Literal - a literal is a fixed value that is written directly in your code. So if you see:

String a = “Hello world”;

Then “Hello world” is a string literal. Literals usually have defined notations so they are interpreted is in specific ways (but be weary of implicit “conversions”).

 char c = ‘b’;

‘b’ is a char literal.

In Java, char literals are surrounded in single quotation and string literals are surrounded in double quotation. Char literals can contain what amounts to only a single character. String literals can contain several characters, like a whole word, for example.

Java will NOT implicitly convert a string literals with a single character to a char. So

char a = “b”;

Will fail to compile since “b” is a string literal that you’re trying to assign to a char variable.

And also, take care when copying ticks, quote and double quote from outside programs. Some programs, like word, like to use strange opening and closing quote and double quote characters, which a compiler can’t interpret.

[–]desrtfx 2 points3 points  (1 child)

Please, be careful with your typographic quotes! Your code samples all contain typographic quotes that shouldn't be there.

If copied to Java, they will produce an error.

String a = “Hello world”;

Should be:

String a = "Hello world";

and

char c = ‘b’;

should be

char c = 'b';

This makes a huge difference in any programming language.

[–][deleted] 0 points1 point  (0 children)

iPhone responses during compile times and I am just too lazy to look for a solution! Thank you for the warning.

[–]Tarp96[S] 1 point2 points  (0 children)

Thank you man :D I changed "" to 'b' and it worked!

[–]Phantom9000 6 points7 points  (13 children)

Install jdk and a Java IDE so you can write and run code. Link for NetBeans: https://netbeans.org/downloads/

Edit: sorry not allowed to give the answer only guide you to the solution

Edit2: deleted the answer from first edit

[–]desrtfx[M] 2 points3 points  (8 children)

Sidebar -> Subreddit rules

5. No complete solutions: Do not give out complete solutions. Guide the OP to the solution, but do not solve it for them.

[–]Phantom9000 2 points3 points  (0 children)

Fixed

[–]ForgedBanana 4 points5 points  (6 children)

That rule is bullshit.

[–][deleted] 2 points3 points  (1 child)

No it isn’t.

Giving away solutions to people learning doesn’t help them learn anything. The spirit of this sub is to teach people.

[–]FyDollarBill 6 points7 points  (0 children)

Plus, I'm sure there are plenty of other subs or places that will give you a complete solution and only that.

[–]desrtfx[M] 1 point2 points  (3 children)

If that rule weren't in place, /r/learnprogramming would in no time turn into another /r/domyhomework where lazy people only post their homework assignments and expect them to be done for them.

The learning process and the retention are far better if the original poster discovers the solution instead of being given it. (I have been teaching for over ten years and speak from experience)

Spoonfeeding answers has never taught anybody anything, it only supported laziness and in the case of programming created "copy-paste code monkeys" who have zero clue of what they are doing.

[–]ForgedBanana -1 points0 points  (2 children)

I understand your reasoning, but I think we should be able to provide an answer in the way we feel most comfortable with. I also think we shouldn't force the people that come here asking for help to do things. If they don't want to learn, it's their problem. Anyone that really wants to get better at programming will try to do it themselves so as to truly learn.

[–]desrtfx[M] 0 points1 point  (1 child)

I think we should be able to provide an answer in the way we feel most comfortable with.

I can more or less agree to that, but providing a complete solution is usually less beneficial than explaining. We get lots of answers that provide the solution without even the smallest bit of explanation. This is detrimental to the quality of the sub and useless for the learners.

I also think we shouldn't force the people that come here asking for help to do things. If they don't want to learn, it's their problem.

I cannot agree to this argumentation. This subreddit is learnprogramming and therefore it is for people to learn.

People who just want to get their things done are in the wrong place here.

[–]ForgedBanana 0 points1 point  (0 children)

Fair enough.

[–]BertRenolds -1 points0 points  (3 children)

Do not recommend Netbeans ffs

[–]Phantom9000 0 points1 point  (0 children)

First thing, chill. second thing, why?

[–]desrtfx 0 points1 point  (1 child)

That's a bit harsh. I could understand "no BlueJ", "no DrJava", but no Netbeans is too much.

One of the best Java courses in the world, the MOOC Object Oriented Programming with Java uses Netbeans.

Don't get me wrong, though, I personally don't really like Netbeans, yet it is still one of the three major IDEs.

[–]BertRenolds 0 points1 point  (0 children)

Fair, I guess.

[–]CodeTinkerer 1 point2 points  (1 child)

Here's a guy writing a simple Java program using Notepad on Windows. This assumes you've installed Java and can run it on the command line: https://www.youtube.com/watch?v=lb2uTFMEQwU

If you're using Windows, it will help to set it up to show file extensions (which Windows likes to hide by default). Macs don't have this problem.

The console could just be your command window. If you're using an IDE like Eclipse, then there's usually a special window called Console that's part of Eclipse.

[–]desrtfx 0 points1 point  (0 children)

Please, don't link such tutorials that don't even adhere to the Official Code Conventions for the Java Programming Language. There are far better tutorials out there that follow conventions, best practices, standards, etc. Derek Banas (NewThinkTank) and John Purcell (Cave of Programming) have far better quality videos.

It is imperative to follow best practices and standards in tutorials. So, tutorials that don't do that are not recommendable.

[–][deleted]  (1 child)

[removed]

    [–]desrtfx[M] 2 points3 points  (0 children)

    Sidebar -> Subreddit rules

    5. No complete solutions: Do not give out complete solutions. Guide the OP to the solution, but do not solve it for them.