I have been reading a design patterns book and it is full of java. I just have some basic understanding of java. I am now trying to implement some of the codes, but I am facing some difficulties.
For example, there are different classes written in different files. All of these classes have been made into a package. Now, when I try to javac the java file where the main is, it complains that it cannot find the other classes (in this case, WeatherData and CurrentConditionsDisplay).
Here is the main file:
package headfirst.src.observer.weatherobservable;
public class WeatherStation {
public static void main(String[] args) {
WeatherData weatherData = new WeatherData();
CurrentConditionsDisplay currentConditions = new CurrentConditionsDisplay(weatherData);`
//StatisticsDisplay statisticsDisplay = new StatisticsDisplay(weatherData);
//ForecastDisplay forecastDisplay = new ForecastDisplay(weatherData);
weatherData.setMeasurements(80, 65, 30.4f);
weatherData.setMeasurements(82, 70, 29.2f);
weatherData.setMeasurements(78, 90, 29.2f);
}
}
I just need to know how to compile the files properly. The java code in the book is pretty basic, and I can understand it. But I just cannot get the files to compile!!!
I guess you are trying to compile the files via command-line. As I see you have packages, please first try this in an IDE like eclipse to get hands on “how to run the programs?”
Via command-line you need to pass the approriate classpath, which you can learn at a later stage.