java enum class example

Read about java enum class example, The latest news, videos, and discussion topics about java enum class example from alibabacloud.com

Understanding java-4.9 Enum types from the beginning

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

Enum in Java uses

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

Enum of Java

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 () {}

Read Java concurrency Programming practice, adding functionality to a thread-safe class-Client Lock Implementation Example

{PrivateGoodlisthelperGoodlisthelper; PrivateString value; PublicPRINTB (goodlisthelperGoodlisthelper, String value) { This. Goodlisthelper =Goodlisthelper; This. Value =value; } @Override Public voidrun () {goodListHelper.list.add (value); } } Public Static voidMain (string[] args)throwsinterruptedexception {FinalGoodlisthelperNewGoodlisthelper(); NewThread (NewRunnable () {@Override Public voidrun () {Executorservice executor= Executors.newfixedthreadpool (50); for(inti

Super Simple example of the relationship between Java PACKET CLASS and variables

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

Give an example of Java JSON Class library Gson basic usage _java

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 Enum

/*** 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

Credential class Interface Java code example

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

A small example of Java packaging class unpacking

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;/

Java example of asynchronous execution of multiple HTTP requests (requires Apache HTTP class library)

blockE.printstacktrace (); } catch(IOException e) {//TODO auto-generated catch blockE.printstacktrace (); } } }; Service.execute (run); }//block HTTP call private static voidSendrequestasync (String event,string username) throwsInterruptedexception, IOException {requestconfig requestconfig =Requestconfig.custom (). SetSocketTimeout (+)//HTTP timeout. Setconnecttimeout (+). Build (); Connection Timeout Closeablehttpasyncclient httpclient =Httpasyncclients.custom (). Setdefaultrequestconfig (Requ

java enum Turn c#__c#

Refs Http://stackoverflow.com/questions/469287/c-sharp-vs-java-enum-for-those-new-to-c Java public enum Planet {MERCURY (3.303e+23, 2.4397e6), VENUS (4.869e+24, 6.0518e6), Earth (5.976e+24, 6.37814e6), MARS (6.421e+23, 3.3972e6), JUPITER (1.9e+27, 7.1492e7), SATURN (5.688e+26, 6.0268e7), Uranus (8.686E+25, 2). 5559

Java example of asynchronous execution of multiple HTTP requests (requires Apache HTTP class library)

Import Java.util.concurrent.countdownlatch;import Org.apache.http.httpresponse;import Org.apache.http.client.config.requestconfig;import Org.apache.http.client.methods.httpget;import Org.apache.http.concurrent.futurecallback;import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; Import org.apache.http.impl.nio.client.HttpAsyncClients; public class Asyncclienthttpexchangefuturecallback {public static void main (final string[] args) thr

A simple example of using Java's FileReader class to read the contents of a file __java

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

Java Basics Learning--------enum type (1)

The concept of enum types:1 /**2 * Purpose: Enum type3 * @authorChenyanlong4 * Date: 2017/10/225 * Website:http://blog.csdn.net/sup_heaven/article/details/352958516 */7 PackageCom.mon10.day22;8 9 Public classEnumdemoone {Ten One //declaring enum types A Private enuminnerenum{ - Red,green,yellow - }; the - Public Static voidMain (string[

Visual Calendar example of the Calendar class for Java

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

Java thread concurrency Semaphore class example _java

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

A simple example of a private method using reflection to invoke another class in Java _java

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

Enum in Java

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

Java enumeration enum usage and related operations

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

Conversion of JAVA enum and INT--REPRINT

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 =

Total Pages: 15 1 .... 8 9 10 11 12 .... 15 Go to: Go

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.