Javaweb >_< Java Foundation Enhancements ①

Source: Internet
Author: User

Javaweb_ⅰjava Base Enhancement-breakpoints

Ps:bad version number in. class file. This error refers to the Eclipse runtime environment that is lower than the edit Java version. Double-click to set a breakpoint, F5 jumps into the method. Step intoF6 Skip. Step overF7 jumps out of the way. Step return to view variable values: Right-click Watch. Jumps to the beginning of the current method. Drop to frame jumps to the next breakpoint/end application. Resume clears the breakpoint breakpoint. After the breakpoint is debugged, to clear all breakpoint breakpoints in breakpoint after debugging is complete, be sure to remember to end the JVM that runs the breakpoint.Javaweb_ⅱjava Foundation Enhanced--eclipse shortcut keysalt+/Content Assistant ctrl+1 quick fix Ctrl+shift+o Guide Pack Ctrl + shift+ f format Ctrl + Left: See Method Code (source import click Third) ALT + arrow key: Jump between methods ctrl+shift+/add comment or \ go to note Release F2 View method description
ctrl+alt+ Copy line down ALT + move entire row up/down ctrl+t view inheritance chrl+shift+t View Source codeJavaweb_ⅲjava Foundation Enhancement--junit Test Tool junit Type Mismatch:cannot convert from Test to AnnotationType Mismatch:cannot convert from Test to Annotation public class Test {@Test public void Testconnection () {}} is because the class name and the test Test method with the same name
      @Test// must be added, notifying the program to make JUnitpublic      void  testrun            () {new Person ();           P. Run ();      
Run before each test method @before: Initialize the resource @after after each test method: Release the resource @beforeClass run Assert after each test method class before each test method class is run Assert Assert.assertequals (expected value, value returned by method);

Javaweb_ⅳjava base Enhancement-enhanced for loop

@Test Public voidtest1 () {intArr[] = {1, 2, 3 };  for(intNum:arr)        {System.out.println (num); }} @Test Public voidtest2 () {List List=NewArraylist<>(); List.add (1); List.add (2); List.add (3);  for(Object object:list) {inti =(Integer) object;        System.out.println (i); }} @Test Public voidtest3 () {map map=NewLinkedhashmap (); Map.put ("1", "AAA"); Map.put ("2", "ABA"); Map.put ("3", "AAC"); //The first way         for(Object object:map.keySet ()) {String key=(String) object; String value=(String) map.get (key); SYSTEM.OUT.PRINTLN (Key+ "=" +value); }                //The second way         for(Object object:map.entrySet ()) {Map.entry Entry=(Entry) object; String Key=(String) Entry.getkey (); String value=(String) entry.getvalue (); SYSTEM.OUT.PRINTLN (Key+ "=" +value); }    }    /** HASHMAP () through the HASHMAP algorithm to achieve the traditional map data extraction method * 1 * Set set = Map.keyset ();      * Iterator it = set.iterator ();     * while (It.hasnext ()) {* String key = (string) it.next ();     * String value = (string) map.get (key);     * SYS;      *} * * 2 * * Set set = Map.entryset ();     * Iterator it = set.iterator ();      * while (It.hasnext ()) {* Map.entry Entry = (Entry) it.next ();      * String key = (string) entry.getkey ();      * String value = (string) entry.getvalue ();      * SYS; * }     */
Questions to note:The enhanced for loop is only suitable for fetching data. Javaweb_ⅴjava Base Enhancement--enumeration
enumgrade{//classA,b,c,d,e;//Object} @Test Public voidTestgrade () {System. println (Grade.      A. Getnum ()); } @Test Public voidTestchinanum () {System. println (.            A. Getnum ()); System. Out. println (China).      B. Chinanum ()); }//How to define the constructor/method and field of an enumeration/to encapsulate more information. enumGrade {A ("100-90"), B ("100-0090"), C ("100-090"), D ("100-900"), E ("1000-90")); PrivateString value; PrivateGrade (String value) { This. Value =value; }//private constructors, which do not allow the enumeration object to be arbitrarily incremented       PublicString Getnum () {return  This. Value; }//provides information for obtaining an enumerated object externally}//enumerations with abstract methodsenumChina {A ("100-90" ) {             PublicString Chinanum () {return"Excellent";//each enumeration object needs to implement an abstract method            }; }, B ("100-0090" ) {             PublicString Chinanum () {returnExcellent ;      }; }, C ("100-090" ) {             PublicString Chinanum () {returnExcellent ;      }; }, D ("100-900" ) {             PublicString Chinanum () {returnExcellent ;      }; }, E ("1000-90" ) {             PublicString Chinanum () {returnExcellent ;      };      }; PrivateString value; PrivateChina (String value) { This. Value =value; }       PublicString Getnum () {return  This. Value; }       Public AbstractString Chinanum ();//Abstract Methods}
Caveats: Enum type constructors must have an abstract method for private implementation of the interface and need to implement abstract methods when creating objects Single-state design mode :Design pattern of a single-state design enum A{//class A;//object}

Javaweb >_< Java Foundation Enhancements ①

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.