{"id":22846546,"url":"https://github.com/jsonkao/mks21x","last_synced_at":"2025-03-31T05:41:21.856Z","repository":{"id":114470949,"uuid":"61814152","full_name":"jsonkao/MKS21X","owner":"jsonkao","description":"AP CS Semester 1","archived":false,"fork":false,"pushed_at":"2016-12-22T17:33:48.000Z","size":28337,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-06T10:15:22.882Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jsonkao.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-06-23T15:01:36.000Z","updated_at":"2020-05-06T20:42:06.000Z","dependencies_parsed_at":"2023-06-08T07:15:32.733Z","dependency_job_id":null,"html_url":"https://github.com/jsonkao/MKS21X","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsonkao%2FMKS21X","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsonkao%2FMKS21X/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsonkao%2FMKS21X/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsonkao%2FMKS21X/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jsonkao","download_url":"https://codeload.github.com/jsonkao/MKS21X/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246423494,"owners_count":20774796,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-13T03:29:29.046Z","updated_at":"2025-03-31T05:41:21.827Z","avatar_url":"https://github.com/jsonkao.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# apcs\n\n###12-06-16: ArrayLists\n```\ni --\u003e (i / cols, i % side) // very common mapping for 2D Array represented by 1D Array\n(r, c) --\u003e r * cols + c // is the inverse to the previous mapping\n```\n\n###12-02-16: enhanced for loops\n- cannot change an array like this, unless array's types are mutable (Objects, cars, NOT: Strings, ints)\n\n\n###11-09-16: abstract classes\n**abstract class:** a class that CANNOT BE INSTANTIATED (cannot call new AbstractClass();) but can be extended. (opposite of abstract is concrete)  \n\nShape is abstract--there are things it must do (getArea()) but until we extend it and know more about its child, we cannot do it.  \n\nabstract methods:  \n- can only be put into abstract classes, but abstract classes can contain concrete methods\n- ARE NOT PUBLIC because they are not directly called\n- when it is subclassed, either:\n    - implement all abstract methods (and now they are concrete and callable)\n    - alternately, inherit them as abstract methods, but your subclass has to be abstract (if this is not the case, COMPILE TIME ERROR)\n- inheritance/sharing code yay! don't have to implement code yet, until you have more fields in your subclass\n```\npublic abstract Shape{\n    className(){}\n    abstract getArea(); // note the syntax\n    abstract getPerimeter();\n    public double getSemiPerimeter(){} // not abstract b/c concrete methods can call abstract methods\n}\n```\ntechnicalities:\n```\nShape n;\nShape[] stuff = new Shape[10] // legal, as long as you don't call new Shape();\n\nn = new Circle(); // allowed b/c inheritance rules: circle is subclass of shape\nStuff[0] = n;\nStuff[0].getRadius() // illegal b/c inheritance rules: superclass cannot call subclass's methods/fields; would result in RUNTIME ERROR\n```\n\n###10-28-16: SuperArray\n\nint[] to Array(), problems with ```return data;``` :\n- trash data @ the end\n- this is returning the **exact address**. NEVER EXPOSE the internal structure of your object, use methods.  \n\n###10-25-16: arrays\n\nArrays are objects, not instances.  \n*Instance variables* are primitives and are part of objects. (int bulletsLeft) **default value:** 0  \n*Object variables* (static int flightNumber) **no default value**  \n```\nint[]varname = new int[10]; // instantiates array to specified size\n// varname refers to 10 blocks of memory in the address\nvarname[n] = m; // \"Varname sub n\"\nvarname.length // returns length\n```\n\n###10-24-16: variable types\n\nHierarchy: Agent--\u003eShip--\u003eEnemy,EnemyBomber\n``` \nAgent orange = new Agent();  \nShip tipton = new Ship();  \nEnemy mine = new Enemy();  \n```\nAn object variable can refer to an instance of itself or one of its subclasses\n```\nAgent x, y;  \nShip z;\n\nx = orange; // allowed, b/c referring to instance of itself\ny = tipton; // allowed, b/c referring to instance of its subclass\nz = orange // not allowed, b/c Agent is higher on the hierarchy\n```\nAn object is the reference (type), but its instance can be a subclass\n```\nAgent y = tipton; // agent reference, but ship instance\n(Ship) y; // legal\n```\nSome notes on typecasting upwards: \n```\nclass A has display() which prints \"Hi\".\nclass B extends A has display() which prints \"Bye\".\n\nclass demo {\n    public static void main(String[]args) {\n        B obj = new B();\n        obj.display(); // Bye\n        ( (A) obj ).display(); // Hi\n    }\n}\n```\nAlthough ((A) obj) is still an instance and still has the properties of class B, Java only reads the reference. Here, the reference is A. So even though A obj has the information of B, java will call the A method.\n\nIf you try to type cast upwards and access methods/variables from your original class, it will not work--they are hidden. This is because Java thinks you are a SuperClass, not a SubClass.\n```\nSuperclass s1 = new Superclass(); // works\nSuperclass s2 = new Subclass(); // works b/c superclass is less specific than subclass\nSubclass sub1 = new Superclass(); // COMPILE TIME ERROR b/c subclass is more specific than superclass\nSubclass sub2 = new Subclass(); // works\n```\nYou cannot store a class into a sub version of itself.\n\nRUNTIME ERROR: errors of values (type casting sibling classes)  \nCOMPILE TIME ERROR: errors of type (Subclass sub1 = new Superclass();)\n\n###10-21-16: loops\n\n**for** is used for basic counting.\n```\nfor (init; boolean; increment) {\n    // ...\n}\n```\nIf the init is declared inside the for loop, it only exists within the for loop. The opposite is true.  \nFor v. While:\n- for: easy to read limits, increments, and behavior (it's in the first line)\n- for: increment **always called last**\n- while: have to look through code for the increments, can be anywhere in body\n\n###10-18-16: running archives of classes (jar)\nJava allows the inclusion of other directories and archives of classes (jar files) with the -cp flag.\n```\njavac -cp  .\u003csemi colon separated files/paths\u003e  filename.java\nexample: javac -cp .:core.jar spaceInvaders.java (period is a comma on Windows)\n```\n\n###09-15-16\nCompiled Language\n- Human readable source code is translated (compiled) into machine language run directly by computer. (binary)\n- programs don't run on computer, they run on java virtual machine (JVM) which reads .class files\n- JVM is an interpreter (translates from byte code to machine instructions)\n- .class files are readable by the JVM, independent of platform\n\nThe primitive data types: (you need the ones underlined)\n- int (32 bit, values from -2^31 to +2^31-1)\n- double (64 bit)\n- boolean\n- char (16 bits)\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsonkao%2Fmks21x","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjsonkao%2Fmks21x","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsonkao%2Fmks21x/lists"}