Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

Why can't i implement what i've learned with TreeHouse on NetBeans?

Hello,

Today i installed NetBeans to practice my Java. But i'm having some issues with the things that i've learned here and what to implement on the IDE. For example, this basic code doesn't let me run the project:

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package firstprogram;

/**
 *
 * @author Pedro
 */
public class FirstProgram {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {    

     String firstName = "Pedro"; {

     System.out.println("My first name is %s\n!", firstName);

    }
    }
    }

Could you please tell me what's wrong?

Thanks!

NetBeans doesn't read readLine either and i don't know why, help me understand please

Csaba Koles
Csaba Koles
4,644 Points

On Treehouse I assume you were using the provided workspaces. With Java you need imports sometimes. Workspaces provides you that so you don't need to import manually.

I recommend Eclips instead of NetBeans when you start out with Java. The Eclips IDE either imports the necessary libraries for you or gives you a notice that you might need something to correct the error the IDE found.

Thank you for your reply Csaba! I've tried eclipse now and i can't even run a simple

System.out.println("Hello world!");

It's very annoying because that basic line is a tutorial of Eclipse itself and doesn't run. What's wrong?

Csaba Koles
Csaba Koles
4,644 Points

Can you include here your code? Or the error that you get.

If Eclipse itself does not run, there is probably no java SDK installed on your computer (that's just a guess, I could be wrong...).

To get this go here: http://www.oracle.com/technetwork/java/javase/downloads/index.html

I hope this will sort out some of your issues.

If not, here is the whole "Hello World" program that I wrote that should be working both in Eclipse and NetBeans.

public class helloWorld {

    public static void main(String[] args) {        
        System.out.println("Hello World!");         
    }
}

Thanks again Csaba! I've installed java IDK and this code still doesn't work:

public class FirstProgram {

public static void main(String[] args) {  

    String world = "World";

    System.out.println("Hello %s!", world);         
}

}

I really don't understand, this was something that i've learned here on Treehouse and doesn't work.

Csaba Koles
Csaba Koles
4,644 Points

Don't worry! Everything you learn here is working, but yes, you have to make the IDE's working.

Unfortunately this is not a subject here. :)

Two things I miss:

First, I do not see the class declaration for the main class to run. If you compare my code and your's you can see what I am talking about. Java is a class based language (Object Oriented), so every code you create has to be in a class.

Second, the class name and the file name has to be the same as well, or it will not work.

Example:

Car.java

Has to have its first class as

public class car{

     // Some code in here

}

Hope this will help, if not, keep posting and we will sort it out. :)

PS: just sow that your class is FirstProgramm, so scrap the first comment. Check the second point.

If that is correct too, it should be working and you must have a different problem, Any errors coming up? Any underlined lines in the IDE?

Hey Csaba!

I've checked all of that and still gives me as a error. I feel really dumb right now, i don't know whats is going on. It's just a simple String and doesn't work.

It's something wrong and i don't what it is.

Thats the code i've tried again:

public class Helloworld {

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {

    String world = "World";

    System.out.println("Hello %s\n!", world);
    // TODO code application logic here
}

}

2 Answers

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

You want System.out.printf for formatted text.

Most IDEs don't wire up the console properly. So for doing a readLine try using a BufferedReader approach like so:

mReader = new BufferedReader(new InputStreamReader(System.in));
String result = mReader.readLine();

I end up teaching that later ^ , but in Java Basics, it was a little too out there ;)

Hope that helps!

Thanks for the reply Craig! You are right i didn't finish the entire course i'm ending up the Objects thats my bad!

That code still doesn't work. I better finish the course i see. I was just trying to start practicing a bit by myself...

Csaba Koles
Csaba Koles
4,644 Points

Don't worry! We all did feel dumb at some point! :) The main thing is to keep an error log. Once you figure out what was the issue, take a document or a notebook and write it down and keep this note as the holy grail!

You will run into issues like that ALL the time if you do programming. :) But with a log you can get to the solution within minutes compare to days.

Give a try to Craig's suggestion and change the function.

Otherwise give the above two lines before your System.out call.

Thanks Csaba thats a real helpful advice!! I'll do that for sure.

I think what i can do best now is finish the entire course and then figure it out. Because i think Craig will mention this problem later on.

Thank you!