I'm self learning Java now and I have only vary basic knowledge of object oriented programing. I have chosen to make a project that could be used in real life, a Computer Repair Shop software for tracking tickets, devices, clients and other related things.
I have two questions.:
I have chosen to learn the language by using it while making a project. Is this good or bad way to learn programing?
While I am learning the language I have also focused on learning good coding style so I don't pick up bad habits in code writing. Am I focusing on code style prematurely, or is it good to learn that hand in hand with the language itself?
Trying to create a project is a pretty good way to learn! A few things:
Class names should start with upper case letters, like String
, variable and method names should use the camel case naming convention: myVariable
, myMethod
. An exception is when a variable is constant, full upper case name in that case:
final in MY_CONSTANT = 3;
Always give clear names for your variables and methods, so it's possible to know what they do just by reading the name.
Comment your code! This is very important, as good, informative comments will help you and others understand the code. You can also take a look at (Javadoc comments).[https://www.tutorialspoint.com/java/java_documentation.htm]
You already mentioned object oriented programming, so don't be afraid to make classes for the entities in your project, like Customer
or Device
. You can combine the classes to better model your Computer Repair Shop:
public class Customer {
private String name;
private List<Device> devices; //all devices of the customer
public Customer(String name) {
this.name = name;
devices = new ArrayList<>();
}
public void registerDevice(Device d) {
devices.add(d);
}
}
This is just a stupid little example of course, but you get the point.