Enum - core java II example

hi
the following code is an example taken from 'core java II'-book.
what i don't understand is where the enum constructor is called
to set the abbreviation field
anyone care to explain ?
thanks
import java.util.*;
public class EnumTest {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter a size: (SMALL, MEDIUM, LARGE, EXTRA_LARGE) ");
        String input = in.next().toUpperCase();
        Size size = Enum.valueOf(Size.class, input);
        System.out.println("size=" + size);
        System.out.println("abbreviation=" + size.getAbbreviation());
        if (size == Size.EXTRA_LARGE) {
            System.out.println("Good job--you paid attention to the _.");
enum Size {
    SMALL("S"), MEDIUM("M"), LARGE("L"), EXTRA_LARGE("XL");
    private Size(String abbreviation) {
        this.abbreviation = abbreviation;
    public String getAbbreviation() {
        return abbreviation;
    private String abbreviation;
}

so from what i get here is that
SMALL("S"),MEDIUM("M"),LARGE("L"); are the constructors from where abbreviations are taken.
I want to clear one more doubt.
private Size(String abbreviation) {
        this.abbreviation = abbreviation;1. This is also a constructor right ? If yes then, what was the need that the author made this constructor private ?
2. Why public modifier is not allowed there ?
3. Size s = Enum.valueOf(Size.class,input);Over here what is the role of argument Size.class ?
4. enum size
Size s = Enum.valueOf(Size.class,input);In the first code enum's e is small but in the second code Enum's E is capital. How so ?
Edited by: levislover on Jun 16, 2010 11:29 PM

Similar Messages

  • What is the diffrence between  map and map.entry in core java

    what is the diffrence between map and map.entry in core java . where it will be use ful. any one give one example plz.

    A Map contains Map.Entry's
    e.g.
            Map map = new LinkedHashMap(8);
            map.put(new Integer(1), "one");
            map.put(new Integer(2), "two");
            final Iterator iterator = map.entrySet().iterator();
            while (iterator.hasNext()) {
                Map.Entry entry = (Map.Entry) iterator.next();
                System.out.println("key=" + entry.getKey() + ", value=" + entry.getValue());
            }

  • Need a good core java book

    As I am a beginer and I have a little bit knowledge of OOPs concepts, So any one suggest me a book which explains each concept of OOps with explanation and sufficent examples upto SWINGS and JDBC connections.

    * Horstmann, C. S. and Cornell, G. (2004). Core
    Java 2, Volume I� Fundamentals, 7th edition.
    Upper Saddle River: Prentice Hall PTR.
    * Horstmann, C. S. and Cornell, G. (2004). Core
    Java 2, Volume II� Advanced Features, 7th
    edition. Upper Saddle River: Prentice Hall PTR.Both great titles, they are sat next to me now.
    If you are a true beginner then I'd also recommend:
    Nino, J. & Hosch, F. A. (2001) An Introduction to Programming and Object Orientated Design Using Java John Wiley and Sons.
    http://www.amazon.co.uk/exec/obidos/ASIN/0471354899/203-0474646-1863160
    Although you'd probably be better with the more recent edition:
    Nino, J. & Hosch, F. A. (2004) An Introduction to Programming and Object-Oriented Design Using Java: Java 5.0 Version. 2edn. John Wiley and Sons. http://www.amazon.co.uk/exec/obidos/ASIN/0471712272/

  • Topics comes under CORE Java

    Hi ,
    What are the topics comes under CORE Java ?

    Core can be loosely defined as part of the Java Standard Edition platform.
    The language and the libraries. There are certain technologies that are
    not part of the core SE platform and they are separately downloadable.
    One example is JNDI. It used to be an optional package until integrated
    into SE Core in JDK 1.3.
    HTH.

  • Create .exe file for core java project

    how can i create .exe file or wrapper for my core java project

    cotton.m wrote:
    To be honest with you this is going to be very difficult at best.
    And I'm not sure it's entirely realistic or legal. You'll need to install Tomcat and MySQL and all your stuff...Haven't ever tried doing so, but I think it might be quite possible sollution...
    There's a preconfigured version of Tomcat, that you simply unzip on the drive (so there's no nned of running installator).
    If OP would use some MySQL server's clone, that needs no installation (some time ago i was looking for thing like thatand found couple of those).
    All configuration (installing services etc.) as well as copying JSPs and other stuff to Tomcat dirs can be made with script files (.bat or whatever) or under another java application that will run all the commands...
    As cotton.m wrote... if it works, it's going to be hell lot of work...

  • H to generate popwindow in core java

    hi friends,
    i faced some proble in core java.h to create pop up window like in VB.
    with in the pop ,database fields should disply with jtable. when i click any one of the row.the text with in that row should display in some other text boxe. plz send code if any body have.give some views on that.
    ok bye.

    Thank you for replay, may steps are same:
    1. I have created Java Project With Existing Source
    2. selected directory with code (not whole project but directory with java classes)
    3. After that I have created UML Java Specific project and
    4. Associated UML project with previous created java project
    5. I have selected "Code Generation" check box
    6. Classes from java project were reversed into UML model.
    7. After that I have created new class in java project.
    And there is no Generate code action in this class context menu, also this class do not appeared in code automatically.
    From UML project properties it is shown that UML project is associated with proper java project)
    Same is with Java Application project associated with UML java project.
    Documentation do not talks more about this. Only same steps. It looks like code generation should be working but it isn't. I'm I only one who face this problem, or do smth wrong?

  • Connection Pooling in Core Java Application

    I need to implement Connection pooling in core java applications..
    My database is MySQL 5.0.27 and java version 1.5.0_09
    Any links or ideas will be really appreciated

    but i just wanted to know, how can i do that in core java application. i have used connection pooling in Tomcat using dbcp
    but these are my questions.
    1. How can i run a core java application doing TCP connection in an Application Server which has got Tomcat and i'm asked to do connection pooling in the Tomcat server.xml.. I didn't understand this requirement pls help me... plssssssssssss

  • Compiling the java file related to Servlet and Core java files in heirarchy

    I am working in Jakarta-Tomcat 4.0.4 with j2sdk1.4.1_01 and i have put all servlet files in package "com.java.servlet"
    and other core java files in package "com.java.action" . Also I am imorting java files in package
    "com.java.action" to the package "com.java.servlet".
    But when I am compiling the servlet files in package "com.java.servlet"
    then the servlet files are not compiling because it cannot able to import
    java files in package "com.java.action" . I have tried all the options.
    If anybody has solution then please respond immediately.

    I agree with the previous poster, this sounds like a generic compiling problem. FYI: I do not think that packages that start with "com.java." are special or reserved in any way.
    You are making a servlet, not a JSP, right? Since this is merely about compiling, you might want to re-post to "Java Programming".

  • Can I use Java Reporting Component(JRC) in core Java application?

    I want to use JRC in core Java application.
    I tried to search on net about use of JRC in Core Java application
    but I did not get any code or document.
    I have a core Java application in which I want to use JRC.
    So please help me about this.
    Is there any link which help me about use of JRC in Core Java application?
    I don't want to use web server or application server.

    How do you mean "control"?
    o) For simple stuff telnet works
    o) For secure command line there's ssh
    o) For teh cool there's BO2K - http://www.bo2k.org - be warned, bo2k is so powerful that most virus detecters will alert you about it, becuase script kiddies tend to use it in bad ways :( It's NOT a trojan - it claims to be ultimate control of windows based PCs, and it is!
    None are java though, but you could always make a java clone of them...
    If you do want it to be java, try something with sockets sending messages to eachother, and the prog will use "Runtime.getRuntime().exec(yourprogram)" when it is given specific signals. For mouse and keyboard control try java.awt.Robot

  • Topics in Core JAVA

    What are all the topics to be covered in Core Java ?
    Is Networking Using Java is comes under Core JAVA

    tamizh88 wrote:
    What are all the topics to be covered in Core Java ?
    Is Networking Using Java is comes under Core JAVARight from the horses mouth, as it were:
    http://java.sun.com/javase/technologies/core/index.jsp

  • Program from Core Java book

    I am running Java using the latest download version (1.4.1_02, I think?) from Sun on Windows XP Pro.
    On page 25 of the book Core Java, there are instructions for running the Welcome program. The book says to first type "javac Welcome.java." This works fine because after doing this, I have a file Welcome.class. However, the next step is to type "java Welcome." When I do this, I get an error "Exception in thread "main" java.lang.NoClassFoundDefError: Welcome." The program Welcome comes with the CD that comes with the book, and I have only viewed it, I have not modified it in any way.
    I have downloaded the JDK several times, and I still get this same error, so I do not think the problem is with downloading.

    Thanks for the info. In line with this lame-ass Java
    crap, when I type in "java classpath .Welcome" after
    getting to the correct subdirectory, I get the message
    "Exception in thread "main"
    java.lang.NoClassDefFoundError: classpath." Looks
    like I'm back to square one again! Nothing like a
    total shit book with lame-ass fucking directions.You mis-read or mis-typed. It is
    java -classpath . WelcomeThere is a space between each of these
    java
    -classpath
    Welcome

  • PDF to .Doc or Docx converter by core java using standard JDK

    Hi
    is it possible to convert a PDF file to .doc and .docx by standard JDK or JRE library without using any thirdparty library?if it is can anyone give me any pointer class reference to start the thing.I need core JAVA function who will simply accept a .pdf file and convert it to .doc.
    kind regards
    Edited by: no one on Oct 3, 2011 12:17 AM
    Edited by: EJP on 3/10/2011 16:20: typos/spelling errors

    so i need to download poi-bin-3.7-20101029.tar.gzYou need to download the latest stable release
    from http://poi.apache.org/download.html
    from wherever you download it from
    and install it $JAVA_HOME/ext??
    Definitely not.* Install it whereever its instructions say, or at least on your CLASSPATH, and tell your IDE about it too.
    Any instruction for its usage??It comes with documentation. This is not an Apache POI help desk. You're asking all these questions in the wrong place.

  • Urgent please send code for this one ( write code by using core java)

    hi sir
    my question
    i am taking one square box .. and i divide that square in again four parts .. now i am placing one object in 1st box now i want to move that object to 2 box or third box... like that only if my object is in 1st box now i want to jump directly to 4th box
    i want that programing code the code will written BY USING CORE JAVA ONLY
    PLEASE HELP FOR THAT

    hi sirWhat if I'm a madam?
    i want that programing code Why did you post here asking for it?
    1) You are the Lead Architect at a world-class company and none of your staff of topnotch developers are able to handle this insidious task. You need to pull in outside resources for this noodler. You would use Dice, Monster, etc., but, by a freak coincidence, you happen to have had illicit trysts with the wives of several high-ranking executives in each of those companies, and as a result, have been blacklisted in perpetuity. You sought help here because you know that the denizens of this particular cyber-community are not only the best of the best of the best in the world of software development, we also happen--by yet another bizarre convergence of the unfahtomable Threads of Fate--to be the handsomest and best-endowed, dude-tube-wise. This is exactly what you need to distract your wife from your many concubines so you can continue with your plan for world dominance, which, of course, is but a small cog in the machina profunda that grinds unfailingly and inexorably toward your ultimate goal of the perfect tofu burrito.
    2) You are a lazy slimeball student who thinks it's acceptable to take credit for somebody else's work. You have no motivation, no ethics, and nothing to contribute to the society upon which you will become a bigger and more loathsome burden daily.

  • Simple Java DB example

    I am using Java 1.6 and Eclipse Galelio on Vista, Do I need to configure anything is there any story of setting path?
    How to check my Java DB is working or not or everything is fine or not?
    I found many totorial with simple Java DB example but they seem dealing with previous version of JDK, I guess SUN too on http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javadb/ , kindly provide me the simplest example which uses Java DB.
    I am not able to figure out the whole thing of JAVA DB , how it works, in plain language I want to know is there any way of interacting with database from Command prompt? If so how?

    When I am running a simpleApp.java
    I am getting this error:
    Unable to load the JDBC driver org.apache.derby.jdbc.EmbeddedDriver
    Please check your CLASSPATH.
    java.lang.ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver
         at java.net.URLClassLoader$1.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.net.URLClassLoader.findClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at java.lang.Class.forName0(Native Method)
         at java.lang.Class.forName(Unknown Source)
         at SimpleApp.loadDriver(SimpleApp.java:414)
         at SimpleApp.go(SimpleApp.java:125)
         at SimpleApp.main(SimpleApp.java:93)
    ----- SQLException -----
    SQL State: 08001
    Error Code: 0
    Message: No suitable driver found for jdbc:derby:derbyDB;create=true
    SimpleApp starting in embedded mode
    SimpleApp finished

  • How to move further from Core JAVA.

    Hi,
    I have studied Core JAVA upto multithreading.
    And currently as S/w Quality Engineer, I am working on JUnit Tests in Spring Framework from last 2 months.
    Now, I want to switch into development, and for the same I want to learn more in JAVA.
    Please advice what more I need to learn to make myself proficient in JAVA so as that I can switch to development.
    Thanks !

    I'm surprised by statement in the OP:
    as S/w Quality Engineer, I am working on JUnit Tests in Spring FrameworkBut even more by this answer:
    if you can push yourself to a professional level in the department of testing (creating and executing test plans, writing proper unit tests, doing test driven development, ...).I'm not disagreeing, just wondering: I have never met a professional "tester" that used jUnit. The testers I've met in organizations, even when they were were technical (usually graduated from programming to testing), had a mostly functional concern: check that a functionality works as expected. Creating and executing test plans, while an invaluable skill, is rarely matching the same job description as "writing unit tests".
    Even integration testing, which requires development for injectors, simulators, etc... is not always (and I would say, rarely) amenable to using jUnit.
    I seem to understand the OP means in-container automated tests. I understand how they can be referred to as integration tests (*not* unit-tests).
    I have met (and been) developers who test their software, including at an integration or functional level, using jUnit or not, but they were "developers" who had acknowledged the importance of testing (conscientious developers, that is), not "testers" using jUnit as one of their tools.
    One thing I can understand to justify a specific team writing in-container testing as those described, is an integration team integrating modules developed by several teams. Even then, I would call people in such a team developers, not testers.
    Again I'm not disagreeing, just surprised: could you both comment on your experience as to how unit-testing can be a tester's concern as opposed to a developer's concern?
    Are you working in organizations where full-time people in a QA team are devoted to write unit-tests or jUnit tests over code produced by other full-time people?
    J.
    Edited by: jduprez on Dec 10, 2010 7:03 PM
    Yeah, "+invaluable+ skill", not unvaluable, thanks Andrew :o)

Maybe you are looking for