Using the java tutorials and im stuck!

Hey, soz to be a pain and post something probably rediculously easy! im trying to learn java going through the online tutorials, im at the end of the object orinetated programming chapter and am doing the followning task;
Exercises
Create new classes for each real-world object that you observed at the beginning of this trail. Refer to the Bicycle class if you forget the required syntax.
For each new class that you've created above, create an interface that defines its behavior, then require your class to implement it. Omit one or two methods and try compiling. What does the error look like?
here is the code i have done for task one so far, but it wont compile, please dont tell me the answers, can you tell me where i am going wrong and suggest ideas for improvments and then ill post my reply here and tell me if i am right? thank you
class Television
int poweron = 1;
int poweroff = 0;
int channel = 1;
void change poweron (int increment)
          poweron = poweron + increment;
void change poweroff (int increment)
          poweroff = poweroff + increment;
void change channel (int newValue)
          channel = newValue;
}

i have the two codes,
this one
class Television
int poweron = 1;
int poweroff = 0;
int channel = 1;
void changepoweron (int increment)
          poweron += increment;
void changepoweroff (int increment)
          poweroff += increment;
void changechannel (int newValue)
          channel = newValue;
void printStates()
        System.out.println("poweron"+poweron+" poweroff:"+poweroff+" channel:"+channel);
}and this one
class TelevisionChange
     public static void main (String[] args)
          Television newTV = new Television ();
          newTV.changepoweron(0);
          newTV.changepoweroff(1);
          newTV.changechannel(6);
          newTV.printStates();
}both are stored in the same folder on my computer, c:\user\documents\textpad stuff
when i compile them there is no eror in textoad but then when i goto run java application using the television class i get the following error;
exception in thread main java.lang.nosuchmethoderror: main press any key to continue, when i compiile and run the other code i get a massive error saying
Exception in thread "main" java.lang.NoClassDefFoundError: televisionchange (wro
ng name: TelevisionChange)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12
4)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
Press any key to continue . . .

Similar Messages

  • The Java Tutorials : Lesson Generics Question and Answers

    Hello,
    I've just finished reading the Generics Lesson from the Java Tutorials,
    http://java.sun.com/docs/books/tutorial/java/generics/index.html
    and was hoping to see the answers in the Question and Answer section at the end of the tutorial, but the link doesn't seem to be working.
    Could someone please grade my answers?
    The question is (copied from the Java Tutorials):
    1. Consider the following classes:
        public class AnimalHouse<E> {
            private E animal;
            public void setAnimal(E x) {
                animal = x;
            public E getAnimal() {
                return animal;
        public class Animal{
        public class Cat extends Animal {
        public class Dog extends Animal {
        }For the following code snippets, identify whether the code:
    * fails to compile,
    * compiles with a warning,
    * generates an error at runtime, or
    * none of the above (compiles and runs without problem.)
    a. AnimalHouse<Animal> house = new AnimalHouse<Cat>();
    b. AnimalHouse<Dog> house = new AnimalHouse<Animal>();
    c. AnimalHouse<?> house = new AnimalHouse<Cat>();
    house.setAnimal(new Cat());
    d. AnimalHouse house = new AnimalHouse();
    house.setAnimal(new Dog());
    My answers are:
    a. fails to compile
    b. fails to compile
    c. compiles and runs without problem
    d. compiles with a warning
    I realize that I could re-read the tutorial, but aside from learning about Generics, I'm also trying to gauge how well I absorb new information, the first time I read it, so I would appreciate if someone could tell me if my answers are correct. Explanations for incorrect answers would also be appreciated.
    Thanks

    Hi,
    as far as I understand it, and am able to explain, creating
    new AnimalHouse<Cat>();has the knowledge (at compiletime) about the generic type Cat.
    But as soon as this is assigned to
    AnimalHouse<?> house = new AnimalHouse<Cat>();the variable house, this knowledge is lost for the variable house. So you have house which does not know the underlying generic type used. Then, there are either two options:
    - allow adding anything via the set...-method
    - do not allow adding/setting anything at all
    In the first case, you would create the problem of being able to potentially add instances of types that do not have any relation to the originally used type Cat - which will cause problems (imagine setting a Car instance instead of a Cat instance and lateron expecting to retrieve something that should be a Cat but is a Car...).
    So, the only safe option is the second one.
    Weird to explain, but maybe there are better explanations around...
    Bye.

  • My LR 4 suddenly no longer recognized my memory cards. I am using the same cards and cameras but consisitently get the error message:"files not imported because the files could not be read. they are jpg and nef files...I am stuck without my workhorse! Any

    My LR 4 suddenly no longer recognized my memory cards. I am using the same cards and cameras but consisitently get the error message:"files not imported because the files could not be read. they are jpg and nef files...I am stuck without my workhorse! Any advice is helpful. This has never happened in 6 years

    answered in your other thread LR 4 suddenly no longer recognizes files.

  • Is it possible to use the JAVA Report Engine SDK to modify DESKI reports?

    Post Author: Nadine
    CA Forum: JAVA
    Hi, is it possible to add a complex filter to a DESKI report using the JAVA report engine sdk?
    In the developer tutorials for this API, I've only found references to WEBI in terms of modifying reports, though it seems to be possible to view DESKI reports with this sdk.
    I am a bit confused in terms of the scope of this API and how I would use it in regard to DESKI.
    Many thanks for any suggestions!
    Nadine

    Post Author: Ted Ueda
    CA Forum: JAVA
    Current (XI R2) version of ReportEngine API only supports refreshing/viewing functionality for Desktop Intelligence documents.  Document modification/creation is only supported with Web Intelligence documents.  Queries aren't modifiable for Deski using ReportEngine API - you can only do so using Desktop Intelligence Reporter SDK, which is COM based.Sincerely,Ted Ueda

  • Using the Java DOM properly

    I am new to the Java DOM (package org.w3c.dom) and have read several tutorials on its basic use, but cannot find the answers to what I feel are some very basic questions.
    In org.w3c.dom (the "Java DOM"), Documents, Elements and Nodes are interfaces all representing the components of an XML document, which is a tree structure where each node can have 0+ children (representing the recursive nature of XML itself). The Document interface represents the entire document, whereas Elements (which extend Nodes) represent a specific tag/element in an XML document, and all of its children (the subtree extending from the Element).
    QUESTION #1: What class, then, actually represents the tree data structure of the XML document? Document, Element and Node are interfaces, meaning they can only provide abstract methods and static members. For instance, Node has a method called "getFirstChild()"... since this is an interface method, it has to be abstract... so where is it defined? Another way to look at this question is:
    noises.xml
    ========
    <animals>
         <cow noise="moo"/>
         <dog noise="woof"/>
    </animals>
    DomTestDriver.java
    ==================
    DocumentBuilderFactory dbf = new DocumentBuilderFactory()
    DocumentBuilder db = dbf.newInstance();
    Document doc = db.parse("noises.xml");
    Element root = doc.getRoot();
    Element cow = root.getFirstChild();Here I have read/parsed noises.xml into a Document object. I am now free to explore the document, modifying it as I wish, etc. When I call root.getFirstChild(), somewhere, somehow, a tree structure is holding an in-memory version of noises.xml, and getFirstChild() queries that structure for the correct Node to return... what is this structure?!? It must be a class... so what is it???
    ***End of Question #1***
    Second, it would be nice if I could modify a Document object or Element at runtime. For instance:
         Element horse = new Element();
         horse.setTagName("horse");
         horse.setAttribute("noise", "naaay");
         root.replaceChild(horse, cow);
         // Now, the 'doc' Document object, which originally parsed noises.xml, looks like:
              <animals>
                   <horse noise="naaay"/>
                   <dog noise="woof"/>
              </animals>
         */Several problems with the code sample above:
    (1) Element is an interface! I can't instantiate it like "Element horse = new Element();"
    (2) Neither Element nor Node specify a "setTageName(String)" method, telling me that Java     does not want me using the Java DOM like this... why?!?!
    QUESTION #2: So, if my code sample above doesn't work, how do I create new Element objects and insert them into my Document object, or into another Element's subtree?

    the top hit for the google search "java dom tutorial" should answer questions 2 and 3. as for 1, the answer is "it doesn't matter". the point of frameworks designed like this is that each jdk implementation is free to provide its own, compatible dom implementation. in case you are curious, the sun jdk implementation uses a modified version of apache xerces, but like i said, that doesn't really matter and should not be visible to you.

  • I am using the MODBUS library and can't receive data, however I can send it just fine?

    Hi,
    I am using the Modbus Library to communicate with a VFD to control a fan. I am using the master write and read vi. I can write data to the VFD and get the fan to do what I want. The VFD is supposed to send a confirmation packet after I tell it to do something and I can also read its registers. When I debug the VI it shows the problem is the buffer always reads zero and the VI timesout. If I watch the lights of the USB to RS 485 adapter I am using to interface with the VFD, I see that the RX light flashs right after I send a message. So I should have something in the buffer. Does anyone have any suggestions?
    Aaron
    Solved!
    Go to Solution.

    Ok, heres what happened for anyone who has this problem. In the MB Serial Receive.vi The Bytes at Port property node was reading 0 even though there was something in the buffer. The program execution was then stuck in a loop till it timed out and never went on to read anything from the serial port buffer. I didn't spend too much time wondering why that VI didn't work and created my own. With an appropriate delay after writing to the serial port,  I used the same Bytes at Port property node and was able to get the right number of bytes to then feed the read VISA vi the number of bytes to read. I got the right response message and everything seemed good. But of course NOT! I then experimented with writing different speeds to the VFD to get the fan to run at different speeds. I found a small range of speeds where I would get no response from the VFD, either by it functioning or sending me a response packet. After quite some time, I found there is an error in the LRC-8 code in the MODBUS NI library. It does not mandate the LRC be a two character value. So if your LRC turns out to be a single character value such as F (which should be 0F)  you get an incomplete MODBUS message. This was easily fixed in the LRC8 vi by telling the 'number to hexidecimal string' vi to produce an output with a minimum width of two. Then everything worked great. Moral of the story is the MODBUS library is clunky.

  • How to Use the JAVA SCRIPT code in .htm page of the component

    Hi .
    In my requirement i have to use Java Script Function in .htm code ..how to use the java script code and functions in .htm???
    thank you
    B.Mani

    Check this document  [Arun's Blog|http://wiki.sdn.sap.com/wiki/display/CRM/CRMWebClientUI-TalkingwithJava+Script]
    Regards
    Kavindra

  • How do I create a user, in my context in OID using the Java API

    How do I create a user, with subschema, in my context in OID using the JAVA API
    I need to be able to create new users in my OID, I was doing it in our old iPlant Directory, but I don't seem to see the same methods in the Oracle LDAP API. I figured out how to get and modify the attributes of a user, but I can't seem to figure out how to add a new one.

    Try this code , modify it accordingly
    ------- cut here -------
    import oracle.ldap.util.*;
    import oracle.ldap.util.jndi.*;
    import javax.naming.NamingException;
    import javax.naming.directory.*;
    import java.io.*;
    import java.util.*;
    public class NewUser
    final static String ldapServerName = "yourLdapServer";
    final static String ldapServerPort = "4032";
    final static String rootdn = "cn=orcladmin";
    final static String rootpass = "welcome1";
    public static void main(String argv[]) throws NamingException
    // Create the connection to the ldap server
    InitialDirContext ctx = ConnectionUtil.getDefaultDirCtx(ldapServerName,
    ldapServerPort,
    rootdn,
    rootpass);
    // Create the subscriber object using the default subscriber
    Subscriber mysub = null;
    String [] mystr = null;
    try {
    RootOracleContext roc = new RootOracleContext(ctx);
    mysub = roc.getSubscriber(ctx, Util.IDTYPE_DN, "o=dec", mystr);
    catch (UtilException e) {
    e.printStackTrace();
    // Create ModPropertySet with user information
    ModPropertySet mps = new ModPropertySet();
    mps.addProperty(LDIF.ATTRIBUTE_CHANGE_TYPE_ADD,"cn", "Steve.Harvey");
    mps.addProperty(LDIF.ATTRIBUTE_CHANGE_TYPE_ADD,"sn", "Harvey");
    mps.addProperty(LDIF.ATTRIBUTE_CHANGE_TYPE_ADD,"uid", "SHarvey");
    mps.addProperty(LDIF.ATTRIBUTE_CHANGE_TYPE_ADD,"givenname", "Steve");
    mps.addProperty(LDIF.ATTRIBUTE_CHANGE_TYPE_ADD,"mail", "[email protected]");
    mps.addProperty(LDIF.ATTRIBUTE_CHANGE_TYPE_ADD,"userpassword", "welcome1");
    // Create the user
    User newUser = null;
    try {
    newUser = mysub.createUser(ctx, mps, true);
    System.out.println("New User DN: " + newUser.getDN(ctx));
    catch (UtilException e) {
    e.printStacktrace();
    ------- end cut --------
    Enjoy.
    Suhail

  • Should i use the Java edition ?

    Hi,
    i'm not sure if i should use the Java edition or the "normal" edition of the berkeley db.
    My application is developed in Java, but i won't be using either JTA, JCA or JMX.
    Is there still any advantage to be taken from using the Java edition ?
    Thanks

    There are many minor differences, e.g., JE has somewhat better write performance, DB uses somewhat less memory, DB has an SQL interface and JE does not. But overall, the two products are very similar, so for most questions you might ask, the answer is going to be "about the same".
    If you want to choose the best product for your app, you'll have to define the very specific criteria that are most important to you. If you care most about getting every ounce of performance out of a specific piece of hardware, using a specific amount of memory, for a specific app (access pattern), then you'll have to write a test and do a comparison.
    --mark                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Why to use the Java API in MDM

    Hi Experts,
    I am new to the MDM.
    We are having the requirement of inetration between Portal and MDM.Can u please tell me when to use the following coponents like the scenorio's.
    Why to install the MDM Business packages in Portal?
    why to use the JAVA API.
    Please give me the complete information.
    Regards

    Hi Vijay,
    Standard Business Package is use to provide interaction between MDM Server and the Portal. It consists of MDM iViews like Item Detail iView (allows to create,edit and delete the records) , Resultset iView (Displays the records, allows to add the records in workflows etc), Search iViews (for searching)i.e. Data Manager functionality.
    Java API are used when you need some functionality that standard MDM iViews dont have.MDM Java API consists of set of classes and interfaces with the help of which customization can be done.
    Regards,
    Jitesh Talreja

  • It is possible to download the java tutorials?

    Hi all,
    there is a place where I can download the java tutorials? I need them for a computer without connection to internet. I'm interested in all the tutorials, but the Thread and Swing tutorials are the ones that I need now.
    TIA.
    Jorge.

    At least the swing tutorial is there.
    Thanks you.You're welcome. Good luck, and happy coding!

  • How to use the Java embedding activity in BPel

    hi all,
    How to use the java embedding activity in BPEL
    pls can u provide sample example

    1 Use [Oracle BPEL Process Manager Client Java API Reference|http://download-uk.oracle.com/docs/cd/B31017_01/integrate.1013/b28986/overview-summary.html] and especially [com.collaxa.cube.engine.ext|http://download-uk.oracle.com/docs/cd/B31017_01/integrate.1013/b28986/com/collaxa/cube/engine/ext/BaseBPELXExecLet.html]
    Instead of System.Out.println use addAuditTrailEntry(java.lang.String message)
    2. If you want to import a package write in code (Source View) of bpel process
    +<bpelx:exec import="package_name"/>+ for example +<bpelx:exec import="java.util.regex.Matcher"/>+
    example 1:
    String bodyAsString;
    StringBuffer myStringBuffer = new StringBuffer();
    try {
    bodyAsString = (String)getVariableData("BodyString");
    addAuditTrailEntry("bodyAsString1: "+ bodyAsString);
    Pattern pattern = Pattern.compile("goodDay");
    Matcher matcher= pattern.matcher(bodyAsString);
    while (matcher.find()) {   
    matcher.appendReplacement(myStringBuffer, "shitDay");
    matcher.appendTail(myStringBuffer);
    bodyAsString = myStringBuffer.toString();
    addAuditTrailEntry("bodyAsString2: "+ bodyAsString);
    } catch (Exception ex) {
    addAuditTrailEntry("Failed+bodyAsString",ex.getMessage());
    I put in code (Source View) the following
    <bpelx:exec import="java.util.regex.Matcher"/>
    <bpelx:exec import="java.util.regex.Pattern"/>
    example2:
    Object temp;
    try {
    temp = ((XMLElement)getVariableData("inputVariable","payload","/ns2:FiscalisMessage/ns2:Body")).getChildNodes().item(1);
    setVariableData("AdjReceipt",temp);
    addAuditTrailEntry("ok",temp.toString());
    catch (Exception ex) {
    addAuditTrailEntry("Failed :",ex);
    I put in code (Source View) the following
    <bpelx:exec import="oracle.xml.parser.v2.XMLElement"/>

  • Using the JAVA ImportXmlTemplate function, should I always use XSL directory?

    Using the JAVA ImportXmlTemplate function requires XSL directory, I do not need XSL for my updates, how can I workaround this requirement?

    Ok, thanks for your quick answer. I saw you last blog posting regarding simple bar codes, I hope your next one turns up soon (read: today ;-) ).
    I did take a swing at writing my own class according to the user guide, using JDeveloper. One of my problems is that I am not that familiar with the whole java world, my experience lies almost entirely within .NET development. So when I read stuff like "make sure the class is available in the classpath for the JVM" and things like that, it is not a detailed enough description for me in order to make anything out of it. Do you think you can clarify that for me?
    I also wonder if you have any tips and tricks on how to trace/log information from the class when it executes? Because I think that I can actually get it to be called, it's just that something goes wrong and the generated PDF becomes badly formatted and has no content. I can see that some calls are made to a Logger class inside the example class. I guess that I need to set up some runtime configuration for that information to turn up in a file, but again me lacking experience from the java world prevents me from accomplishing that :-)
    Regarding tracing and logging from the java classes for the BI Publisher, can I get them to trace or log debug information in some clever way?
    The app I am developing is a .NET app that calls these classes using a product called juggerNET. I am developing a print direct application for JDEdwards EnterpriseOne since BI Publisher is not entirely integrated into it yet.
    I would greatly appreciate a quick reply this time as well if you can find the time!
    Best regards, Jörgen

  • Handle a pdf using using the Java-based programming

    Could I handle a PDF document created by LiveCycle using the Java-based programming?
    I want to say, don't use the LiveCycle server-based application.
    I'm developing a small desktop application. This application read from the database and populate a PDF document. The PDF document has many forms and they use a button to increment the field in the subform or duplicate the subform.

    Could I handle a PDF document created by LiveCycle using the Java-based programming?
    I want to say, don't use the LiveCycle server-based application.
    I'm developing a small desktop application. This application read from the database and populate a PDF document. The PDF document has many forms and they use a button to increment the field in the subform or duplicate the subform.

  • Using the Java API

    Hi everyone,
    I just wanted to see if anyone knows whether I need a license to use the Java API included in the trial version of Adobe LiveCycle ES.
    I need to include some PDF manipulation code for dynamic XFA forms in an application, and I first read that XPAAJ jar was free. So is the API here also free or do I need a license? If anyone knows, could you please point me in the direction of the details if a license is needed.
    I would appreciate your help.
    Thanks.
    Mira.

    Mira
    You don't need a license as long as the application you're building is for evaluation or testing, and NOT for production use.
    You will need to purchase a license for production use.
    Licensing can be complex, and you should contact your local Adobe office or enterprise partner for details.
    XPAAJ was never free, it was bundled with other Adobe products.
    It has been deprecated, and is no longer supplied or supported, as far as I'm aware. You will need to purchase a LiveCycle license of some sort.
    Howard
    http://www.avoka.com

Maybe you are looking for