In this section, let's talk a little bit about enumeration types.1. Enum type is a data typePackage Com.ray.ch04;public class Test {public static void main (string[] args) {MyType MyType = Mytype.one; System.out.println (MyType instanceof Object);}} Enum MyType {One, both, three}Output:True2. The enumeration type has rewritten the Tosting method and can be output
1. The list of enumerated elements must be written at the top of the enumeration class, separated by commas, and if there is no other content after the end of the list of elements, you may not write a semicolon or you must write.
2. All constructors in the enumeration class are private, and external programs cannot create instances of enumerated classes. An enumeration
syntactic sugar that replaces the static initialization block, all written in right, more intuitive but not enough up (5) concise, because down does not use the direction (int) constructor, so direction () is needed here.2.value-specific class Bodies enumeration value-specific anonymous classespublic enum direction{ up{ @Override void foo () {PLN (UP);} },down,left,right; void foo () {}
One, package packet is a folder, the package under the class to each other to access such as a file.Second, the class interior is equivalent to a Delphi CALSS, static functions can only access static functions.Package mainpack;public class Mainprg {/*** @param args*/public static void Main (string[] args) {TODO auto-generated Method StubHuman Aman=new Human ();Hu
Gson This Java class library converts Java objects to JSON or converts JSON strings into an equal Java object. Gson supports arbitrary complex Java objects including objects that have no source code.Other JSON parsing libraries and Json-lib;jackson;com.alibaba.fastjson.Small
/*** Effective Java Second Edition* 30th: Use enum instead of int constant*/Import Java.util.HashMap;Import Java.util.Map;public class Enumtest {/* Media operation */Public final static int START = 1;Public final static int PAUSE = 2;Public final static int RESUME = 3;Public final static int STOP = 4;/* Return results */Public final static int ret_ok = 1;private
bin = new Filebody (file);Stringbody encapsulates a parameter of type stringStringbody keybody = new Stringbody (key, Contenttype.text_plain);Stringbody typebody = new Stringbody (type, contenttype.text_plain);Addpart Pass the argument and specify the parameter nameHttpentity reqentity = Multipartentitybuilder.create (). Addpart ("Pic", bin). Addpart ("key", Keybody). Addpart ("Cardtype", Typebody). Build ();Httppost.setentity (reqentity);Httppost.setconfig (config);Perform network requests and
Simply put, packing is to convert the value type to the reference type, and unpacking is to convert the reference type to the value type.In fact, there is nothing to say about this. You can see it in the Code:Java code/*** @ Author hellosure* @ Time 2011-7-27 8:10:46 a.m.* @ Description: Example of packing and unpacking*/Public class Test {Public static void main (String arg []) {Int v1 = 100;Int v2 = 100;/
Import java.io.*; public class Filereadersample {public static void main (String args[]) throws IOException {//Create an array that can hold 1024 characters Char Data[]=new char[1024]; Establish object Fr FileReader fr=new filereader ("C://java//donkey.txt"); Read the data into the character list, int num=fr.read (data); Converts a list of characters to a string Str=new string (data,0,num); Outp
ImportJava.text.DateFormat;Importjava.text.ParseException;ImportJava.text.SimpleDateFormat;ImportJava.util.Calendar;Importjava.util.Date;ImportJava.util.GregorianCalendar;ImportJava.util.Scanner;/*** Visual Calendar program **/ Public classVisualcalendar { Public Static voidMain (string[] args) {System.out.println ("Please enter a date (by format: 2015-08-17):"); Scanner Scanner=NewScanner (system.in); String Temp=Scanner.nextline (); //String temp = "2015-8-17";DateFormat format =NewSimpleDateF
Copy Code code as follows:
Package Com.yao;
Import Java.util.concurrent.ExecutorService;Import java.util.concurrent.Executors;Import Java.util.concurrent.Semaphore;
/*** Java 5.0 adds 4 synchronization devices that coordinate the process between threads, respectively:* Semaphore, Countdownlatch, Cyclicbarrier and exchanger.* This example mainly introduces semaphore.* Semaphore is a tool used to m
We know that a Java application cannot access the private method of a persisted class, but Hibernate does not have this restriction to access various levels of methods, such as private, default, protected, public. How does hibernate implement this function? The answer is to use the Java reflection mechanism as follows:
Import java.lang.reflect.InvocationTarg
returns the difference in order of the two enumeration values. Of course, the premise is that two enumeration values must belong to the same enumeration class, otherwise a classcastexception () exception will be thrown. (Visible source code)Color.RED.compareTo (Color.Blue); return result-1(3) The values () method: A static method that returns an array that contains all the enumeration values.Color[] Colors=color.values ();for (Color c:colors) {System
After Java1.5, the enumeration of new features was introduced, before Java had two ways of defining new types: Classes and interfaces. But in special cases, we can't satisfy our needs, for example, we define a color class, which can only have red,blue,green three values and is not valid for other values. Before we introduce enumerations, we typically use them to
name of the enumeration constant.Color c=color.red;System.out.println (c);//return Result: RED(5) ValueOf () Method: This method is relative to the ToString method and returns an enumeration constant of the specified enumeration type with the specified name.Color.valueof ("BLUE"); return Result: Color.Blue(6) Equals () method: Compares references to two enum class objects.Summarize:1. Enumenum--Int:int i =
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.