Click here to Skip to main content
14,982,840 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I'm currently learning MVC for java and I saw this simple tutorial.

What confuses me most is the use of classes

This is for the model:
Java
package MyPackage;
 
public class Course {
       private String CourseName;
       private String CourseId;
       private String CourseCategory;
        
       public String getId() {
          return CourseId;
       }


This is for the VIEW:
Java
package MyPackage;
 
public class CourseView {
       public void printCourseDetails(String CourseName, String CourseId, String CourseCategory){
          System.out.println("Course Details: ");
          System.out.println("Name: " + CourseName);
          System.out.println("Course ID: " + CourseId);
          System.out.println("Course Category: " + CourseCategory);
       }
    }


This is for the Controller:
Java
package MyPackage;
 
public class CourseController {
       private Course model;
       private CourseView view;
 
       public CourseController(Course model, CourseView view){
          this.model = model;
          this.view = view;
       }


In the controller class where the code is written like this
Java
private Course model;
private CourseView view;

is where I'm confused. The Course and CourseView was a Class but treated like a data type? I really don't get it. I got frustrated by this.

What I have tried:

I'm trying to find a good tutorial on what happened there but I don't know what to search for. I tried searching how to use classes in java.

NOTE: I didn't copy the whole code from the website because my thread will become long. I just copied what I think is needed to make my question clear.
Posted
Updated 21-May-21 21:53pm
v2

That's the whole idea: when you create a class, you create a datatype which is that class.

This s fundamental stuff: classes are a huge part of Java (and all other OOPs languages) so it's important that you do understand this stuff.

I'd strongly suggest that instead of looking for a classes tutorial, you get a book on Java, or better sign up for a course and follow it from start to finish - it will introduce concepts in a structured manner and build on those for further items.

O'Reilly, Wrox, and Addison Wesley all do good ones.
   
Comments
lelouch_vi 2 22-May-21 5:51am
   
Quote:That's the whole idea: when you create a class, you create a datatype which is that class.

I see. Thanks for this. I'm still learning Java and all I can see in the tutorials is they used classes just to create an object in the main method. That's why I got confused. As far as I know, I thought classes are a blueprint of an object and never thought that it could be treated like a data type.
Quote:
I'm trying to find a good tutorial
Then you should try the obvious place: The Java™ Tutorials[^].
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900