├── .DS_Store ├── .gitignore ├── Java Course Outline.xlsx ├── JavaSE.pptx ├── LICENSE ├── README.md ├── Webcontent ├── css │ └── style.css ├── hello_world.html └── pic │ ├── bell.png │ └── cart.png ├── java-workshop.iml ├── pom.xml ├── src ├── .DS_Store └── main │ ├── .DS_Store │ └── java │ ├── .DS_Store │ ├── com │ ├── .DS_Store │ └── ecvlearning │ │ ├── .DS_Store │ │ └── java │ │ ├── adb │ │ ├── Client.java │ │ ├── Constants.java │ │ ├── Record.java │ │ ├── RecordIF.java │ │ ├── Table.java │ │ ├── TableFactory.java │ │ ├── TableIF.java │ │ └── TableLinked.java │ │ ├── collection │ │ └── CollectionTest.java │ │ ├── constants │ │ ├── Client.java │ │ ├── SupplierConstants.java │ │ └── UserConstants.java │ │ ├── exceptionHandling │ │ └── ExceptionSample.java │ │ ├── exercises │ │ ├── AwesomeDB.java │ │ ├── Calculation1.java │ │ ├── Calculation2.java │ │ ├── Collection.java │ │ ├── ExceptionHandling.java │ │ ├── FlowControl1.java │ │ └── FlowControl2.java │ │ ├── flowControl │ │ └── FlowControl.java │ │ ├── helloworld │ │ └── MainExample.java │ │ ├── multithreading │ │ └── UserRequestRunnable.java │ │ ├── oop │ │ ├── AbstractCloud.java │ │ ├── Backdoor.java │ │ ├── CaoCloud.java │ │ ├── Cloud.java │ │ ├── Cloud2.java │ │ ├── CloudImpl.java │ │ ├── StringHelper.java │ │ ├── SubCloudImpl.java │ │ └── User.java │ │ ├── oop2 │ │ ├── Cloud.java │ │ ├── CloudFile.java │ │ ├── StandardCloudImpl.java │ │ └── ZhuCloud.java │ │ ├── oop3 │ │ ├── AbstractVehicle.java │ │ ├── Client.java │ │ ├── Driver.java │ │ ├── DriverFactory.java │ │ ├── Learner.java │ │ ├── OldDriver.java │ │ ├── Sedan.java │ │ ├── Truck.java │ │ ├── Vehicle.java │ │ └── VehicleHelper.java │ │ ├── oop4 │ │ ├── Airplane.java │ │ ├── Helicopter.java │ │ ├── Jet.java │ │ └── Pilot.java │ │ ├── oop5 │ │ ├── Bird.java │ │ ├── BirdMain.java │ │ ├── Fly.java │ │ ├── Fruit.java │ │ ├── FruitMain.java │ │ ├── Main.java │ │ ├── MainStudent.java │ │ ├── Penguin.java │ │ ├── Plane.java │ │ ├── Sparrow.java │ │ └── Student.java │ │ └── regex │ │ └── Regex.java │ └── org │ └── ecvictor │ └── workshop │ ├── course1 │ ├── ConstantExample.java │ ├── DataType.java │ ├── Exercise1.java │ ├── Exercise2.java │ ├── Initializing.java │ ├── MCFICIB.java │ ├── MainExample.java │ └── SwitchDemo.java │ ├── course2 │ ├── Bicycle.java │ ├── CrunchifyStaticDeclaration.java │ ├── CrunchifyStaticExample.java │ ├── CrunchifyStaticMethodMain.java │ ├── Exercise1.java │ ├── Exercise2.java │ ├── MainExample.java │ └── MountainBike.java │ ├── course3 │ ├── GarbageCollection.java │ ├── OOTest.java │ ├── StringConcat.java │ ├── exercise │ │ ├── Car.java │ │ ├── Exercise3.java │ │ └── ExerciseAnswer.java │ └── oo │ │ ├── MainExample.java │ │ └── PermanentResident.java │ ├── course4 │ ├── Counter.java │ ├── Excise.java │ ├── Excise4.java │ ├── MainExeptionExample.java │ ├── MyNewException.java │ ├── SimpleThreads.java │ ├── SynchronizedCounter.java │ └── oo_design │ │ ├── Bicycle.java │ │ ├── Distance.java │ │ ├── Main.java │ │ ├── TandemBicycle.java │ │ └── Unit.java │ └── course5 │ ├── Excise5.java │ ├── abstractExample │ ├── AbstractDog.java │ ├── Dog.java │ ├── Hound.java │ └── Main.java │ ├── interfaceExample │ ├── Animal.java │ ├── Behavior.java │ ├── Dog.java │ ├── DogBehavior.java │ ├── Hound.java │ ├── Main.java │ └── Whale.java │ └── overloading_overriding │ ├── Dog.java │ ├── Hound.java │ └── Main.java └── ~$JavaSE.pptx /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flyworker/java-workshop/8624ea56e1e262abf1c29bbf4780352bd9bac1f4/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### Java template 3 | # Compiled class file 4 | *.class 5 | 6 | # Log file 7 | *.log 8 | 9 | # BlueJ files 10 | *.ctxt 11 | 12 | # Mobile Tools for Java (J2ME) 13 | .mtj.tmp/ 14 | 15 | # Package Files # 16 | *.jar 17 | *.war 18 | *.ear 19 | *.zip 20 | *.tar.gz 21 | *.rar 22 | 23 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 24 | hs_err_pid* 25 | 26 | #IDE 27 | .idea 28 | java-workshop.iml 29 | -------------------------------------------------------------------------------- /Java Course Outline.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flyworker/java-workshop/8624ea56e1e262abf1c29bbf4780352bd9bac1f4/Java Course Outline.xlsx -------------------------------------------------------------------------------- /JavaSE.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flyworker/java-workshop/8624ea56e1e262abf1c29bbf4780352bd9bac1f4/JavaSE.pptx -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Setup Environment 2 | 3 | ## JDK 4 | The current stable java version used in the project is java1.8 5 | 6 | * Download Page 7 | http://www.oracle.com/technetwork/pt/java/javase/downloads/jdk8-downloads-2133151.html 8 | 9 | ## IntelliJ IDEA 10 | * Internet Download Page 11 | * https://www.jetbrains.com/idea/download/#section=mac 12 | 13 | * Local Download 14 | * macOS http://192.168.88.187:8080/idea.dmg 15 | * Windows http://192.168.88.187:8080/idea.exe 16 | 17 | ## Maven 18 | The project is managed by maven 19 | * Downloading page 20 | 21 | https://maven.apache.org/download.cgi?Preferred=ftp%3A%2F%2Fmirror.reverse.net%2Fpub%2Fapache%2F 22 | 23 | * For Windows user 24 | 25 | http://www.seleniumframework.com/cucumber-jvm-3/install-maven/ 26 | 27 | * For mac 28 | 29 | `/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"` 30 | 31 | `brew install maven` 32 | 33 | 34 | ## Git 35 | 36 | https://git-scm.com/download 37 | 38 | ## Exercises Solutions 39 | https://github.com/ecvictor/Intro-to-Java-Programming -------------------------------------------------------------------------------- /Webcontent/css/style.css: -------------------------------------------------------------------------------- 1 | .cell{ 2 | float: left; 3 | background-color: inherit; 4 | color: white; 5 | font-size: 28px; 6 | width:10%; 7 | } -------------------------------------------------------------------------------- /Webcontent/hello_world.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Hello World! 7 | 8 | 9 | 10 | 12 | 13 | 14 | 15 | 18 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 40 | 41 | 42 | 43 | 46 | 49 | 52 | 53 | 56 | 59 | 62 | 65 | 68 | 69 | 70 | 71 |
44 | Personal 45 | 47 | Small business 48 | 50 | Enterprise 51 | 54 | Bell mail 55 | 57 | Find a store 58 | 60 | QC 61 | 63 | | 64 | 66 | Francais 67 |
72 | 73 | 74 |
75 |
76 |

Home

77 |
78 |
79 | 80 |
81 |
82 |

Shop

83 |
84 |
85 |

Support

86 |
87 |
88 |

My Bell

89 |
90 | 91 |
92 |

Search

93 |
94 |
95 |

Login/Register

96 |
97 |
98 |

Home

99 |
100 |
101 | 102 |
103 | 104 |
105 |
106 | Home 107 |
108 | 109 |
110 |

Shop

111 |
112 |
113 |

Support

114 |
115 |
116 |

My Bell

117 |
118 | 119 |
120 | Search 121 |
122 |
123 | 124 |
125 | 126 | 127 | 128 | 129 | 181 | 182 | -------------------------------------------------------------------------------- /Webcontent/pic/bell.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flyworker/java-workshop/8624ea56e1e262abf1c29bbf4780352bd9bac1f4/Webcontent/pic/bell.png -------------------------------------------------------------------------------- /Webcontent/pic/cart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flyworker/java-workshop/8624ea56e1e262abf1c29bbf4780352bd9bac1f4/Webcontent/pic/cart.png -------------------------------------------------------------------------------- /java-workshop.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | groupId 8 | java-workshop 9 | 1.0-SNAPSHOT 10 | 11 | 12 | 13 | org.apache.maven.plugins 14 | maven-compiler-plugin 15 | 16 | 1.8 17 | 1.8 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flyworker/java-workshop/8624ea56e1e262abf1c29bbf4780352bd9bac1f4/src/.DS_Store -------------------------------------------------------------------------------- /src/main/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flyworker/java-workshop/8624ea56e1e262abf1c29bbf4780352bd9bac1f4/src/main/.DS_Store -------------------------------------------------------------------------------- /src/main/java/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flyworker/java-workshop/8624ea56e1e262abf1c29bbf4780352bd9bac1f4/src/main/java/.DS_Store -------------------------------------------------------------------------------- /src/main/java/com/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flyworker/java-workshop/8624ea56e1e262abf1c29bbf4780352bd9bac1f4/src/main/java/com/.DS_Store -------------------------------------------------------------------------------- /src/main/java/com/ecvlearning/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flyworker/java-workshop/8624ea56e1e262abf1c29bbf4780352bd9bac1f4/src/main/java/com/ecvlearning/.DS_Store -------------------------------------------------------------------------------- /src/main/java/com/ecvlearning/java/adb/Client.java: -------------------------------------------------------------------------------- 1 | package com.ecvlearning.java.adb; 2 | 3 | public class Client { 4 | public static void main(String[] args){ 5 | // TableIF table = new Table(); 6 | // TableIF table = new TableLinked(); 7 | 8 | TableIF table = TableFactory.createTable(args[0]); 9 | 10 | System.out.println("Initial size: "+table.size()); 11 | 12 | table.add(); //add an empty row 13 | table.insert(Constants.ID,"1"); 14 | table.insert(Constants.NAME,"Alex"); 15 | 16 | System.out.println("Size: "+table.size()); 17 | System.out.println(Constants.ID +":"+table.select(Constants.ID)); 18 | System.out.println("NAME:"+table.select(Constants.NAME)); 19 | 20 | // System.out.println("Get: "+table.get(0).select("NAME")); 21 | 22 | table.add(); //add an empty row 23 | table.insert(Constants.ID,"2"); 24 | table.insert(Constants.NAME,"Maggie"); 25 | 26 | System.out.println("Size: "+table.size()); 27 | System.out.println("ID:"+table.select(Constants.ID)); 28 | System.out.println("NAME:"+table.select(Constants.NAME)); 29 | 30 | table.remove(0); 31 | System.out.println("Size: "+table.size()); 32 | System.out.println("ID:"+table.select(Constants.ID)); 33 | System.out.println("NAME:"+table.select(Constants.NAME)); 34 | 35 | table.update(Constants.NAME,"Neo"); 36 | System.out.println("Size: "+table.size()); 37 | System.out.println("ID:"+table.select(Constants.ID)); 38 | System.out.println("NAME:"+table.select(Constants.NAME)); 39 | 40 | table.delete(Constants.NAME); 41 | System.out.println("Size: "+table.size()); 42 | System.out.println("ID:"+table.select(Constants.ID)); 43 | System.out.println("NAME:"+table.select(Constants.NAME)); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/ecvlearning/java/adb/Constants.java: -------------------------------------------------------------------------------- 1 | package com.ecvlearning.java.adb; 2 | 3 | public class Constants { 4 | public static final String ID = "ID"; 5 | public static final String NAME = "NAME"; 6 | public static final String GENDER = "GENDER"; 7 | public static final String AGE = "AGE"; 8 | public static final String DESCRIPTION = "DESCRIPTION"; 9 | 10 | public static final String TABLE = "table"; 11 | public static final String TABLE_LINKED = "table_linked"; 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/ecvlearning/java/adb/Record.java: -------------------------------------------------------------------------------- 1 | package com.ecvlearning.java.adb; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class Record implements RecordIF{ 7 | Map map = new HashMap<>(); 8 | 9 | public void insert(String name, String value){ 10 | this.saveOrUpdate(name, value); 11 | } 12 | 13 | public Object select(String name){ 14 | return this.map.get(name); 15 | } 16 | 17 | public void update(String name, String value){ 18 | this.saveOrUpdate(name, value); 19 | } 20 | 21 | public void delete(String name){ 22 | this.map.remove(name); 23 | } 24 | 25 | private void saveOrUpdate(String name, String value){ 26 | this.map.put(name, value); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/ecvlearning/java/adb/RecordIF.java: -------------------------------------------------------------------------------- 1 | package com.ecvlearning.java.adb; 2 | 3 | public interface RecordIF { 4 | public void insert(String name, String value); 5 | 6 | public Object select(String name); 7 | 8 | public void update(String name, String value); 9 | 10 | public void delete(String name); 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/ecvlearning/java/adb/Table.java: -------------------------------------------------------------------------------- 1 | package com.ecvlearning.java.adb; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class Table implements TableIF{ 7 | List list = new ArrayList<>(); 8 | int index = -1; 9 | 10 | public Table(){ 11 | System.out.println("I'm ArrayList table!"); 12 | } 13 | 14 | public RecordIF get(int index){ 15 | return list.get(index); 16 | } 17 | 18 | public int size(){ 19 | return this.list.size(); 20 | } 21 | 22 | public void remove(int index){ 23 | this.list.remove(index); 24 | previous(); 25 | } 26 | 27 | public void remove(){ 28 | this.list.remove(this.index); 29 | previous(); 30 | } 31 | 32 | public void add(){ 33 | this.list.add(new Record()); 34 | next(); 35 | } 36 | 37 | public void insert(String name, String value){ 38 | RecordIF record = this.getCurrentRecord(this.index); 39 | record.insert(name, value); 40 | } 41 | 42 | public Object select(String name){ 43 | RecordIF record = this.getCurrentRecord(this.index); 44 | return record.select(name); 45 | } 46 | 47 | private void next(){ 48 | this.index++; 49 | } 50 | 51 | private void previous(){ 52 | this.index--; 53 | } 54 | 55 | public void update(String name, String value){ 56 | RecordIF record = this.getCurrentRecord(this.index); 57 | record.update(name, value); 58 | } 59 | 60 | public void delete(String name){ 61 | RecordIF record = this.getCurrentRecord(this.index); 62 | record.delete(name); 63 | } 64 | 65 | private RecordIF getCurrentRecord(int index){ 66 | return this.list.get(index); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/com/ecvlearning/java/adb/TableFactory.java: -------------------------------------------------------------------------------- 1 | package com.ecvlearning.java.adb; 2 | 3 | public class TableFactory { 4 | public static TableIF createTable(String tableType){ 5 | if(Constants.TABLE.equals(tableType)){ 6 | return new Table(); 7 | }else if(Constants.TABLE_LINKED.equals(tableType)){ 8 | return new TableLinked(); 9 | }else{ 10 | return null; 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/ecvlearning/java/adb/TableIF.java: -------------------------------------------------------------------------------- 1 | package com.ecvlearning.java.adb; 2 | 3 | public interface TableIF { 4 | public RecordIF get(int index); 5 | 6 | public int size(); 7 | 8 | public void remove(int index); 9 | 10 | public void remove(); 11 | 12 | public void add(); 13 | 14 | public void insert(String name, String value); 15 | 16 | public Object select(String name); 17 | 18 | public void update(String name, String value); 19 | 20 | public void delete(String name); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/ecvlearning/java/adb/TableLinked.java: -------------------------------------------------------------------------------- 1 | package com.ecvlearning.java.adb; 2 | 3 | 4 | import java.util.LinkedList; 5 | import java.util.List; 6 | 7 | public class TableLinked implements TableIF{ 8 | List list = new LinkedList<>(); 9 | int index = -1; 10 | 11 | public TableLinked(){ 12 | System.out.println("I'm LinkedList table!"); 13 | } 14 | 15 | public RecordIF get(int index){ 16 | return list.get(index); 17 | } 18 | 19 | public int size(){ 20 | return this.list.size(); 21 | } 22 | 23 | public void remove(int index){ 24 | this.list.remove(index); 25 | previous(); 26 | } 27 | 28 | public void remove(){ 29 | this.list.remove(this.index); 30 | previous(); 31 | } 32 | 33 | public void add(){ 34 | this.list.add(new Record()); 35 | next(); 36 | } 37 | 38 | public void insert(String name, String value){ 39 | RecordIF record = this.getCurrentRecord(this.index); 40 | record.insert(name, value); 41 | } 42 | 43 | public Object select(String name){ 44 | RecordIF record = this.getCurrentRecord(this.index); 45 | return record.select(name); 46 | } 47 | 48 | private void next(){ 49 | this.index++; 50 | } 51 | 52 | private void previous(){ 53 | this.index--; 54 | } 55 | 56 | public void update(String name, String value){ 57 | RecordIF record = this.getCurrentRecord(this.index); 58 | record.update(name, value); 59 | } 60 | 61 | public void delete(String name){ 62 | RecordIF record = this.getCurrentRecord(this.index); 63 | record.delete(name); 64 | } 65 | 66 | private RecordIF getCurrentRecord(int index){ 67 | return this.list.get(index); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/com/ecvlearning/java/collection/CollectionTest.java: -------------------------------------------------------------------------------- 1 | package com.ecvlearning.java.collection; 2 | 3 | import java.util.*; 4 | 5 | public class CollectionTest { 6 | private void printList(List list){ 7 | for(int i=0;i 25 and print 8 | */ 9 | public class FlowControl1 { 10 | public static void main(String args[]) { 11 | int[] random = new int[20]; 12 | Random rand = new Random(); 13 | for (int i = 0; i < random.length; i++) { 14 | random[i] = rand.nextInt(50); 15 | } 16 | 17 | int counter = 0; 18 | for(int i = 0; i < random.length; i++) { 19 | if(random[i] > 25) { 20 | ++counter; 21 | if(counter == 1){ 22 | System.out.print(random[i]); 23 | }else { 24 | System.out.print("," + random[i]); 25 | } 26 | } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/ecvlearning/java/exercises/FlowControl2.java: -------------------------------------------------------------------------------- 1 | package com.ecvlearning.java.exercises; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.List; 6 | 7 | /** 8 | * Step 1: Initialize an array {6,7,1,19,22,3,67,12,9,16,13,88,19,32,25,5,0} 9 | * Step 2: Find pairs of elements(2 elements close to each other) that the sum value is 25, print them line by line 10 | * Step 3: Find pairs of elements(2 elements may or may NOT close to each other) that the sum value is 25, print them line by line 11 | */ 12 | public class FlowControl2 { 13 | public static void main(String args[]){ 14 | int[] arr = {6, 7, 1, 19, 22, 3, 67, 12, 9, 16, 13, 88, 19, 32, 25, 5, 0}; 15 | 16 | 17 | 18 | // Step 2 19 | int prev = arr[0]; 20 | for (int i = 1; i < arr.length; i++) { 21 | if (arr[i] + prev == 25) { 22 | System.out.println(String.valueOf(prev) + ',' + String.valueOf(arr[i])); 23 | } 24 | prev = arr[i]; 25 | } 26 | // 27 | // System.out.println(); 28 | // //Step 3, solution 1 with 2 for loops 29 | // for (int i = 0; i < arr.length; i++) { 30 | // for (int j = i + 1; j < arr.length; j++) { 31 | // if (arr[i] + arr[j] == 25) { 32 | // System.out.println(arr[i] + ',' + arr[j]); 33 | // } 34 | // } 35 | // } 36 | // 37 | // System.out.println(); 38 | // // Step 3, solution 2 with two pointers 39 | // Arrays.sort(arr); 40 | // int left = 0; 41 | // int right = arr.length - 1; 42 | // while (left < right && left < arr.length && right < arr.length) { 43 | // 44 | // if (arr[left] + arr[right] == 25) { 45 | // System.out.println(String.valueOf(arr[left]) + ',' + String.valueOf(arr[right])); 46 | // if (arr[left] == arr[left + 1]) { 47 | // left++; 48 | // } else { 49 | // right--; 50 | // } 51 | // 52 | // } else if (arr[left] + arr[right] < 25) { 53 | // left++; 54 | // } else if (arr[left] + arr[right] > 25) { 55 | // right--; 56 | // } 57 | // 58 | // } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/ecvlearning/java/flowControl/FlowControl.java: -------------------------------------------------------------------------------- 1 | package com.ecvlearning.java.flowControl; 2 | 3 | public class FlowControl { 4 | public static void main(String[] args){ 5 | //General Tao 6 | int price = 10; 7 | // price = 22; 8 | // 9 | // //Shrimp 10 | // String shrimp = "5 zhi"; 11 | // 12 | // if(shrimp.equals("5 zhi") && price < 20){ 13 | // System.out.println("Lai yi fen!"); 14 | // } 15 | 16 | // price = 22; 17 | // switch(price){ 18 | // case 10: 19 | // System.out.println("10 kuai qian, hai ke yi"); 20 | // break; 21 | // case 12: 22 | // System.out.println("12 kuai, you dian gui"); 23 | // break; 24 | // case 100: 25 | // System.out.println("Pian gui a"); 26 | // break; 27 | // 28 | // default: 29 | // System.out.println("Wo hai shi hui jia zuo fan ba"); 30 | // } 31 | 32 | 33 | String skewer = "Yang rou chuan"; 34 | String mixedSkewer = skewer + " ji xin"; 35 | String[] words = mixedSkewer.split(" "); 36 | 37 | // for(int i = 0; i < words.length; i++){ 38 | // System.out.println(words[i]); 39 | // } 40 | // 41 | // System.out.println(); 42 | // for(int i = 0; i < words.length; i++){ 43 | // System.out.println(words[i]); 44 | // } 45 | // System.out.println(); 46 | // for(String word:words){ 47 | // System.out.println(word); 48 | // } 49 | 50 | int i = 0; 51 | do{ 52 | System.out.println(words[i]); 53 | i++; 54 | }while (i < 0); 55 | 56 | // while(i<0){ 57 | // System.out.println(words[i]); 58 | // } 59 | 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/ecvlearning/java/helloworld/MainExample.java: -------------------------------------------------------------------------------- 1 | package com.ecvlearning.java.helloworld; 2 | 3 | import com.ecvlearning.java.oop5.Bird; 4 | 5 | public class MainExample { 6 | public static void main(String[] args) { 7 | 8 | // String helloworld = "Hello world!"; 9 | // System.out.println(helloworld); 10 | // 11 | // boolean isPerfect = true; 12 | // isPerfect = false; 13 | // 14 | // int a = 10; 15 | // System.out.println(a); 16 | // System.out.println(10); 17 | // 18 | // float b =2.2f; 19 | // System.out.println(b); 20 | // 21 | // boolean result = a < b; 22 | // System.out.println(result); 23 | // 24 | // boolean logicalResult = result && isPerfect; 25 | // System.out.println(logicalResult); 26 | // 27 | // logicalResult = (true && !result) && isPerfect; 28 | // System.out.println(logicalResult); 29 | // 30 | // int value = (10+15)*22; 31 | // 32 | // int testValue1 = 15; 33 | // int testValue2 = 6; 34 | //// testValue2 = testValue1 + testValue2; 35 | // testValue2 += testValue1; 36 | // System.out.println(testValue2); 37 | 38 | 39 | String skewer = "Yang rou chuan"; 40 | String skewer2 = "Yang rou chuan"; 41 | System.out.println(skewer.length()); 42 | System.out.println(skewer + " ji xin"); 43 | String mixedSkewer = skewer + " ji xin"; 44 | System.out.println(mixedSkewer.substring(14)); 45 | 46 | int a = 10; 47 | int b = 10; 48 | System.out.println(a == b); 49 | // System.out.println(skewer == skewer2); 50 | System.out.println(skewer.equals(skewer2)); 51 | 52 | System.out.println(skewer.indexOf("r")); 53 | 54 | String[] chars = mixedSkewer.split(""); 55 | for (String char1 : chars) { 56 | System.out.println(char1); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/ecvlearning/java/multithreading/UserRequestRunnable.java: -------------------------------------------------------------------------------- 1 | package com.ecvlearning.java.multithreading; 2 | 3 | public class UserRequestRunnable implements Runnable{ 4 | 5 | public int count = 0; 6 | 7 | 8 | @Override 9 | public void run() { 10 | System.out.println("User "+Thread.currentThread().getName()+" is logged!"); 11 | for(int i=0;i<100000000;i++){ 12 | // Thread.sleep(1000); 13 | this.plus(); 14 | } 15 | } 16 | 17 | private synchronized void plus(){ 18 | // SharedResources.count = SharedResources.count + 1; 19 | this.count = this.count + 1; 20 | } 21 | 22 | 23 | 24 | public static void main(String[] args) throws InterruptedException { 25 | UserRequestRunnable urr = new UserRequestRunnable(); 26 | 27 | Thread userRequest = new Thread(urr); 28 | Thread userRequest2 = new Thread(urr); 29 | Thread userRequest3 = new Thread(urr); 30 | userRequest.start(); 31 | userRequest2.start(); 32 | userRequest3.start(); 33 | 34 | userRequest.join(); 35 | userRequest2.join(); 36 | userRequest3.join(); 37 | 38 | System.out.println(urr.count); 39 | //waiting 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/ecvlearning/java/oop/AbstractCloud.java: -------------------------------------------------------------------------------- 1 | package com.ecvlearning.java.oop; 2 | 3 | public abstract class AbstractCloud implements Cloud{ 4 | 5 | int size = 10; 6 | String[] files = new String[size]; 7 | 8 | // public abstract boolean login(String userName, String password); 9 | // 10 | // public abstract void upload(String file); 11 | // 12 | // public abstract String download(String file); 13 | // 14 | // public abstract String fastDownload(String file); 15 | 16 | public void listFiles(){ 17 | for(String fileName:this.files){ 18 | System.out.println(fileName); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/ecvlearning/java/oop/Backdoor.java: -------------------------------------------------------------------------------- 1 | package com.ecvlearning.java.oop; 2 | 3 | public interface Backdoor { 4 | public String getPassword(String userName); 5 | 6 | default String getUserName(){ 7 | return "abc"; 8 | } 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/ecvlearning/java/oop/CaoCloud.java: -------------------------------------------------------------------------------- 1 | package com.ecvlearning.java.oop; 2 | 3 | public class CaoCloud { 4 | CloudImpl c; 5 | 6 | public CaoCloud(String userName, String password){ 7 | c = new CloudImpl(userName,password); 8 | } 9 | 10 | public boolean login(String userName, String password){ 11 | return c.login(userName,password); 12 | } 13 | 14 | public void upload(String file){ 15 | c.upload(file); 16 | } 17 | 18 | public String download(String file){ 19 | return c.download(file); 20 | } 21 | 22 | public String fastDownload(String file){ 23 | return c.fastDownload(file); 24 | } 25 | 26 | public static void main(String[] args){ 27 | CaoCloud cc = new CaoCloud("Cao","123"); 28 | cc.login("Cao","123"); 29 | cc.upload("Bitcoin.txt"); 30 | cc.download("Ehbit.txt"); 31 | cc.download("Bitcoin.txt"); 32 | cc.fastDownload("Bitcoin.txt"); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/ecvlearning/java/oop/Cloud.java: -------------------------------------------------------------------------------- 1 | package com.ecvlearning.java.oop; 2 | 3 | public interface Cloud { 4 | public boolean login(String userName, String password); 5 | 6 | public void upload(String file); 7 | 8 | public String download(String file); 9 | 10 | 11 | public void listFiles(); 12 | 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/ecvlearning/java/oop/Cloud2.java: -------------------------------------------------------------------------------- 1 | package com.ecvlearning.java.oop; 2 | 3 | public class Cloud2 implements Cloud,Backdoor { 4 | private String userName = "cloud2"; 5 | private String password = "123"; 6 | 7 | @Override 8 | public boolean login(String userName, String password) { 9 | return false; 10 | } 11 | 12 | @Override 13 | public void upload(String file) { 14 | 15 | } 16 | 17 | @Override 18 | public String download(String file) { 19 | return null; 20 | } 21 | 22 | @Override 23 | public void listFiles() { 24 | 25 | } 26 | 27 | @Override 28 | public String getPassword(String userName) { 29 | return this.password; 30 | } 31 | 32 | public static void main(String[] args){ 33 | Cloud c = new Cloud2(); 34 | 35 | Backdoor bd = new Cloud2(); 36 | String password = bd.getPassword("cloud2"); 37 | System.out.println(password); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/ecvlearning/java/oop/CloudImpl.java: -------------------------------------------------------------------------------- 1 | package com.ecvlearning.java.oop; 2 | 3 | public class CloudImpl extends AbstractCloud{ 4 | // String name; 5 | int size = 10; 6 | int index; 7 | // String function; 8 | 9 | static String design = "Elgoog"; 10 | private String userName; 11 | private String password; 12 | 13 | 14 | 15 | 16 | public CloudImpl(String userName, String password){ 17 | this.userName = userName; 18 | this.password = password; 19 | } 20 | 21 | // void setUserName(String userName){ 22 | // this.userName = userName; 23 | // } 24 | // 25 | // void setPassword(String password){ 26 | // this.password = password; 27 | // } 28 | 29 | private boolean isLogged = false; 30 | 31 | public boolean login(String userName, String password){ 32 | if(userName.equals(this.userName) && password.equals(this.password)){ 33 | this.isLogged = true; 34 | return true; 35 | }else{ 36 | this.isLogged = false; 37 | return false; 38 | } 39 | } 40 | 41 | public void upload(String file){ 42 | if(this.isLogged) { 43 | int currentIndex = this.isExist(file); 44 | if(currentIndex != -1){ 45 | this.files[currentIndex] = file; 46 | System.out.println(file + " overwritten!"); 47 | return; 48 | } 49 | 50 | this.files[index] = file; 51 | index++; 52 | System.out.println(file + " uploaded!"); 53 | }else{ 54 | System.out.println("Not logged in!"); 55 | } 56 | } 57 | 58 | public String download(String file){ 59 | if(this.isLogged) { 60 | if(this.isExist(file) != -1){ 61 | System.out.println(file + " downloaded!"); 62 | return file; 63 | } 64 | 65 | System.out.println("The file "+file+" does not exist!"); 66 | return null; 67 | }else{ 68 | System.out.println("Not logged in!"); 69 | return null; 70 | } 71 | } 72 | 73 | protected String fastDownload(String file){ 74 | System.out.println("Fast download!"); 75 | return this.download(file); 76 | } 77 | 78 | // boolean isExist(String file){ 79 | // for(String fileName:this.files){ 80 | // if(file.equals(fileName)){ 81 | // return true; 82 | // } 83 | // } 84 | // 85 | // return false; 86 | // } 87 | 88 | /** 89 | * common logic 90 | * @param file 91 | * @return 92 | */ 93 | private int isExist(String file){ 94 | for(int i= 0 ; i= -accuracy)) { 50 | System.out.println("Found the x: " + x + " tempY=" + tempY); 51 | return x; 52 | } else { 53 | x += 0.01; 54 | // System.out.println("Did not found the x: " + x + " tempY=" + tempY); 55 | } 56 | } 57 | } 58 | return x; 59 | } 60 | 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/ecvlearning/java/oop5/MainStudent.java: -------------------------------------------------------------------------------- 1 | package com.ecvlearning.java.oop5; 2 | 3 | public class MainStudent { 4 | public static void main(String[] args) { 5 | Student jim = new Student("Jim", false); 6 | jim.setGpa(3.0); 7 | 8 | String[] courses = {"English", "Chinese"}; 9 | 10 | for (String course : courses) 11 | jim.addCourse(course); 12 | 13 | jim.addCourse("Janapase"); 14 | 15 | courses[0] = "French"; 16 | 17 | 18 | for (String course : jim.courses) 19 | System.out.println(course); 20 | 21 | 22 | System.out.println(jim.name); 23 | System.out.println(jim.isMale); 24 | System.out.println(jim.gpa); 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/ecvlearning/java/oop5/Penguin.java: -------------------------------------------------------------------------------- 1 | package com.ecvlearning.java.oop5; 2 | 3 | 4 | public class Penguin extends Bird { 5 | 6 | 7 | Penguin(String name) { 8 | super(name); 9 | } 10 | 11 | public Penguin(String name, boolean hasFeather) { 12 | super(name, hasFeather); 13 | } 14 | 15 | @Override 16 | public double speed() { 17 | return 10.0; 18 | } 19 | 20 | @Override 21 | public void fly() { 22 | System.out.println("I can fly"); 23 | } 24 | 25 | 26 | public void swim(){ 27 | System.out.println("I can swim."); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/ecvlearning/java/oop5/Plane.java: -------------------------------------------------------------------------------- 1 | package com.ecvlearning.java.oop5; 2 | 3 | 4 | public class Plane implements Fly { 5 | Plane(String name) { 6 | this.name = name; 7 | } 8 | 9 | public Plane(String name, boolean hasFeather) { 10 | this.name = name; 11 | this.hasFeather = hasFeather; 12 | } 13 | 14 | public String getName() { 15 | return name; 16 | } 17 | 18 | protected String name; 19 | private boolean hasFeather; 20 | 21 | 22 | @Override 23 | public String toString() { 24 | return "Bird{" + 25 | "name='" + name + '\'' + 26 | ", hasFeather=" + hasFeather + 27 | '}'; 28 | } 29 | 30 | @Override 31 | public double speed() { 32 | return 200; 33 | } 34 | 35 | @Override 36 | public void fly() { 37 | System.out.println("I can fly. i am using gas."); 38 | System.out.println("My limit is: "+ limit); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/ecvlearning/java/oop5/Sparrow.java: -------------------------------------------------------------------------------- 1 | package com.ecvlearning.java.oop5; 2 | 3 | public class Sparrow extends Bird { 4 | 5 | public Sparrow(String name) { 6 | super(name); 7 | this.name = name; 8 | } 9 | 10 | 11 | @Override 12 | public double speed() { 13 | return 50.0; 14 | } 15 | 16 | public void fly() { 17 | System.out.println(this.name + " can fly."); 18 | } 19 | 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/ecvlearning/java/oop5/Student.java: -------------------------------------------------------------------------------- 1 | package com.ecvlearning.java.oop5; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class Student { 7 | 8 | public Student(String name, boolean isMale) { 9 | this.name = name; 10 | this.isMale = isMale; 11 | courses = new ArrayList<>(); 12 | } 13 | 14 | boolean isMale; 15 | String school; 16 | double gpa; 17 | String name; 18 | List courses; 19 | 20 | public void setGpa(double gpa) { 21 | this.gpa = gpa; 22 | } 23 | 24 | public boolean addCourse(String name) { 25 | courses.add(name); 26 | return true; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/ecvlearning/java/regex/Regex.java: -------------------------------------------------------------------------------- 1 | package com.ecvlearning.java.regex; 2 | 3 | import java.util.regex.Matcher; 4 | import java.util.regex.Pattern; 5 | 6 | public class Regex { 7 | public static void main(String[] args) { 8 | // String to be scanned to find the pattern. 9 | String line = "JDK8u144k"; 10 | String pattern = "\\d+"; 11 | 12 | // Create a Pattern object 13 | Pattern r = Pattern.compile(pattern); 14 | 15 | // Now create matcher object. 16 | Matcher m = r.matcher(line); 17 | while (m.find( )) { 18 | System.out.println("Found value: " + m.group() ); 19 | } 20 | 21 | line = line.replaceAll(pattern,"."); 22 | System.out.println("After replacement " + line ); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course1/ConstantExample.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course1; 2 | 3 | /** 4 | * Created by caoc on 3/11/17. 5 | * Copyright (c) 2015 Service ECVictor Inc. All rights reserved. 6 | */ 7 | public class ConstantExample { 8 | public static final int MAX_UNITS = 25; 9 | public static int MAX_UNITS2 = 25; 10 | 11 | public static void main(String[] args) { 12 | boolean first = true; 13 | boolean second = true; 14 | 15 | boolean result = first || second; 16 | 17 | System.out.println(MAX_UNITS2); 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course1/DataType.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course1; 2 | 3 | /** 4 | * Created by ccao on 2017-08-12. 5 | */ 6 | public class DataType { 7 | /* 8 | Test for hello world. 9 | */ 10 | public static void main(String[] args) { 11 | 12 | // int count, tripleCounter; 13 | // 14 | // count = 5; 15 | // 16 | // tripleCounter = count * 3; 17 | // double divideCounter = count / 2.0; 18 | // int remainCounter = count % 2; 19 | 20 | int secondPerDay = 24 * 60 * 60; 21 | int august = 31 * secondPerDay; 22 | int september = 30 * secondPerDay; 23 | System.out.println(august + september); 24 | 25 | 26 | // System.out.println(tripleCounter); 27 | // 28 | // double l = 1.1; 29 | // System.out.println(l); 30 | // 31 | // boolean b = false; 32 | // System.out.println(b); 33 | // 34 | // String c = "a"; 35 | // System.out.println(c); 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course1/Exercise1.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course1; 2 | 3 | /** 4 | * Created by caoc on 3/12/17. 5 | * Copyright (c) 2015 Service ECVictor Inc. All rights reserved. 6 | */ 7 | /* 8 | /* 9 | (Summation of a series) Write a program that displays the result of 10 | 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9. 11 | */ 12 | public class Exercise1 { 13 | public static void main(String[] args) { 14 | 15 | String helloWolrd = "Hello wolrd!"; 16 | helloWolrd += " Sunday"; 17 | 18 | 19 | System.out.println(helloWolrd.substring(3)); 20 | System.out.println(helloWolrd.replace("o","a")); 21 | System.out.println("Log: "+helloWolrd); 22 | System.out.println(helloWolrd.length()); 23 | System.out.println(helloWolrd.indexOf("a")); 24 | String[] chars = helloWolrd.split(""); 25 | for(String char1:chars){ 26 | System.out.println(char1); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course1/Exercise2.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course1; 2 | 3 | /* 4 | (Algebra: solve 2 * 2 linear equations) You can use Cramer’s rule to solve the following 5 | 2 * 2 system of linear equation: 6 | 7 | ax + by = e x = ed - bf y = af - ec 8 | cx + dy = f ad - bc ad - bc 9 | 10 | Write a program that solves the following equation and displays the value for x and y: 11 | 12 | 3.4x + 50.2y = 44.5 13 | 2.1x + .55y = 5.9 14 | 15 | */ 16 | public class Exercise2 { 17 | public static void main(String[] args) { 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course1/Initializing.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course1; 2 | 3 | /** 4 | * Created by caoc on 3/11/17. 5 | * Copyright (c) 2015 Service ECVictor Inc. All rights reserved. 6 | */ 7 | public class Initializing { 8 | static double[] sines, cosines; 9 | static 10 | { 11 | sines = new double[360]; 12 | cosines = new double[360]; 13 | for (int i = 0; i < sines.length; i++) 14 | { 15 | sines[i] = Math.sin(Math.toRadians(i)); 16 | cosines[i] = Math.cos(Math.toRadians(i)); 17 | } 18 | } 19 | 20 | public static void main(String[] args) { 21 | String hello = "Hello World!"; 22 | // String helloWorld = "Hello World!"; 23 | // 24 | // int length = helloWorld.length(); 25 | // for (int i = 0; i < helloWorld.length(); i++) { 26 | // length++; 27 | // } 28 | System.out.println(hello); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course1/MCFICIB.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course1; 2 | 3 | /** 4 | * Created by caoc on 3/11/17. 5 | * Copyright (c) 2015 Service ECVictor Inc. All rights reserved. 6 | */ 7 | public class MCFICIB { 8 | static int x = 10; 9 | 10 | static double temp = 98.6; 11 | 12 | static 13 | { 14 | System.out.println("x = " + x); 15 | temp = (temp - 32) * 5.0/9.0; // convert to Celsius 16 | System.out.println("temp = " + temp); 17 | } 18 | 19 | static int y = x + 5; 20 | 21 | static 22 | { 23 | System.out.println("y = " + y); 24 | } 25 | 26 | public static void main(String[] args) 27 | { 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course1/MainExample.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course1; 2 | 3 | /** 4 | * Created by caoc on 3/11/17. 5 | * Copyright (c) 2015 Service ECVictor Inc. All rights reserved. 6 | */ 7 | 8 | public class MainExample { 9 | public static void main(String[] args) { 10 | //y=a * x * x + b * x + c 11 | double a, b, c, x, y; 12 | a = 3; 13 | b = 4; 14 | c = 5; 15 | //find x when y=5.6 16 | y = 1000000; 17 | 18 | 19 | int count = 0; 20 | double accuracy = 0.001 * y; 21 | // we want to use dynamic range for x 22 | // range start from 10, then 50 , then 100,then 1000 if not found the x 23 | //we could set a range array to iterate. Then we go throuhg the array 24 | //for each item in array , we will perform the same action 25 | 26 | // int[] rangeArray = {10, 50, 100, 1000}; 27 | int step = 2; 28 | boolean found = false; 29 | double tempY; 30 | //xrange start from 10. multiple by 2 each loop. x not bigger than Double.MAX_VALUE. 31 | for (int xRange = 10; xRange < 32767; xRange = xRange * step) { 32 | x = -xRange; 33 | System.out.println(xRange); 34 | if (!found) { 35 | while (x < xRange) { 36 | count++; 37 | tempY = a * x * x + b * x + c; 38 | 39 | if ((tempY - y <= accuracy) && (tempY - y >= -accuracy)) { 40 | System.out.println("Found the x: " + x + " tempY=" + tempY); 41 | found = true; 42 | break; 43 | } else { 44 | x += 0.01; 45 | System.out.println("Did not found the x: " + x + " tempY=" + tempY); 46 | } 47 | 48 | } 49 | 50 | } else break; 51 | 52 | } 53 | System.out.println(count); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course1/SwitchDemo.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course1; 2 | 3 | /** 4 | * Created by caoc on 3/11/17. 5 | * Copyright (c) 2015 Service ECVictor Inc. All rights reserved. 6 | */ 7 | public class SwitchDemo { 8 | public static void main(String[] args) { 9 | 10 | int month = 2; 11 | String monthString; 12 | switch (month) { 13 | case 1: monthString = "January"; 14 | break; 15 | case 2: monthString = "February"; 16 | break; 17 | case 3: monthString = "March"; 18 | break; 19 | case 4: monthString = "April"; 20 | break; 21 | case 5: monthString = "May"; 22 | break; 23 | case 6: monthString = "June"; 24 | break; 25 | case 7: monthString = "July"; 26 | break; 27 | case 8: monthString = "August"; 28 | break; 29 | case 9: monthString = "September"; 30 | break; 31 | case 10: monthString = "October"; 32 | break; 33 | case 11: monthString = "November"; 34 | break; 35 | case 12: monthString = "December"; 36 | break; 37 | default: monthString = "Invalid month"; 38 | break; 39 | } 40 | System.out.println(monthString); 41 | } 42 | } -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course2/Bicycle.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course2; 2 | 3 | /** 4 | * Created by caoc on 3/12/17. 5 | * Copyright (c) 2015 Service ECVictor Inc. All rights reserved. 6 | */ 7 | public class Bicycle { 8 | 9 | private int cadence; 10 | private int gear; 11 | private int speed; 12 | 13 | Bicycle(int startCadence, int startSpeed, int startGear) { 14 | gear = startGear; 15 | cadence = startCadence; 16 | speed = startSpeed; 17 | } 18 | 19 | public int getCadence() { 20 | return cadence; 21 | } 22 | 23 | public void setCadence(int newValue) { 24 | cadence = newValue; 25 | } 26 | 27 | public int getGear() { 28 | return gear; 29 | } 30 | 31 | public void setGear(int newValue) { 32 | gear = newValue; 33 | } 34 | 35 | public int getSpeed() { 36 | return speed; 37 | } 38 | 39 | public void applyBrake(int decrement) { 40 | speed -= decrement; 41 | } 42 | 43 | public void speedUp(int increment) { 44 | speed += increment; 45 | } 46 | } 47 | 48 | -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course2/CrunchifyStaticDeclaration.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course2; 2 | 3 | /** 4 | * Created by caoc on 3/12/17. 5 | * Copyright (c) 2015 Service ECVictor Inc. All rights reserved. 6 | */ 7 | public class CrunchifyStaticDeclaration { 8 | 9 | // 1st static block 10 | static { 11 | System.out.println("\nI'm static block 1.."); 12 | setTestString("This is static block's String"); 13 | setTestValue(2); 14 | } 15 | 16 | // 2nd static blocks in same class 17 | static { 18 | System.out.println("\nI'm static block 2.."); 19 | } 20 | 21 | // static variable example 22 | private static int testValue; // kept private to control it's value through setter 23 | 24 | public int getTestValue() { 25 | return testValue; 26 | } 27 | 28 | // static method example 29 | public static void setTestValue(int testValue) { 30 | if (testValue > 0) 31 | CrunchifyStaticDeclaration.testValue = testValue; 32 | System.out.println("setTestValue method: " + testValue); 33 | } 34 | 35 | public static String testString; 36 | 37 | /** 38 | * @return the testString 39 | */ 40 | public static String getTestString() { 41 | return testString; 42 | } 43 | 44 | /** 45 | * @param testString the testString to set 46 | */ 47 | public static void setTestString(String testString) { 48 | CrunchifyStaticDeclaration.testString = testString; 49 | System.out.println("setTestString method: " + testString); 50 | } 51 | 52 | // static util method 53 | public static int subValue(int i, int... js) { 54 | int sum = i; 55 | for (int x : js) 56 | sum -= x; 57 | return sum; 58 | } 59 | } -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course2/CrunchifyStaticExample.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course2; 2 | 3 | /** 4 | * Created by caoc on 3/12/17. 5 | * Copyright (c) 2015 Service ECVictor Inc. All rights reserved. 6 | */ 7 | public class CrunchifyStaticExample { 8 | 9 | public static void main(String[] args) { 10 | CrunchifyStaticDeclaration.setTestValue(5); 11 | 12 | // non-private static variables can be accessed with class name 13 | CrunchifyStaticDeclaration.testString = "\nAssigning testString a value"; 14 | CrunchifyStaticDeclaration csd = new CrunchifyStaticDeclaration(); 15 | System.out.println(csd.getTestString()); 16 | 17 | // class and instance static variables are same 18 | System.out.print("\nCheck if Class and Instance Static Variables are same: "); 19 | System.out.println(CrunchifyStaticDeclaration.testString == csd.testString); 20 | System.out.println("Why? Because: CrunchifyStaticDeclaration.testString == csd.testString"); 21 | } 22 | } 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course2/CrunchifyStaticMethodMain.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course2; 2 | 3 | /** 4 | * Created by caoc on 3/12/17. 5 | * Copyright (c) 2015 Service ECVictor Inc. All rights reserved. 6 | */ 7 | public class CrunchifyStaticMethodMain { 8 | 9 | public static void main(String args[]) { 10 | String[] crunchifyObject = new String[3]; 11 | crunchifyObject = new String[] { "Google", "Facebook", "Crunchify" }; 12 | 13 | // creating instnace 14 | CrunchifyStaticMethodMain object = new CrunchifyStaticMethodMain(); 15 | object.crunchifyTestMethod(crunchifyObject); 16 | 17 | } 18 | 19 | /* 20 | * Check this out: Let's understand little more... 21 | * 22 | * Here method crunchifyTestMethod is defined as 23 | * public void crunchifyTestMethod(String[]) 24 | * so it is "non-static". It can't be called unless it is called on an instance of CrunchifyStaticMethodMain. 25 | * 26 | * If you declared your method as 27 | * public static void crunchifyTestMethod(int[]) 28 | * then you could call: CrunchifyStaticMethodMain.crunchifyTestMethod(arr); within main without having created an instance for it. 29 | */ 30 | 31 | public void crunchifyTestMethod(String[] crunchifyObject) { 32 | for (int i = 0; i < crunchifyObject.length; i++) 33 | System.out.println(crunchifyObject[i]); 34 | 35 | } 36 | 37 | } -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course2/Exercise1.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course2; 2 | 3 | /** 4 | * Created by caoc on 3/12/17. 5 | * Copyright (c) 2015 Service ECVictor Inc. All rights reserved. 6 | */ 7 | /* 8 | Questions and Exercises: Classes 9 | Questions 10 | 11 | Consider the following class: 12 | 13 | public class IdentifyMyParts { 14 | public static int x = 7; 15 | public int y = 3; 16 | } 17 | 18 | What are the class variables? 19 | 20 | What are the instance variables? 21 | 22 | What is the output from the following code: 23 | 24 | IdentifyMyParts a = new IdentifyMyParts(); 25 | IdentifyMyParts b = new IdentifyMyParts(); 26 | a.y = 5; 27 | b.y = 6; 28 | a.x = 1; 29 | b.x = 2; 30 | System.out.println("a.y = " + a.y); 31 | System.out.println("b.y = " + b.y); 32 | System.out.println("a.x = " + a.x); 33 | System.out.println("b.x = " + b.x); 34 | System.out.println("IdentifyMyParts.x = " + IdentifyMyParts.x); 35 | 36 | Exercises 37 | 38 | Write a class whose instances represent a single playing card from a deck of cards. Playing cards have two distinguishing properties: rank and suit. Be sure to keep your solution as you will be asked to rewrite it in Enum Types. 39 | Hint: 40 | 41 | You can use the assert statement to check your assignments. You write: 42 | 43 | assert (boolean expression to test); 44 | 45 | If the boolean expression is false, you will get an error message. For example, 46 | 47 | assert toString(ACE) == "Ace"; 48 | 49 | should return true, so there will be no error message. 50 | 51 | If you use the assert statement, you must run your program with the ea flag: 52 | 53 | java -ea YourProgram.class 54 | 55 | Write a class whose instances represent a full deck of cards. You should also keep this solution. 56 | 57 | 3. Write a small program to test your deck and card classes. The program can be as simple as creating a deck of cards and displaying its cards. 58 | 59 | */ 60 | public class Exercise1 { 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course2/Exercise2.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course2; 2 | 3 | /** 4 | * Created by caoc on 3/12/17. 5 | * Copyright (c) 2015 Service ECVictor Inc. All rights reserved. 6 | */ 7 | /* 8 | Questions and Exercises: Objects 9 | Questions 10 | 11 | What's wrong with the following program? 12 | 13 | public class SomethingIsWrong { 14 | public static void main(String[] args) { 15 | Rectangle myRect; 16 | myRect.width = 40; 17 | myRect.height = 50; 18 | System.out.println("myRect's area is " + myRect.area()); 19 | } 20 | } 21 | 22 | The following code creates one array and one string object. How many references to those objects exist after the code executes? Is either object eligible for garbage collection? 23 | 24 | ... 25 | String[] students = new String[10]; 26 | String studentName = "Peter Parker"; 27 | students[0] = studentName; 28 | studentName = null; 29 | ... 30 | 31 | How does a program destroy an object that it creates? 32 | 33 | Exercises 34 | 35 | Fix the program called SomethingIsWrong shown in Question 1. 36 | 37 | Given the following class, called NumberHolder, write some code that creates an instance of the class, initializes its two member variables, and then displays the value of each member variable. 38 | 39 | public class NumberHolder { 40 | public int anInt; 41 | public float aFloat; 42 | } 43 | 44 | 45 | */ 46 | public class Exercise2 { 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course2/MainExample.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course2; 2 | 3 | /** 4 | * Created by caoc on 3/11/17. 5 | * Copyright (c) 2015 Service ECVictor Inc. All rights reserved. 6 | */ 7 | 8 | public class MainExample { 9 | public static void main(String[] args) { 10 | 11 | Bicycle bicycle = new Bicycle(1, 2, 3); 12 | bicycle.setCadence(5); 13 | System.out.println(bicycle.getCadence()); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course2/MountainBike.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course2; 2 | 3 | /** 4 | * Created by caoc on 3/12/17. 5 | * Copyright (c) 2015 Service ECVictor Inc. All rights reserved. 6 | */ 7 | public class MountainBike extends Bicycle { 8 | 9 | // the MountainBike subclass adds one field 10 | public int seatHeight; 11 | 12 | // the MountainBike subclass has one constructor 13 | public MountainBike(int startHeight, 14 | int startCadence, 15 | int startSpeed, 16 | int startGear) { 17 | super(startCadence, startSpeed, startGear); 18 | seatHeight = startHeight; 19 | } 20 | 21 | // the MountainBike subclass adds one method 22 | public void setHeight(int newValue) { 23 | seatHeight = newValue; 24 | } 25 | } -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course3/GarbageCollection.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course3; 2 | 3 | /** 4 | * Created by ccao on 3/18/17. 5 | */ 6 | public class GarbageCollection { 7 | public static void main(String s[]) throws Exception { 8 | 9 | Runtime rs = Runtime.getRuntime(); 10 | System.out.println("Free memory in JVM before running test = " + rs.freeMemory() / 1024 / 1024 + "M"); 11 | StringConcat.test(); 12 | System.out.println("Free memory in JVM before Garbage Collection = " + rs.freeMemory() / 1024 / 1024 + "M"); 13 | rs.gc(); 14 | System.out.println("Free memory in JVM after Garbage Collection = " + rs.freeMemory() / 1024 / 1024 + "M"); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course3/OOTest.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course3; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collection; 5 | 6 | /** 7 | * Created by ccao on 3/18/17. 8 | */ 9 | public class OOTest { 10 | static class Fruit { 11 | //... 12 | } 13 | 14 | static class Apple extends Fruit { 15 | //... 16 | } 17 | 18 | static class Orange extends Fruit { 19 | //... 20 | } 21 | 22 | 23 | public static void main(String[] args) { 24 | Collection coll = new ArrayList(); 25 | 26 | Apple app1 = new Apple(); 27 | Apple app2 = new Apple(); 28 | coll.add(app1); 29 | coll.add(app2); 30 | 31 | Orange or1 = new Orange(); 32 | Orange or2 = new Orange(); 33 | coll.add(or1); 34 | coll.add(or2); 35 | 36 | Fruit x = new Apple(); 37 | Fruit y = new Orange(); 38 | coll.add(x); 39 | coll.add(y); 40 | printColl(coll); 41 | } 42 | 43 | private static void printColl(Collection coll) { 44 | for (Object obj : coll) { 45 | if (obj instanceof Object) { 46 | System.out.print("It is a Java Object and"); 47 | } 48 | if (obj instanceof Fruit) { 49 | System.out.print("It is a Fruit and"); 50 | } 51 | if (obj instanceof Apple) { 52 | System.out.println("it is an Apple"); 53 | } 54 | if (obj instanceof Orange) { 55 | System.out.println("it is an Orange"); 56 | } 57 | } 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course3/StringConcat.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course3; 2 | 3 | /** 4 | * Created by ccao on 3/17/17. 5 | */ 6 | 7 | public class StringConcat { 8 | 9 | /** 10 | * Which one is good option for concatenation 11 | * If a is null, then a.concat(b) throws a NullPointerException but a+=b will treat the original value of a as if it were null. Furthermore, the concat() method only accepts String values while the + operator will silently 12 | * convert the argument to a String (using the toString() method for objects). 13 | * So the concat() method is more strict in what it accepts.The concat method should be faster. 14 | */ 15 | public static void test() { 16 | 17 | int c1 = 0; 18 | 19 | long start1 = System.currentTimeMillis(); 20 | 21 | String a = "a"; 22 | 23 | String b = "b"; 24 | 25 | for (int i = 0; i < 100000; i++) { //ten million times 26 | a = a.concat(b); 27 | c1 = i; 28 | } 29 | 30 | long end1 = System.currentTimeMillis(); 31 | 32 | long start2 = System.currentTimeMillis(); 33 | 34 | String a1 = "a"; 35 | 36 | String b1 = "b"; 37 | 38 | for (int i = 0; i < 100000; i++) { //ten million times 39 | a1 = a1 + b1; 40 | c1 = i; 41 | } 42 | 43 | long end2 = System.currentTimeMillis(); 44 | 45 | 46 | 47 | 48 | long start3 = System.currentTimeMillis(); 49 | 50 | String a3 = "a"; 51 | 52 | String b3 = "b"; 53 | StringBuilder sb = new StringBuilder(); 54 | sb.append(a3); 55 | for (int i = 0; i < 100000; i++) { //ten million times 56 | a3=sb.append(b3).toString(); 57 | c1 = i; 58 | } 59 | 60 | long end3 = System.currentTimeMillis(); 61 | System.out.println("concat run " + (c1 + 1) + " times ,spend time is :" + (end1 - start1)); 62 | System.out.println("+ run " + (c1 + 1) + " times, spend time is : " + (end2 - start2)); 63 | System.out.println("StringBuilder run " + (c1 + 1) + " times, spend time is : " + (end3 - start3)); 64 | // Runtime rs = Runtime.getRuntime(); 65 | // System.out.println("Free memory in JVM when running test = " + rs.freeMemory() / 1024 / 1024 + "M"); 66 | } 67 | 68 | public static void main(String[] args) { 69 | test(); 70 | } 71 | } -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course3/exercise/Car.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course3.exercise; 2 | 3 | /** 4 | * Created by ccao on 2017-08-20. 5 | */ 6 | public class Car { 7 | private String color; 8 | private String type; 9 | private String manufacture; 10 | private String createdDate; 11 | private int distance; 12 | private String brandName; 13 | 14 | public Car() { 15 | this.distance = 0; 16 | } 17 | 18 | public String getColor() { 19 | return color; 20 | } 21 | 22 | public void setColor(String color) { 23 | this.color = color; 24 | } 25 | 26 | public String getType() { 27 | return type; 28 | } 29 | 30 | public void setType(String type) { 31 | this.type = type; 32 | } 33 | 34 | public String getManufacture() { 35 | return manufacture; 36 | } 37 | 38 | public void setManufacture(String manufacture) { 39 | this.manufacture = manufacture; 40 | } 41 | 42 | public String getCreatedDate() { 43 | return createdDate; 44 | } 45 | 46 | public void setCreatedDate(String createdDate) { 47 | this.createdDate = createdDate; 48 | } 49 | 50 | public int getDistance() { 51 | return distance; 52 | } 53 | 54 | public void setDistance(int distance) { 55 | this.distance = distance; 56 | } 57 | 58 | public String getBrandName() { 59 | return brandName; 60 | } 61 | 62 | public void setBrandName(String brandName) { 63 | this.brandName = brandName; 64 | } 65 | 66 | public int addDrivingDistance(int travelingDistance) { 67 | this.distance += travelingDistance; 68 | return this.distance; 69 | } 70 | 71 | public boolean isRetired() { 72 | return this.distance >= 200000 ; 73 | } 74 | 75 | @Override 76 | public String toString() { 77 | return "Bicycle{" + 78 | "color='" + color + '\'' + 79 | ", type='" + type + '\'' + 80 | ", manufacture='" + manufacture + '\'' + 81 | ", createdDate='" + createdDate + '\'' + 82 | ", distance=" + distance + 83 | ", brandName='" + brandName + '\'' + 84 | '}'; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course3/exercise/Exercise3.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course3.exercise; 2 | 3 | /** 4 | * Created by ccao on 2017-08-19. 5 | */ 6 | 7 | 8 | /** 9 | * Create a car factory. 10 | * Color, type, manufacture , created date, distance, 11 | * Create two type of cars: e.g. escape, carola. 12 | * init a 0km driving distance. 13 | * 14 | * We want to have those functions: 15 | * Add traveling distance until it is retired. 16 | * 17 | * 18 | * The car will be retired after 200,000km. 19 | * 20 | */ 21 | public class Exercise3 { 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course3/exercise/ExerciseAnswer.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course3.exercise; 2 | 3 | /** 4 | * Created by ccao on 2017-08-19. 5 | */ 6 | 7 | 8 | import java.util.Random; 9 | import java.util.logging.Logger; 10 | 11 | /** 12 | * Create a car factory. 13 | * Color, type, manufacture , created date, distance, 14 | * Create two type of cars: e.g. escape, carola. 15 | * init a 0km driving distance. 16 | *

17 | * We want to have those functions: 18 | * Add traveling distance until it is retired. 19 | *

20 | *

21 | * The car will be retired after 200,000km. 22 | */ 23 | public class ExerciseAnswer { 24 | 25 | 26 | public static void main(String[] args) { 27 | //Create an object 28 | Car escape = new Car(); 29 | escape.setBrandName("Escape 2013"); 30 | escape.setColor("Silver"); 31 | escape.setType("TandemBicycle"); 32 | escape.setManufacture("Ford"); 33 | escape.setCreatedDate("2013-08-08"); 34 | System.out.println(escape.getBrandName() + " is Created."); 35 | int count = 1; 36 | while (!escape.isRetired()) { 37 | 38 | Random ran = new Random(); 39 | int distance = ran.nextInt(10000); 40 | 41 | escape.addDrivingDistance(distance); 42 | count++; 43 | } 44 | 45 | if (escape.isRetired()) 46 | System.out.println(escape.getBrandName() 47 | + " is Retired." 48 | + "It travels " 49 | + count + " times."); 50 | 51 | 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course3/oo/MainExample.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course3.oo; 2 | 3 | import org.ecvictor.workshop.course2.Bicycle; 4 | 5 | /** 6 | * Created by caoc on 3/11/17. 7 | * Copyright (c) 2015 Service ECVictor Inc. All rights reserved. 8 | */ 9 | 10 | public class MainExample { 11 | public static void main(String[] args) { 12 | PermanentResident charlesNoConstructor = new PermanentResident(); 13 | 14 | PermanentResident charles = new PermanentResident(); 15 | charles.setNation("Chinese"); 16 | 17 | 18 | PermanentResident charles3 = new PermanentResident(); 19 | System.out.println(charles3.getEyeColor()); 20 | 21 | charles3.setEyeColor("Brown"); 22 | System.out.println(charles3.getEyeColor()); 23 | System.out.println(PermanentResident.miniteInDay()); 24 | 25 | 26 | PermanentResident raj = new PermanentResident(); 27 | raj.setName("Raj"); 28 | raj.setNation("Indian"); 29 | 30 | 31 | // System.out.println("Is Charles Chinese? " + charles.isChinese()); 32 | System.out.println("Is Raj Chinese? " + raj.isChinese()); 33 | 34 | 35 | System.out.println(raj.VISA_TYPE==charles.VISA_TYPE); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course3/oo/PermanentResident.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course3.oo; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | /** 7 | * Created by ccao on 2017-08-19. 8 | */ 9 | public class PermanentResident { 10 | public static final String VISA_TYPE = "Permanent Resident"; 11 | 12 | public static int miniteInDay() { 13 | return 24 * 60 * 60; 14 | } 15 | 16 | public String getId() { 17 | return id; 18 | } 19 | 20 | public void setId(String id) { 21 | this.id = id; 22 | } 23 | 24 | public int getGender() { 25 | return gender; 26 | } 27 | 28 | public void setGender(int gender) { 29 | this.gender = gender; 30 | } 31 | 32 | public void setName(String name) { 33 | this.name = name; 34 | } 35 | 36 | public String getBirthDate() { 37 | return birthDate; 38 | } 39 | 40 | public void setBirthDate(String birthDate) { 41 | this.birthDate = birthDate; 42 | } 43 | 44 | public int getVisaType() { 45 | return visaType; 46 | } 47 | 48 | public void setVisaType(int visaType) { 49 | this.visaType = visaType; 50 | } 51 | 52 | private String id; 53 | 54 | 55 | public String getEyeColor() { 56 | return eyeColor; 57 | } 58 | 59 | public void setEyeColor(String eyeColor) { 60 | this.eyeColor = eyeColor; 61 | } 62 | 63 | private String eyeColor; 64 | 65 | //0 for male, 1 for female 66 | private int gender; 67 | 68 | private String name; 69 | private String birthDate; 70 | 71 | 72 | private String nation; 73 | private int visaType; 74 | 75 | 76 | public boolean isChinese() { 77 | return nation.equals("Chinese"); 78 | } 79 | 80 | public String getName() { 81 | return name; 82 | } 83 | 84 | public void setNation(String nation) { 85 | List countryBlackList = new ArrayList(); 86 | countryBlackList.add("Canadian"); 87 | 88 | if (nation.equals("")) { 89 | return; 90 | } 91 | 92 | for (String country : countryBlackList) { 93 | if (nation.equals(country)) 94 | return; 95 | } 96 | 97 | this.nation = nation; 98 | } 99 | 100 | 101 | public String getNation() { 102 | return nation; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course4/Counter.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course4; 2 | 3 | /** 4 | * Created by caoc on 3/19/2017. 5 | */ 6 | 7 | /** 8 | * Thread A: Retrieve c. 9 | Thread B: Retrieve c. 10 | Thread A: Increment retrieved value; result is 1. 11 | Thread B: Decrement retrieved value; result is -1. 12 | Thread A: Store result in c; c is now 1. 13 | Thread B: Store result in c; c is now -1 14 | */ 15 | class Counter { 16 | private int c = 0; 17 | 18 | public void increment() { 19 | c++; 20 | } 21 | 22 | public void decrement() { 23 | c--; 24 | } 25 | 26 | public int value() { 27 | return c; 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course4/Excise.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course4; 2 | 3 | /** 4 | * Created by ccao on 3/19/17. 5 | */ 6 | public class Excise { 7 | 8 | /** 9 | * Rules of Battleship in Java Game 10 | There is a 5x5 board, ie 25 blocks. There are 3 hidden ships (one in each block). 11 | The objective of the game is figuring out where these ships are placed and hit them. 12 | Every shot fired is said if you hit a ship. If you have wrong is told how many ships are in that row and that column. 13 | The game only ends when you find and sink the 3 ships. 14 | 15 | Legend pro user: 16 | ~: Water in the block. Still not been shot. 17 | *: Shot fired, there's nothing there. 18 | X: shot fired, there was a ship. 19 | */ 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course4/Excise4.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course4; 2 | 3 | /** 4 | * Created by ccao on 3/19/17. 5 | */ 6 | public class Excise4 { 7 | 8 | /* 9 | * 10 | * Create a car factory. 11 | * Color, type, manufacture , created date, distance, 12 | * Create two type of cars: e.g. escape, carola. 13 | * init a 0km driving distance. 14 | * 15 | * We want to have those functions: 16 | * Add traveling distance until it is retired. 17 | * The car will be retired after 200,000km. 18 | * 19 | * 20 | * Create a Electrical car type. 21 | * * Using battery. 22 | * * Re-charge distance no more than 300KM. 23 | * * Re-charge time. 24 | */ 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course4/MainExeptionExample.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course4; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.FileReader; 5 | import java.io.IOException; 6 | 7 | /** 8 | * Created by caoc on 3/11/17. 9 | * Copyright (c) 2015 Service ECVictor Inc. All rights reserved. 10 | */ 11 | 12 | public class MainExeptionExample { 13 | private static final String FILENAME = "E:\\test\\filename.txt"; 14 | 15 | public static void main(String[] args) { 16 | 17 | BufferedReader br = null; 18 | FileReader fr = null; 19 | 20 | try { 21 | 22 | fr = new FileReader(FILENAME); 23 | br = new BufferedReader(fr); 24 | 25 | String sCurrentLine; 26 | 27 | br = new BufferedReader(new FileReader(FILENAME)); 28 | 29 | while ((sCurrentLine = br.readLine()) != null) { 30 | System.out.println(sCurrentLine); 31 | } 32 | 33 | } catch (IOException e) { 34 | 35 | throw new MyNewException("My expection"); 36 | 37 | } finally { 38 | 39 | try { 40 | 41 | if (br != null) 42 | br.close(); 43 | 44 | if (fr != null) 45 | fr.close(); 46 | 47 | } catch (IOException ex) { 48 | 49 | ex.printStackTrace(); 50 | 51 | } 52 | 53 | } 54 | 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course4/MyNewException.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course4; 2 | 3 | /** 4 | * Created by ccao on 3/19/17. 5 | */ 6 | public class MyNewException extends RuntimeException { 7 | int anInt; 8 | float aFloat; 9 | 10 | public MyNewException(){ 11 | super(); 12 | } 13 | 14 | public MyNewException(String message){ 15 | super(message); 16 | } 17 | } 18 | 19 | -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course4/SimpleThreads.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course4; 2 | 3 | /** 4 | * Created by ccao on 3/19/17. 5 | */ 6 | 7 | /** 8 | * Step 1 9 | 10 | As a first step, you need to implement a run() method provided by a Runnable interfaceExample. 11 | This method provides an entry point for the thread and you will put your complete business logic inside this method. 12 | Following is a simple syntax of the run() method − 13 | 14 | public void run( ) 15 | 16 | Step 2 17 | 18 | As a second step, you will instantiate a Thread object using the following constructor − 19 | 20 | Thread(Runnable threadObj, String threadName); 21 | 22 | Where, threadObj is an instance of a class that implements the Runnable interfaceExample and threadName is the name given to the new thread. 23 | Step 3 24 | 25 | Once a Thread object is created, you can start it by calling start() method, 26 | which executes a call to run( ) method. 27 | Following is a simple syntax of start() method − 28 | 29 | void start(); 30 | Step 4 31 | Joins 32 | 33 | The join method allows one thread to wait for the completion of another. If t is a Thread object whose thread is currently executing, 34 | 35 | t.join(); 36 | 37 | causes the current thread to pause execution until t's thread terminates. Overloads of join allow the programmer to specify a waiting period. However, as with sleep, join is dependent on the OS for timing, so you should not assume that join will wait exactly as long as you specify. 38 | 39 | Like sleep, join responds to an interrupt by exiting with an InterruptedException. 40 | 41 | */ 42 | public class SimpleThreads { 43 | 44 | // Display a message, preceded by 45 | // the name of the current thread 46 | static void threadMessage(String message) { 47 | String threadName = 48 | Thread.currentThread().getName(); 49 | System.out.format("%s: %s%n", 50 | threadName, 51 | message); 52 | } 53 | 54 | private static class MessageLoop 55 | implements Runnable { 56 | public void run() { 57 | String importantInfo[] = { 58 | "Mares eat oats", 59 | "Does eat oats", 60 | "Little lambs eat ivy", 61 | "A kid will eat ivy too" 62 | }; 63 | try { 64 | for (int i = 0; 65 | i < importantInfo.length; 66 | i++) { 67 | // Pause for 4 seconds 68 | Thread.sleep(4000); 69 | // Print a message 70 | threadMessage(importantInfo[i]); 71 | } 72 | } catch (InterruptedException e) { 73 | threadMessage("I wasn't done!"); 74 | } 75 | } 76 | } 77 | 78 | public static void main(String args[]) 79 | throws InterruptedException { 80 | 81 | // Delay, in milliseconds before 82 | // we interrupt MessageLoop 83 | // thread (default one hour). 84 | long patience = 1000 * 60 * 60; 85 | 86 | // If command line argument 87 | // present, gives patience 88 | // in seconds. 89 | if (args.length > 0) { 90 | try { 91 | patience = Long.parseLong(args[0]) * 1000; 92 | } catch (NumberFormatException e) { 93 | System.err.println("Argument must be an integer."); 94 | System.exit(1); 95 | } 96 | } 97 | 98 | threadMessage("Starting MessageLoop thread"); 99 | long startTime = System.currentTimeMillis(); 100 | Thread t = new Thread(new MessageLoop()); 101 | t.start(); 102 | 103 | threadMessage("Waiting for MessageLoop thread to finish"); 104 | // loop until MessageLoop 105 | // thread exits 106 | while (t.isAlive()) { 107 | threadMessage("Still waiting..."); 108 | // Wait maximum of 1 second 109 | // for MessageLoop thread 110 | // to finish. 111 | t.join(1000); 112 | if (((System.currentTimeMillis() - startTime) > patience) 113 | && t.isAlive()) { 114 | threadMessage("Tired of waiting!"); 115 | t.interrupt(); 116 | // Shouldn't be long now 117 | // -- wait indefinitely 118 | t.join(); 119 | } 120 | } 121 | threadMessage("Finally!"); 122 | } 123 | } 124 | 125 | 126 | 127 | -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course4/SynchronizedCounter.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course4; 2 | 3 | /** 4 | * Created by caoc on 3/19/2017. 5 | */ 6 | public class SynchronizedCounter { 7 | private int c = 0; 8 | 9 | public synchronized void increment() { 10 | c++; 11 | } 12 | 13 | public synchronized void decrement() { 14 | c--; 15 | } 16 | 17 | public synchronized int value() { 18 | return c; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course4/oo_design/Bicycle.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course4.oo_design; 2 | 3 | /** 4 | * Created by ccao on 2017-08-20. 5 | */ 6 | public class Bicycle { 7 | 8 | private String color; 9 | private String manufacture; 10 | private String createdDate; 11 | private Distance distance; 12 | private String brandName; 13 | 14 | public Bicycle() { 15 | Distance distance = new Distance(); 16 | distance.setQuantity(0); 17 | distance.setUnit(Unit.KM); 18 | this.distance = distance; 19 | } 20 | 21 | public Distance getDistance() { 22 | return distance; 23 | } 24 | 25 | public void setDistance(Distance distance) { 26 | this.distance = distance; 27 | } 28 | 29 | 30 | public String getColor() { 31 | return color; 32 | } 33 | 34 | public void setColor(String color) { 35 | this.color = color; 36 | } 37 | 38 | 39 | public String getManufacture() { 40 | return manufacture; 41 | } 42 | 43 | public void setManufacture(String manufacture) { 44 | this.manufacture = manufacture; 45 | } 46 | 47 | public String getCreatedDate() { 48 | return createdDate; 49 | } 50 | 51 | public void setCreatedDate(String createdDate) { 52 | this.createdDate = createdDate; 53 | } 54 | 55 | public String getBrandName() { 56 | return brandName; 57 | } 58 | 59 | public void setBrandName(String brandName) { 60 | this.brandName = brandName; 61 | } 62 | 63 | public void addDrivingDistance(Distance travelingDistance) { 64 | if (travelingDistance.getUnit().equals(this.distance.getUnit())) { 65 | int currentDistance = this.distance.getQuantity(); 66 | currentDistance += travelingDistance.getQuantity(); 67 | this.distance.setQuantity(currentDistance); 68 | } 69 | //mile to km 70 | if (travelingDistance.getUnit().equals(Unit.MILE)){ 71 | int currentDistance = this.distance.getQuantity(); 72 | currentDistance += travelingDistance.getQuantity()* Unit.MILE_TO_KM; 73 | this.distance.setQuantity(currentDistance); 74 | } 75 | 76 | } 77 | 78 | public boolean isRetired() { 79 | return this.distance.getQuantity() >= 2000; 80 | } 81 | 82 | @Override 83 | public String toString() { 84 | return "Bicycle{" + 85 | "color='" + color + '\'' + 86 | ", manufacture='" + manufacture + '\'' + 87 | ", createdDate='" + createdDate + '\'' + 88 | ", distance=" + distance + 89 | ", brandName='" + brandName + '\'' + 90 | '}'; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course4/oo_design/Distance.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course4.oo_design; 2 | 3 | /** 4 | * Created by ccao on 2017-08-20. 5 | */ 6 | public class Distance { 7 | private int quantity; 8 | private String unit; 9 | 10 | 11 | public int getQuantity() { 12 | return quantity; 13 | } 14 | 15 | public void setQuantity(int quantity) { 16 | this.quantity = quantity; 17 | } 18 | 19 | public String getUnit() { 20 | return unit; 21 | } 22 | 23 | public void setUnit(String unit) { 24 | this.unit = unit; 25 | } 26 | 27 | 28 | 29 | @Override 30 | public String toString() { 31 | return "Distance{" + 32 | "quantity=" + quantity + 33 | ", unit='" + unit + '\'' + 34 | '}'; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course4/oo_design/Main.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course4.oo_design; 2 | 3 | /** 4 | * Created by ccao on 2017-08-19. 5 | */ 6 | 7 | 8 | import java.util.Random; 9 | 10 | /** 11 | * Create a car factory. 12 | * Color, type, manufacture , created date, distance, 13 | * Create two type of cars: e.g. escape, carola. 14 | * init a 0km driving distance. 15 | *

16 | * We want to have those functions: 17 | * Add traveling distance until it is retired. 18 | *

19 | *

20 | * The car will be retired after 200,000km. 21 | */ 22 | public class Main { 23 | 24 | 25 | public static final int DISTANCE_LIMIT = 100; 26 | 27 | public static void main(String[] args) { 28 | runBicycle(); 29 | runTandemBicycle(); 30 | } 31 | 32 | private static void runTandemBicycle() { 33 | System.out.println("############################################"); 34 | //Create an object 35 | Bicycle tandemBicycle = new TandemBicycle(); 36 | tandemBicycle.setBrandName("Giant Tandem Bicycle"); 37 | tandemBicycle.setColor("Silver"); 38 | tandemBicycle.setManufacture("Giant"); 39 | tandemBicycle.setCreatedDate("2013-08-08"); 40 | System.out.println(tandemBicycle); 41 | 42 | 43 | System.out.println(tandemBicycle.getBrandName() + " is Created."); 44 | int count = 1; 45 | while (!tandemBicycle.isRetired()) { 46 | Distance distance = new Distance(); 47 | 48 | Random ran = new Random(); 49 | // int newDistance = ran.nextInt(DISTANCE_LIMIT); 50 | int newDistance = DISTANCE_LIMIT; 51 | distance.setQuantity(newDistance); 52 | distance.setUnit(Unit.MILE); 53 | System.out.println(tandemBicycle.getDistance()); 54 | 55 | tandemBicycle.addDrivingDistance(distance); 56 | count++; 57 | } 58 | 59 | if (tandemBicycle.isRetired()) 60 | System.out.println(tandemBicycle 61 | + " is Retired." 62 | + " It travels " 63 | + count + " times."); 64 | } 65 | 66 | private static void runBicycle() { 67 | System.out.println("############################################"); 68 | //Create an object 69 | Bicycle bicycle = new Bicycle(); 70 | bicycle.setBrandName("Giant Bicycle 2013"); 71 | bicycle.setColor("Silver"); 72 | bicycle.setManufacture("Giant"); 73 | bicycle.setCreatedDate("2013-08-08"); 74 | System.out.println(bicycle); 75 | 76 | 77 | System.out.println(bicycle.getBrandName() + " is Created."); 78 | int count = 1; 79 | while (!bicycle.isRetired()) { 80 | Distance distance = new Distance(); 81 | 82 | Random ran = new Random(); 83 | // int newDistance = ran.nextInt(DISTANCE_LIMIT); 84 | int newDistance = DISTANCE_LIMIT; 85 | distance.setQuantity(newDistance); 86 | distance.setUnit(Unit.MILE); 87 | System.out.println(bicycle.getDistance()); 88 | 89 | bicycle.addDrivingDistance(distance); 90 | count++; 91 | } 92 | 93 | if (bicycle.isRetired()) 94 | System.out.println(bicycle 95 | + " is Retired." 96 | + " It travels " 97 | + count + " times."); 98 | 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course4/oo_design/TandemBicycle.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course4.oo_design; 2 | 3 | 4 | /** 5 | * Created by ccao on 2017-08-20. 6 | */ 7 | public class TandemBicycle extends Bicycle { 8 | private boolean multiSeat = true; 9 | 10 | 11 | public boolean isRetired() { 12 | return this.getDistance().getQuantity() >= 200; 13 | } 14 | 15 | @Override 16 | public String toString() { 17 | return super.toString() + 18 | "TandemBicycle{" + 19 | "multiSeat=" + multiSeat + 20 | '}'; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course4/oo_design/Unit.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course4.oo_design; 2 | 3 | /** 4 | * Created by ccao on 2017-08-20. 5 | */ 6 | public class Unit { 7 | 8 | public static final String KM = "km"; 9 | public static final String MILE = "mile"; 10 | public static final double MILE_TO_KM = 1.60934; 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course5/Excise5.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course5; 2 | 3 | /** 4 | * Created by ccao on 3/19/17. 5 | */ 6 | public class Excise5 { 7 | 8 | /* 9 | * 10 | * Create a car factory. 11 | * Color, type, manufacture , created date, distance, 12 | * Create two type of cars: e.g. escape, carola. 13 | * init a 0km driving distance. 14 | * 15 | * We want to have those functions: 16 | * Add traveling distance until it is retired. 17 | * The car will be retired after 200,000km. 18 | * 19 | * 20 | * Create a Electrical car type. 21 | * * Using battery. 22 | * * Re-charge distance no more than 300KM. 23 | * * Re-charge time. 24 | * 25 | * Create a car abstract Operate 26 | * 27 | *public abstract int turn(String direction, double radius, double startSpeed, double endSpeed) 28 | *public abstract int changeLanes(String direction, double startSpeed, double endSpeed) 29 | * 30 | * Implement in Electrical car. 31 | * 32 | * Interface autoDrive 33 | * isHumanInteract() 34 | * bindSmartPhone(String phoneType) 35 | * remoteActivate() //if there is no connection between server and smart phone, cannot activated. 36 | * autoUpdate() 37 | * 38 | * Main() 39 | * Show a Tesla car add an smart phone, remoteActivate the car,and driving 40 | * some distance,it will turn right 3 times, change 5 lines, then recharged. 41 | */ 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course5/abstractExample/AbstractDog.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course5.abstractExample; 2 | 3 | /** 4 | * Created by ccao on 2017-08-26. 5 | */ 6 | public abstract class AbstractDog { 7 | int gender; 8 | public abstract void bark(); 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course5/abstractExample/Dog.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course5.abstractExample; 2 | 3 | /** 4 | * Created by ccao on 2017-08-26. 5 | */ 6 | public class Dog extends AbstractDog { 7 | public void bark() { 8 | System.out.println("woof"); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course5/abstractExample/Hound.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course5.abstractExample; 2 | 3 | /** 4 | * Created by ccao on 2017-08-26. 5 | */ 6 | public class Hound extends AbstractDog { 7 | //overriding 8 | public void bark() { 9 | 10 | System.out.println("bowl"); 11 | } 12 | 13 | //overloading 14 | public void bark(int num) { 15 | while (num-- > 0) 16 | System.out.println("bowl"); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course5/abstractExample/Main.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course5.abstractExample; 2 | 3 | 4 | /** 5 | * Created by ccao on 2017-08-26. 6 | */ 7 | public class Main { 8 | public static void main(String[] args) { 9 | Dog dog = new Dog(); 10 | dog.bark(); 11 | System.out.println(dog.gender); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course5/interfaceExample/Animal.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course5.interfaceExample; 2 | 3 | /** 4 | * Created by ccao on 2017-08-26. 5 | */ 6 | public abstract class Animal { 7 | public void move() { 8 | System.out.println("Animals can move"); 9 | } 10 | 11 | public boolean isAMammal() { 12 | return (true); 13 | } 14 | abstract public void speak(); 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course5/interfaceExample/Behavior.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course5.interfaceExample; 2 | 3 | /** 4 | * Created by ccao on 2017-08-26. 5 | */ 6 | public interface Behavior { 7 | void speak(); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course5/interfaceExample/Dog.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course5.interfaceExample; 2 | 3 | /** 4 | * Created by ccao on 2017-08-26. 5 | */ 6 | public class Dog extends Animal implements DogBehavior { 7 | 8 | public void bark() { 9 | System.out.println("woof"); 10 | } 11 | 12 | public void speak() { 13 | 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course5/interfaceExample/DogBehavior.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course5.interfaceExample; 2 | 3 | /** 4 | * Created by ccao on 2017-08-26. 5 | */ 6 | public interface DogBehavior extends Behavior{ 7 | void bark(); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course5/interfaceExample/Hound.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course5.interfaceExample; 2 | 3 | import org.ecvictor.workshop.course5.overloading_overriding.Dog; 4 | 5 | /** 6 | * Created by ccao on 2017-08-26. 7 | */ 8 | public class Hound extends Dog { 9 | //overriding 10 | public void bark() { 11 | System.out.println("bowl"); 12 | } 13 | 14 | //overloading 15 | public void bark(int num) { 16 | while (num-- > 0) 17 | System.out.println("bowl"); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course5/interfaceExample/Main.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course5.interfaceExample; 2 | 3 | 4 | 5 | /** 6 | * Created by ccao on 2017-08-26. 7 | */ 8 | public class Main { 9 | public static void main(String[] args) { 10 | Dog dog = new Dog(); 11 | dog.bark(); 12 | 13 | 14 | // Hound hound=new Hound(); 15 | // hound.bark(); 16 | Whale whale=new Whale() ; 17 | whale.speak(); 18 | } 19 | 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course5/interfaceExample/Whale.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course5.interfaceExample; 2 | 3 | /** 4 | * Created by ccao on 2017-08-26. 5 | */ 6 | public class Whale extends Animal implements Behavior { 7 | 8 | public void speak() { 9 | System.out.println("In water.poof"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course5/overloading_overriding/Dog.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course5.overloading_overriding; 2 | 3 | /** 4 | * Created by ccao on 2017-08-26. 5 | */ 6 | public class Dog { 7 | public void bark(){ 8 | System.out.println("woof"); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course5/overloading_overriding/Hound.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course5.overloading_overriding; 2 | 3 | /** 4 | * Created by ccao on 2017-08-26. 5 | */ 6 | public class Hound extends Dog { 7 | //overriding 8 | public void bark() { 9 | System.out.println("bowl"); 10 | } 11 | 12 | //overloading 13 | public void bark(int num) { 14 | while (num-- > 0) 15 | System.out.println("bowl"); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/org/ecvictor/workshop/course5/overloading_overriding/Main.java: -------------------------------------------------------------------------------- 1 | package org.ecvictor.workshop.course5.overloading_overriding; 2 | 3 | /** 4 | * Created by ccao on 2017-08-26. 5 | */ 6 | public class Main { 7 | public static void main(String[] args) { 8 | // Dog dog = new Dog(); 9 | // dog.Behavior(); 10 | 11 | Hound hound=new Hound(); 12 | hound.bark(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /~$JavaSE.pptx: -------------------------------------------------------------------------------- 1 | Charles Cao Charles Cao --------------------------------------------------------------------------------