Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting Up Java - Basic (yet not so basic...) Question

Tags:

java

classpath

I've recently jumped into Java with Head First Java, and I found that the book lacked a lot of information on setting up Java. It pretty much told me to download the JDK, and mentioned something about a classpath variable.

I was very confused, and obviously, my Java wasn't set up to function. So... I researched, and managed to add the /bin/ directory to my CLASS_PATH, and I also made a new system variable called JAVA_HOME and pointed that to the bin folder. I'm not really sure what to do - and this topic is seemingly easy for every other programmer, because I can't find anyone else having this much difficulty setting up their Java environment.

So, I can compile and run programs now. I've done some Hello World stuff, yada yada. Now, on page 37, we're actually going to do some OOP stuff. Here are the classes:

class Movie {
    String title;
    String genre;
    int rating;

    void PlayIt() {
        System.Out.println("Playing the movie");
    }
}

and the second:

public class MovieTestDrive  {
    public static void main(String[] args) {
        Movie one = new Movie();
        one.title = "Movie 1";
        one.genre = "Movie 1 Genre";
        one.rating = -2
        two.title = "Movie 2";
        two.genre = "Movie 2 Genre";
        two.rating = -1
        three.title = "Movie 3";
        three.genre = "Movie 3 Genre";
        three.rating = 3
    }
}

So, I can compile the first class (Movie.java). However, when I try to compile the second class (the object?) - MovieTestDrive.java, I'm returned this error:

MovieTestDrive.java:12: cannot find symbol
symbol : method PlayIt()
location: class Movie
two.playIt();

1 error

I've done some research, and from what I've gathered, I guess Java doesn't know to also look for the first class. However, my research did not find nearly any helpful information at all on how to guide the silly thing to where it is.

like image 715
Brandon Avatar asked Jun 13 '11 14:06

Brandon


People also ask

Why is Java hard beginner?

Learning Java is only hard when you have no technical background or you don't take the proper steps to learn the language. Java syntax is a statically typed machine language that has broad features and frameworks and can be integrated into several platforms. This can make it difficult to grasp as a beginner.


1 Answers

Is there any particular reason that you're not using an IDE such as Eclipse, IntelliJ IDEA or Netbeans?

like image 151
Matt Ball Avatar answered Nov 15 '22 01:11

Matt Ball