GitHub PullRequestReviewCommentEvent at 2014-11-20 18:37:42
Repository: Java-Training
Actor: Utopia1138
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/SandyThomson/Java-Training/pulls/comments/20667023","id":20667023,"diff_hunk":"@@ -0,0 +1,105 @@\n+## Chapter 4 Self Test\n+\n+ 1) _What is the difference between a class and an object?_\n+ \n+ A class defines the contained types, layout, and operations that can be performed on class \n+ instances (the book uses the term _template_, which is reasonable, but unnecessarily confuses\n+ it with the template metaprogramming concept in languages like C++).\n+ \n+ An object is an _instance_ of a class (where per-instance state is allocated in\n+ memory). It should be noted that in Java classes can also have instantiable state (static\n+ members); unlike instances, these are allocated at _class load time_.\n+ \n+ 2) _How is a class defined?_\n+ \n+ ```java\n+ <access modifier|default> <abstract?> class <ClassName> <Generic parameters?> <extends|implements? SomeOtherClass> {\n+   //...\n+ }\n+ ```\n+ \n+ For example:\n+ \n+ ```java\n+ public class Kitteh {}\n+ ```\n+ \n+ Or for more complex classes:\n+ \n+ ```java\n+ public abstract class Convoluted<T extends Thing> extends SimplerBase implements Function<T, String>, Callable<T> {}\n+ ```\n+ \n+ 3) _What does each object have its own copy of?_\n+ \n+ All non-static member variables defined in the class (or base class).\n+ \n+ 4) _Using two separate statements, show how to declare an object called `counter` of a class called `MyCounter`_\n+ \n+ ```java\n+ MyCounter counter;\n+ counter = new MyCounter(1);\n+ ```\n+ \n+ 5) _Show how a method called `myMeth()` is declared if it has a return type of `double` and has two `int`\n+   parameters called a and b._\n+   \n+```java\n+  public double myMeth( int a, int b ); \n+```\n+ \n+ 6) _How must a method return if it returns a value?_\n+ \n+ It must explicitly define `return <type>;` statements wherever control would be returned to the caller. The\n+ one exception to this is, well, throwing exceptions.\n+ \n+ 7) _What name does a constructor have?_\n+ \n+ The identifier of the class it belongs to.\n+ \n+ 8) _What does `new` do?_\n+ \n+ Creates an instance of a type by dynamically allocating memory, then calling the supplied constructor for\n+ the type, returning a reference to the newly allocated instance. In some circumstances it'll throw a\n+ runtime exception (e.g. `OutOfMemoryError`).\n+ \n+ 9) _What is garbage collection, and how does it work? What is `finalize()`?_\n+ \n+ Garbage collection is a means some languages employ of cleaning up dynamically allocated memory for reuse\n+ (languages that don't trust the programmer to properly employ RAII techniques and clean up memory when it's\n+ actually no longer needed as opposed to, say, whenever).\n+ \n+ Techniques vary from simple reference counting (ref descoping decrements a ref count, when it hits zero it\n+ cleans up the memory) to more complex mark and sweep techniques, generational garbage collection etc.\n+ \n+ `finalize` is a method that gets called on an instance when it's eligible for garbage collection but prior\n+ to collection. It can be used to clean up resources owned by the instance, or more dangerously to cause\n+ the instance to become ineligible for collection (_~back from the dead~_).\n+ \n+ It should be noted that whilst Java handles memory automatically, this is not so for various other resources\n+ (file handles, database connections, socket connections, basically any other resource with a concept of\n+ ownership) - here Java _does_ employ RAII with the `AutoCloseable` interface, and notably the new \n+ `try-with-resources` semantics:\n+ ","path":"answers.md","position":83,"original_position":83,"commit_id":"3083591e1125413b9ce2711b6f7a489afa30911b","original_commit_id":"3083591e1125413b9ce2711b6f7a489afa30911b","user":{"login":"Utopia1138","id":2646781,"avatar_url":"https://avatars.githubusercontent.com/u/2646781?v=3","gravatar_id":"","url":"https://api.github.com/users/Utopia1138","html_url":"https://github.com/Utopia1138","followers_url":"https://api.github.com/users/Utopia1138/followers","following_url":"https://api.github.com/users/Utopia1138/following{/other_user}","gists_url":"https://api.github.com/users/Utopia1138/gists{/gist_id}","starred_url":"https://api.github.com/users/Utopia1138/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Utopia1138/subscriptions","organizations_url":"https://api.github.com/users/Utopia1138/orgs","repos_url":"https://api.github.com/users/Utopia1138/repos","events_url":"https://api.github.com/users/Utopia1138/events{/privacy}","received_events_url":"https://api.github.com/users/Utopia1138/received_events","type":"User","site_admin":false},"body":"Yeah, that's what I was getting at - Java employs RAII for resources except memory. In my example below, if a `RuntimeException` is thrown, our file is still closed, because the resource leaving scope causes its `close` method to be called regardless.","created_at":"2014-11-20T18:37:42Z","updated_at":"2014-11-20T18:37:42Z","html_url":"https://github.com/SandyThomson/Java-Training/pull/47#discussion_r20667023","pull_request_url":"https://api.github.com/repos/SandyThomson/Java-Training/pulls/47","_links":{"self":{"href":"https://api.github.com/repos/SandyThomson/Java-Training/pulls/comments/20667023"},"html":{"href":"https://github.com/SandyThomson/Java-Training/pull/47#discussion_r20667023"},"pull_request":{"href":"https://api.github.com/repos/SandyThomson/Java-Training/pulls/47"}}},"pull_request":{"url":"https://api.github.com/repos/SandyThomson/Java-Training/pulls/47","id":24736984,"html_url":"https://github.com/SandyThomson/Java-Training/pull/47","diff_url":"https://github.com/SandyThomson/Java-Training/pull/47.diff","patch_url":"https://github.com/SandyThomson/Java-Training/pull/47.patch","issue_url":"https://api.github.com/repos/SandyThomson/Java-Training/issues/47","number":47,"state":"open","locked":false,"title":"Red - Chapter 4 exercises/test answers","user":{"login":"Utopia1138","id":2646781,"avatar_url":"https://avatars.githubusercontent.com/u/2646781?v=3","gravatar_id":"","url":"https://api.github.com/users/Utopia1138","html_url":"https://github.com/Utopia1138","followers_url":"https://api.github.com/users/Utopia1138/followers","following_url":"https://api.github.com/users/Utopia1138/following{/other_user}","gists_url":"https://api.github.com/users/Utopia1138/gists{/gist_id}","starred_url":"https://api.github.com/users/Utopia1138/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Utopia1138/subscriptions","organizations_url":"https://api.github.com/users/Utopia1138/orgs","repos_url":"https://api.github.com/users/Utopia1138/repos","events_url":"https://api.github.com/users/Utopia1138/events{/privacy}","received_events_url":"https://api.github.com/users/Utopia1138/received_events","type":"User","site_admin":false},"body":"Chapter 4 _Try This_ and self test answers.","created_at":"2014-11-20T01:41:39Z","updated_at":"2014-11-20T18:37:42Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f596f01d3f5d643dc6b1b4252ad023e30942d093","assignee":{"login":"ardavey","id":2790047,"avatar_url":"https://avatars.githubusercontent.com/u/2790047?v=3","gravatar_id":"","url":"https://api.github.com/users/ardavey","html_url":"https://github.com/ardavey","followers_url":"https://api.github.com/users/ardavey/followers","following_url":"https://api.github.com/users/ardavey/following{/other_user}","gists_url":"https://api.github.com/users/ardavey/gists{/gist_id}","starred_url":"https://api.github.com/users/ardavey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ardavey/subscriptions","organizations_url":"https://api.github.com/users/ardavey/orgs","repos_url":"https://api.github.com/users/ardavey/repos","events_url":"https://api.github.com/users/ardavey/events{/privacy}","received_events_url":"https://api.github.com/users/ardavey/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/SandyThomson/Java-Training/pulls/47/commits","review_comments_url":"https://api.github.com/repos/SandyThomson/Java-Training/pulls/47/comments","review_comment_url":"https://api.github.com/repos/SandyThomson/Java-Training/pulls/comments/{number}","comments_url":"https://api.github.com/repos/SandyThomson/Java-Training/issues/47/comments","statuses_url":"https://api.github.com/repos/SandyThomson/Java-Training/statuses/3083591e1125413b9ce2711b6f7a489afa30911b","head":{"label":"SandyThomson:red_chapter4","ref":"red_chapter4","sha":"3083591e1125413b9ce2711b6f7a489afa30911b","user":{"login":"SandyThomson","id":7848639,"avatar_url":"https://avatars.githubusercontent.com/u/7848639?v=3","gravatar_id":"","url":"https://api.github.com/users/SandyThomson","html_url":"https://github.com/SandyThomson","followers_url":"https://api.github.com/users/SandyThomson/followers","following_url":"https://api.github.com/users/SandyThomson/following{/other_user}","gists_url":"https://api.github.com/users/SandyThomson/gists{/gist_id}","starred_url":"https://api.github.com/users/SandyThomson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SandyThomson/subscriptions","organizations_url":"https://api.github.com/users/SandyThomson/orgs","repos_url":"https://api.github.com/users/SandyThomson/repos","events_url":"https://api.github.com/users/SandyThomson/events{/privacy}","received_events_url":"https://api.github.com/users/SandyThomson/received_events","type":"User","site_admin":false},"repo":{"id":24990054,"name":"Java-Training","full_name":"SandyThomson/Java-Training","owner":{"login":"SandyThomson","id":7848639,"avatar_url":"https://avatars.githubusercontent.com/u/7848639?v=3","gravatar_id":"","url":"https://api.github.com/users/SandyThomson","html_url":"https://github.com/SandyThomson","followers_url":"https://api.github.com/users/SandyThomson/followers","following_url":"https://api.github.com/users/SandyThomson/following{/other_user}","gists_url":"https://api.github.com/users/SandyThomson/gists{/gist_id}","starred_url":"https://api.github.com/users/SandyThomson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SandyThomson/subscriptions","organizations_url":"https://api.github.com/users/SandyThomson/orgs","repos_url":"https://api.github.com/users/SandyThomson/repos","events_url":"https://api.github.com/users/SandyThomson/events{/privacy}","received_events_url":"https://api.github.com/users/SandyThomson/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/SandyThomson/Java-Training","description":"","fork":false,"url":"https://api.github.com/repos/SandyThomson/Java-Training","forks_url":"https://api.github.com/repos/SandyThomson/Java-Training/forks","keys_url":"https://api.github.com/repos/SandyThomson/Java-Training/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SandyThomson/Java-Training/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SandyThomson/Java-Training/teams","hooks_url":"https://api.github.com/repos/SandyThomson/Java-Training/hooks","issue_events_url":"https://api.github.com/repos/SandyThomson/Java-Training/issues/events{/number}","events_url":"https://api.github.com/repos/SandyThomson/Java-Training/events","assignees_url":"https://api.github.com/repos/SandyThomson/Java-Training/assignees{/user}","branches_url":"https://api.github.com/repos/SandyThomson/Java-Training/branches{/branch}","tags_url":"https://api.github.com/repos/SandyThomson/Java-Training/tags","blobs_url":"https://api.github.com/repos/SandyThomson/Java-Training/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SandyThomson/Java-Training/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SandyThomson/Java-Training/git/refs{/sha}","trees_url":"https://api.github.com/repos/SandyThomson/Java-Training/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SandyThomson/Java-Training/statuses/{sha}","languages_url":"https://api.github.com/repos/SandyThomson/Java-Training/languages","stargazers_url":"https://api.github.com/repos/SandyThomson/Java-Training/stargazers","contributors_url":"https://api.github.com/repos/SandyThomson/Java-Training/contributors","subscribers_url":"https://api.github.com/repos/SandyThomson/Java-Training/subscribers","subscription_url":"https://api.github.com/repos/SandyThomson/Java-Training/subscription","commits_url":"https://api.github.com/repos/SandyThomson/Java-Training/commits{/sha}","git_commits_url":"https://api.github.com/repos/SandyThomson/Java-Training/git/commits{/sha}","comments_url":"https://api.github.com/repos/SandyThomson/Java-Training/comments{/number}","issue_comment_url":"https://api.github.com/repos/SandyThomson/Java-Training/issues/comments/{number}","contents_url":"https://api.github.com/repos/SandyThomson/Java-Training/contents/{+path}","compare_url":"https://api.github.com/repos/SandyThomson/Java-Training/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SandyThomson/Java-Training/merges","archive_url":"https://api.github.com/repos/SandyThomson/Java-Training/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SandyThomson/Java-Training/downloads","issues_url":"https://api.github.com/repos/SandyThomson/Java-Training/issues{/number}","pulls_url":"https://api.github.com/repos/SandyThomson/Java-Training/pulls{/number}","milestones_url":"https://api.github.com/repos/SandyThomson/Java-Training/milestones{/number}","notifications_url":"https://api.github.com/repos/SandyThomson/Java-Training/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SandyThomson/Java-Training/labels{/name}","releases_url":"https://api.github.com/repos/SandyThomson/Java-Training/releases{/id}","created_at":"2014-10-09T13:20:54Z","updated_at":"2014-11-19T11:35:08Z","pushed_at":"2014-11-20T11:14:09Z","git_url":"git://github.com/SandyThomson/Java-Training.git","ssh_url":"git@github.com:SandyThomson/Java-Training.git","clone_url":"https://github.com/SandyThomson/Java-Training.git","svn_url":"https://github.com/SandyThomson/Java-Training","homepage":null,"size":1557,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":9,"forks":4,"open_issues":9,"watchers":0,"default_branch":"master"}},"base":{"label":"SandyThomson:master","ref":"master","sha":"a10fec7fca35a50c4928eea031d45367721c86a1","user":{"login":"SandyThomson","id":7848639,"avatar_url":"https://avatars.githubusercontent.com/u/7848639?v=3","gravatar_id":"","url":"https://api.github.com/users/SandyThomson","html_url":"https://github.com/SandyThomson","followers_url":"https://api.github.com/users/SandyThomson/followers","following_url":"https://api.github.com/users/SandyThomson/following{/other_user}","gists_url":"https://api.github.com/users/SandyThomson/gists{/gist_id}","starred_url":"https://api.github.com/users/SandyThomson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SandyThomson/subscriptions","organizations_url":"https://api.github.com/users/SandyThomson/orgs","repos_url":"https://api.github.com/users/SandyThomson/repos","events_url":"https://api.github.com/users/SandyThomson/events{/privacy}","received_events_url":"https://api.github.com/users/SandyThomson/received_events","type":"User","site_admin":false},"repo":{"id":24990054,"name":"Java-Training","full_name":"SandyThomson/Java-Training","owner":{"login":"SandyThomson","id":7848639,"avatar_url":"https://avatars.githubusercontent.com/u/7848639?v=3","gravatar_id":"","url":"https://api.github.com/users/SandyThomson","html_url":"https://github.com/SandyThomson","followers_url":"https://api.github.com/users/SandyThomson/followers","following_url":"https://api.github.com/users/SandyThomson/following{/other_user}","gists_url":"https://api.github.com/users/SandyThomson/gists{/gist_id}","starred_url":"https://api.github.com/users/SandyThomson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SandyThomson/subscriptions","organizations_url":"https://api.github.com/users/SandyThomson/orgs","repos_url":"https://api.github.com/users/SandyThomson/repos","events_url":"https://api.github.com/users/SandyThomson/events{/privacy}","received_events_url":"https://api.github.com/users/SandyThomson/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/SandyThomson/Java-Training","description":"","fork":false,"url":"https://api.github.com/repos/SandyThomson/Java-Training","forks_url":"https://api.github.com/repos/SandyThomson/Java-Training/forks","keys_url":"https://api.github.com/repos/SandyThomson/Java-Training/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SandyThomson/Java-Training/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SandyThomson/Java-Training/teams","hooks_url":"https://api.github.com/repos/SandyThomson/Java-Training/hooks","issue_events_url":"https://api.github.com/repos/SandyThomson/Java-Training/issues/events{/number}","events_url":"https://api.github.com/repos/SandyThomson/Java-Training/events","assignees_url":"https://api.github.com/repos/SandyThomson/Java-Training/assignees{/user}","branches_url":"https://api.github.com/repos/SandyThomson/Java-Training/branches{/branch}","tags_url":"https://api.github.com/repos/SandyThomson/Java-Training/tags","blobs_url":"https://api.github.com/repos/SandyThomson/Java-Training/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SandyThomson/Java-Training/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SandyThomson/Java-Training/git/refs{/sha}","trees_url":"https://api.github.com/repos/SandyThomson/Java-Training/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SandyThomson/Java-Training/statuses/{sha}","languages_url":"https://api.github.com/repos/SandyThomson/Java-Training/languages","stargazers_url":"https://api.github.com/repos/SandyThomson/Java-Training/stargazers","contributors_url":"https://api.github.com/repos/SandyThomson/Java-Training/contributors","subscribers_url":"https://api.github.com/repos/SandyThomson/Java-Training/subscribers","subscription_url":"https://api.github.com/repos/SandyThomson/Java-Training/subscription","commits_url":"https://api.github.com/repos/SandyThomson/Java-Training/commits{/sha}","git_commits_url":"https://api.github.com/repos/SandyThomson/Java-Training/git/commits{/sha}","comments_url":"https://api.github.com/repos/SandyThomson/Java-Training/comments{/number}","issue_comment_url":"https://api.github.com/repos/SandyThomson/Java-Training/issues/comments/{number}","contents_url":"https://api.github.com/repos/SandyThomson/Java-Training/contents/{+path}","compare_url":"https://api.github.com/repos/SandyThomson/Java-Training/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SandyThomson/Java-Training/merges","archive_url":"https://api.github.com/repos/SandyThomson/Java-Training/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SandyThomson/Java-Training/downloads","issues_url":"https://api.github.com/repos/SandyThomson/Java-Training/issues{/number}","pulls_url":"https://api.github.com/repos/SandyThomson/Java-Training/pulls{/number}","milestones_url":"https://api.github.com/repos/SandyThomson/Java-Training/milestones{/number}","notifications_url":"https://api.github.com/repos/SandyThomson/Java-Training/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SandyThomson/Java-Training/labels{/name}","releases_url":"https://api.github.com/repos/SandyThomson/Java-Training/releases{/id}","created_at":"2014-10-09T13:20:54Z","updated_at":"2014-11-19T11:35:08Z","pushed_at":"2014-11-20T11:14:09Z","git_url":"git://github.com/SandyThomson/Java-Training.git","ssh_url":"git@github.com:SandyThomson/Java-Training.git","clone_url":"https://github.com/SandyThomson/Java-Training.git","svn_url":"https://github.com/SandyThomson/Java-Training","homepage":null,"size":1557,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":9,"forks":4,"open_issues":9,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/SandyThomson/Java-Training/pulls/47"},"html":{"href":"https://github.com/SandyThomson/Java-Training/pull/47"},"issue":{"href":"https://api.github.com/repos/SandyThomson/Java-Training/issues/47"},"comments":{"href":"https://api.github.com/repos/SandyThomson/Java-Training/issues/47/comments"},"review_comments":{"href":"https://api.github.com/repos/SandyThomson/Java-Training/pulls/47/comments"},"review_comment":{"href":"https://api.github.com/repos/SandyThomson/Java-Training/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/SandyThomson/Java-Training/pulls/47/commits"},"statuses":{"href":"https://api.github.com/repos/SandyThomson/Java-Training/statuses/3083591e1125413b9ce2711b6f7a489afa30911b"}}}}