Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.26 KB | None | 0 0
  1. public class ProgramName{
  2.     public static void main(String args[]){
  3.         //canonical entry point for application
  4.     }
  5. }
  6.  
  7. looping:
  8. while(condition){
  9.     // dostuff
  10. }
  11.  
  12. //loop through everything in a collection. This case it's args.
  13. for(String text : args){
  14.     System.out.println(text);
  15. }
  16.  
  17. if(condition){
  18.     //do stuff
  19. }
  20. else{
  21.     //otherwise
  22. }
  23. Else is optional. Remember dangling else though!
  24.  
  25. //here's a simple person class, as if you took it from an SQL server.
  26. public class Person{
  27.     private int IDNumber;
  28.     private String fName;
  29.     private String lName;
  30.     private String pNumber; // really, you mostly treat these things as strings anyway, so why the fuck not?
  31.  
  32.     public Person(int IDNumber, String firstName, String lastName, String phoneNumber){
  33.         this.IDNumber = IDNumber; //this refers to this class' member, as opposed to the one in the method call.
  34.         fName = firstName;
  35.         lName = lastName;
  36.         pNumber = phoneNumber;
  37.     }
  38.  
  39.     private Person(); // this means you can't call new Person() outside this class.
  40.  
  41.     public toString(){
  42.         return fName + " " + lName + " Phone: " + pNumber + "\nInternalID: " +_IDNumber;
  43.     }
  44. }
  45.  
  46. you can now create Person objects with new Person(idNumber, "first name", "last name", "phone number"); but note that nothing validates the phone number.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement