0

Can java classes be outsourced? I have e.g. a huge Database java with over 1000 lines and much methods to do database stuff such as insert, update etc. I want move similar methods to another file to get a clear file.

PHP can do that with "include(filename)". How can java do that?

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
anika
  • 153
  • 1
  • 2
  • 6
  • 4
    Possible duplicate of [How is import done in Java?](https://stackoverflow.com/questions/1053658/how-is-import-done-in-java) – Joe C Nov 18 '17 at 09:59
  • The actual question is not so much about imports as it is about partial classes: [A way to implement partial classes in Java](https://stackoverflow.com/questions/9876339/a-way-to-implement-partial-classes-in-java) – Crusha K. Rool Nov 19 '17 at 17:42

1 Answers1

0
public class Database {
  //1000 lines of codes
  // updateBankAccount()
  // insertPerson()
} 

//You can refactor them out in different classes:
public class PersonDatabase {
    // insertPerson()
}

Then in the classes using those two classes you can something like that by importing those classes:

import com.demo.PersonDatabase
import com.demo.Database
public class Main {

 void main() {
   new PersonDatabase.intersetPerson()
 }

}
Joe C
  • 15,324
  • 8
  • 38
  • 50
ian1095
  • 551
  • 4
  • 8