Project Name: development team scheduling software
Project investigation: Java basic syntax
IDE:Eclipse
-
At the beginning of the project, three packages (domain, service and view) were roughly divided according to the functional requirements. These packages have a clear division of labor and show great readability in subsequent calls.
-
When writing each class, you should pay attention to writing set/get methods and null / non null constructors for subsequent calls, which reflects the object-oriented characteristics of Java language.
-
toString() function: for convenience of operation and belonging to Object class, all objects contain this function; If you do not write the toString function and output an Object, it will return xxxx@xxxxxxx Class name plus address form.
public class Orc { public static class A { public String toString() { return "this is A"; } } public static void main(String[] args) { A obj = new A(); System.out.println(obj); } }
Get output:
this is A
public class Orc { public static class A { public String getString() { return "this is A"; } } public static void main(String[] args) { A obj = new A(); System.out.println(obj); System.out.println(obj.getString()); } }
Get output:
xxxx@xxxxxxx
-
Integer class: the integer class wraps a value of the basic type int in the object. The integer class object contains a field of type int. In addition, this class provides multiple methods that can convert between int and String types. It also provides some other constants and methods that are very useful when dealing with int types.
method Return value function byteValue() byte Returns the value of the Integer as byte shortValue() short Returns the value of this Integer as short intValue() int Returns the value of this Integer as int toString() String Returns a String object representing the Integer value equals(Object obj) boolean Compares whether the secondary object is equal to the specified object valueOf(String s) Integer Returns the Integer object that holds the specified String value parseInt(String s) int Converts a numeric string to an int value compareTo(Integer anotherlnteger) Int Compare two Integer objects numerically. If they are equal, 0 is returned; If the value of the calling object is less than the value of otherlnteger, a negative value is returned; If the value of the calling object is greater than the value of otherlnteger, a positive value is returned parseDouble(String s) Double Converts a numeric string to a double value -
Static constants:
public static final int EXAMPLE = 22; public static final double EXAM1 = 23;
-
Static variables:
public static int counter = 0; counter++;
-
instanceof is a binary operator in Java, similar to = =, >, < and other operators.
instanceof is a reserved keyword for Java. Its function is to test whether the object on its left is the instance of the class on its right, and return the data type of boolean.
if (e instanceof Architect)
-
thorws throws the exception in the current class to the higher level, but finally pay attention to try and catch it.
private void addMember() { try { Employee e = listSvc.getEmployee(id); teamSvc.addMember(e); System.out.println("Added successfully"); } catch (TeamException e) { System.out.println("Failed to add, reason:" + e.getMessage()); } --------------------------------------------------------------- public void addMember(Employee e) throws TeamException { // The member is full and cannot be added if (total >= MAX_MEMBER) throw new TeamException("The member is full and cannot be added.");}
-
Import uses the wildcard * to import all classes at one time. Adding the static keyword can call the functions in the class without instantiating the object.
import domain.*; import static service.*;
-
When working on a project, you need to remember to carry out unit tests in the middle of the project. Don't look for bug s after you finish them all at once.