How to write javascript in java class method

Hi,
any one please resolved this,
i want to write javascript window closing code into java class method, in that method i want to write javascript code & wanted to call in jsf page on commandButton action event,
my code is below but it is not working properly
public void closeWindowClicked(ActionEvent event) {
          try
     FacesContext facesContext = FacesContext.getCurrentInstance();
     String javaScriptText = "window.close();";
     // Add the Javascript to the rendered page's header for immediate execution
     AddResource addResource = AddResourceFactory.getInstance(facesContext);
     addResource.addInlineScriptAtPosition(facesContext, AddResource.HEADER_BEGIN, javaScriptText);
catch(Exception e)
     System.out.println(""+e);
for calling into jsf code is below
<h:commandButton action="#{parentBean.closeWindowClicked}" value="OK" />
/*Note- i want to closed the window by caling method contain javascript only, i don't want any ajax code in method */
please any one can resolved this.
Thanks

/*Note- i want to closed the window by caling method contain javascript only, i
don't want any ajax code in method */ When the user presses your button, do your business logic and then send them to a page containing the following (note: untested code ahead):
<html>
<head>
    function onLoadHandler()
        window.close();
</head>
<body onload="onLoadHandler();">
    <p>Window closing....</p>
</body>
</html>

Similar Messages

  • How do you call a java class from the main method in another class?

    Hi all,
    How do you call a java class from the main() method in another class? Assuming the two class are in the same package.
    Thanks
    SI
    Edited by: okun on May 16, 2010 8:40 PM
    Edited by: okun on May 16, 2010 8:41 PM
    Edited by: okun on May 16, 2010 8:47 PM

    georgemc wrote:
    To answer your impending question, either the method you're calling has to be static, or you need an instance of that other class to invoke it against. Prefer the latterAnd to your impending question after that: no, don't use the Singleton pattern.

  • How to Use JavaScript in Controller Class...

    Hi All,
    Can any one tell me how to use JavaScript in Controller Class.
    Requirement is:
    I have
    Radio Group(RG1),
    Two Radio Buttons(RB1,RB2),
    Two messageTextInput(MTI1,MTI2),
    if i click RB1 i should Prompt to the end user to "Enter value for MTI1" or
    If i click RB2 i should prompt "Enter value for MTI2" while submitting page.
    Please let me know the steps to use JavaScript and the above client validation...
    Regards
    Alem...

    Using javascript is against the standard. I can tell you a workaround instead of you setting the javascript, check if that would be acceptable.
    You can use PPR and set the required property on the messageTextInput on clicking of the radio button. By doing this you will let UIX generate the javascript for you to handle the client side validation. But the validation will happen only on click of the submit button. The visual indicator is good enough to tell that the value has to be entered to the item.

  • Setting Control-Flow- Case on java class/method

    hello All :D
    i have little problem about control flow case, in my case i've 2 page where before load to the page i'wanna make condition (if-else)
    when the user choose the field, the java class get the value for make true condition. In this case, i wanna implement ControlFlowCase in java class/method, so anyone help..?
    thx
    agungdmt

    Have you considered using router activity - http://download.oracle.com/docs/cd/E17904_01/web.1111/b31974/taskflows_activities.htm#CJHFFGAF ?

  • How to write comments for a class

    hi
    how to write comments for a class

    I'm reeling with incredulity, and as such am unable to do anything except just post some code
    // this is a single line comment
    /* this is a multiline comment.
        it can be spread over as many lines as you
        want */Or are you asking about how to decide what the content should be?

  • Essential PL/SQL , Java Classes/Methods for working on BLOB

    &#61623; Are there any methods/procedures with which we could work on a BLOB object which contains purely text?
    &#61623; Essential PL/SQL , Java Classes/Methods for working on BLOB:
    null

    &#61623; Are there any methods/procedures with which we could work on a BLOB object which contains purely text?
    &#61623; Essential PL/SQL , Java Classes/Methods for working on BLOB:
    null

  • Invoking remote java classes/methods

    Hi,
    I just wanted to ask for opinions and suggestions regarding my attempt to call a remote java class method using PL/SQL. I didn't want to load it in the database since the configurations for the java class were already set using Spring Integration. I just wanted to supply constructor arguments and run the method and then retrieve the result. Are there any good or easier ways on doing this?
    Thanks in advance

    Very curious Susan,
    A server JVM might not want to host mobile code from other clients, not that it's unsafe, it's just that it allows clients to crash the server JVM at will. They should have it configured to automatically restart though.
    Did they delete the java.rmi.* packages from the server JVM runtime? I don't understand why they'd do that.
    If you can pry some reasons from them, I'd be very interested to hear them. Perhaps they just want more money, in order to allow you this privilige.
    John
    PS I've updated representation for you, and ejp, on the cajo project supporting The Land Down Under!

  • How to pass value from Javascript function to a Java class method

    Hi All,
    I want to pass a value, which I catch in a Javascript function to a method in a Java class. I have tried many combinations but it gives me error.
    This is the way I am doing
    function assignBill() {
    proj = projPh.substring(0,indSlash);
    <% myproject.getProj(" project_cd = '" + proj + "'");%>
    proj is the variable which I want to pass to getProj methods.
    If any one has done this, please let me know. Thanks for your help.
    Ritesh Mehta

    The only way to receive something from clients page is to submit it somehow: through a form or link, but the info has to make it back to the server obviously. I dont know how your app works, but you can use the the javascript -location.href- function(i think) to submit the var to the server and process it there.

  • How can I call a java class from within my program?

    I was wondering if there's a platform independent way to call a java class from my program.

    Here's my scenario. I'm working on a platform independent, feature rich, object-oriented command prompt program. The way I'm designing it is that users can drop classes they write into my bin directory and gain access to the class through my program. For example, they drop a class named Network.class in the bin directory. They would type Network network at my command prompt and gain access to all the methods available in that class. They can then type system.echo network.ipaddress() at my prompt and get the system's ip address. I have it designed that there's a server running in the background and the clients connect to my port. Once connected the end-user can enter their user name and password and gain access to the system. When they type a command they actually call another java program which connects to my server using a seperate thread. They can then communicate back and forth. I have it set that everything has a process id and it's used to keep track of who called what program. Once the program is done it disconnects and closes. Rather than getting into the nitty gritty (I didn't want to get into heavy detail, I know how everything will work) I'm really interested in finding out how I can call a java program from my program. I don't want it to be part of the app in any way.

  • How do you invoke custom java classes???

    Could someone post a detailed method of invoking custom java classes that works including what files go where, settings and the way it is invoked etc.
    I have tried various ways from this forum and in the documentation without success. I am using IDM 8. I found these instructions regarding how you would do it if you were writing custom resource adaptors in the deployment tools guide:
    To install a resource adapter you’ve customized:
    1. Load the NewResourceAdapter.class file in the Identity Manager installation
    directory under
    idm/WEB-INF/classes/com/waveset/adapter/sample
    (You might have to create this directory.)
    2. Copy the .gif file to idm/applet/images.
    This .gif file is the image that displays next to the resource name on the List
    Resources page, and it should contain an image for your resource that is
    18x18 pixels and 72 DPI in size.
    3. Add the class to the resource.adapter property in
    config/waveset.properties.
    4. Stop and restart the application server. (For information about working with
    application servers, see Identity Manager Installation.)
    I tried the instructions here but placed my custom class in a folder entitled custom instead of /adapter/sample. Not sure about instruction 3 or whether it is relevent. Anyway nothings working.
    Edited by: masj78 on Nov 25, 2008 3:50 AM
    Edited by: masj78 on Nov 25, 2008 4:03 AM

    Hi,
    The way to add custom class is the same as you followed , put them in the WEB-INF/classes.
    To use the custom adapter ,
    Go To Resources - > Configure Types -> Add Custom Resource .
    Type in the fully qualified class name of the custom adapter you added.and Save.
    Now the new adapter you added should showup in the list of available adapters when you try to
    configure a new adapter.
    (Make sure that the prototype XML of your custom adapter is correct so that it displays the correct name / type for the adapter in the adapter list.
    Thanks,
    Balu

  • How can I execute a java class with arguments from an air application built from mxml?

    I have an mxml application. It has a button, and when that button select event occurs, I want my mxml air app to pass arguments to a java class I have built, which resides in a package path on my system. I need to be able to pass several arguments to my java method from my mxml call. How do I do this, and what config files are necessary? For the simple task I want to engineer, can you show me an example of a properly configured config file? My java class has been executed at the command line in the past as follows:
    java -cp %CP% com.abc.prism.queue.EmitMessage XYZ "my message text" 192.12.13.14 5672
    where %CP% is an env variable that tells my class the classpath it runs with, and XYZ, "my message text", the IP address, and the port are the arguments I must pass from mxml to my java class. How do I accomplish this?
    How do I make known to the java class I call from mxml the %CP% class path? It tells my java class where to find various rabbitMQ jars.

    Hi,
    You need to use Integration technology like BlazeDS or LCDS.

  • How can i mention a java class in the form's action=" ...."  in jsp

    if i am not using struts frame work, how can i call?
    i am not using any of the frame work.
    for example.
    i am searching for a customer name from a database
    i have coded the form fields in jsp
    as
    <%@page session="true"%>
    <%@page errorPage="ErrorPage.jsp"%>
    <%@page import="com.krysl.model.*"%>
    <jsp:useBean id="model" scope="session" class="com.krysl.model.webmodel"/>
    <html>
    <head>
    <title>Customer Seach</title>
    <jsp:include page="SetBaseURL.jsp" flush="false"/>
    <link rel="stylesheet" href="http://forums.sureshkumar.net/style.css">
    </head>
    <body>
    <jsp:include page="Banner.jsp" flush="false"/>
    <h1>Customer Search</h1
    <form method="POST" action=".......................">
    <b>Customer Name</b>
    <input type="TEXT" name="customerSearchArgument" size="20">
    <input type="submit" value="search">
    </form>
    </body>
    </html>
    this "customerSearchArgument" will receive a class method
    package com.krysl.controller;
    import java.io.*;
    import java.sql.SQLException;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import com.krysl.model.*;
    * @author dsdc
    public class customersearchaction extends Action
    public void run() throws ServletException, IOException
    String arg = request.getParameter("customerSearchArgument");
    if(arg != null)
    arg = arg.trim();
    if(!arg.equals(""))
    try
    model.customerSearch(arg);
    catch(SQLException e)
    throw new ServletException(e.getMessage());
    final String next = "/CustomersList.jsp";
    RequestDispatcher rd = application.getRequestDispatcher(next);
    if(rd == null)
    throw new ServletException("Could not find" + next);
    rd.forward(request, response);
    All other database connections and related things i coded in
    some other classes webmodel, model, controller servlets etc....
    in the above class the model.customerseach(arg);
    will do all the searching.
    my doubt is how to call this method in that action="" of jsp
    i tried as action="com.krysl.model.customersearch"
    action="com/krysl/model/customersearch"
    its not working
    please letme kno
    urget
    thank you

    Hi.
    go to otn.oracle.com/products/forms and get infromation about PJC and JavaBeans in Forms. The keyfilter example is available as sample as well. However, the link temporarily doesn't work
    All Forms demos and code sources: http://download.oracle.com/otndocs/demos/Forms_Demos_10gr2.zip
    Frank

  • Javascript calling Java class

    Hello, kindly help. I am calling a java class file for validating a username and password. The browser returns no error but it seems that execution does not even pass my class file.
    Here is my class file.
    import java.sql.*;
    import java.applet.Applet;
    public class auth extends Applet {
    boolean isAuth = false;
    String h;
    public void init() {
    h = "hello"; }
    public void login(String user, String pwd) {
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection("jdbc:odbc:test");
    Statement stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery("select * from users where username ='" + user + "'");
    if (rs.next()) {
    pswd=rs.getString(2).trim();
         if (pswd.equals(pwd)) {
    this.isAuth = true;
    rs.close();
    con.close();
    } catch (Exception ex) {
    System.out.println(ex);
    Here is aportion of my HTML file.
    <script language="JavaScript">
    <!--
    function auth_user(u, p) {
         document.auth.login(u, p);
         alert (document.auth.h); // property is undefined
         if (document.auth.isAuth) // property is undefined
              alert("User authenticated!");
         } else {
              alert("User not authenticated!");
    //-->
    </script>
    <applet code="auth.class" name="auth" width="1" height="1" id="auth"></applet>
         <form action="" method="post" name="login" id="login">
    <input name="uname" type="text" id="uname2" maxlength="10">
    <input name="upwd" type="password" id="upwd2" maxlength="10">
              <INPUT TYPE="button" VALUE="Login" onClick="auth_user(document.login.uname.value, document.login.upwd.value)">
    Many thanks,

    is it running when you making that call? i.e. i hope
    you have a lot more in the body of your applet than
    just a string assignment. The applet successfully initialized upon loading. However, even the "auth.h" property which is in the init() and is a simple assignment is undefined when I try to display it.

  • Accessing a java class method from the jsp page.

    Hi im a beginner with jsp and im trying to find a way to access a method of my java class file in jsp page. After searching through the forums i tried to use the usebean tag. Im using apache to host the jsp file.Below is an excerpt of my code and the error message i got. What am i doing wrong? anyone know?
    <%@ page language="java" %>
    <jsp:useBean id="movies" class="movie.Movie" />
    <jsp:setProperty name="movies" property="*"/>
    <%
    movies.getStart("file:///C:/Video/Applications2/sun.mpg");
    response.setContentType("text/xml");
    %>
    exception
    org.apache.jasper.JasperException: Exception in JSP: /View.jsp:7
    4: <jsp:setProperty name="movies" property="*"/>
    5: <%
    6:
    7: movies.getStart("file:///C:/Video/Applications2/sun.mpg");
    8: response.setContentType("text/xml");
    9: %>
    Stacktrace:
         org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:504)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    root cause
    javax.servlet.ServletException: javax/media/ControllerListener

    Hi thanks for responding. Ok i did look through and it was opening some gui. I still need the program to do server side processes so cant use an applet.but i dont need the gui so i revised it and removed the gui. also im using a servlet to call the class now yet i still have the same error. Any ideas?
    Below is the vid2jpg code minus the gui.
    import java.io.*;
    import java.awt.*;
    import javax.media.*;
    import javax.media.control.*;
    import javax.media.format.*;
    import javax.media.protocol.*;
    import java.awt.image.*;
    import javax.imageio.*;
    public class vid2jpg implements ControllerListener
         Processor p;
         Object waitObj = new Object();
         boolean stateOK = true;
         DataSourceHandler handler;
    int imgWidth;int imgHeight;
         Image outputImage;
         String sep = System.getProperty("file.separator");
         int[] outvid;
         int startFr = 1;int endFr = 1000;int countFr = 0;
         boolean sunjava=true;
         * Static main method
         public static void main(String[] args)
              if(args.length == 0)
                   System.out.println("No media address.");
                   new vid2jpg("file:///C:/Video/applications2/sun.mpg");     // or alternative "vfw://0" if webcam
              else
                   String path = args[0].trim();
                   System.out.println(path);
                   new vid2jpg(path);
         * Constructor
         public vid2jpg(String path)
              MediaLocator ml;String args = path;
              if((ml = new MediaLocator(args)) == null)
                   System.out.println("Cannot build media locator from: " + args);
              if(!open(ml))
                   System.out.println("Failed to open media source");
         * Given a MediaLocator, create a processor and start
         private boolean open(MediaLocator ml)
              System.out.println("Create processor for: " + ml);
              try
                   p = Manager.createProcessor(ml);
              catch (Exception e)
                   System.out.println("Failed to create a processor from the given media source: " + e);
                   return false;
              p.addControllerListener(this);
              // Put the Processor into configured state.
              p.configure();
              if(!waitForState(p.Configured))
                   System.out.println("Failed to configure the processor.");
                   return false;
              // Get the raw output from the Processor.
              p.setContentDescriptor(new ContentDescriptor(ContentDescriptor.RAW));
              TrackControl tc[] = p.getTrackControls();
              if(tc == null)
                   System.out.println("Failed to obtain track controls from the processor.");
                   return false;
              TrackControl videoTrack = null;
              for(int i = 0; i < tc.length; i++)
                   if(tc.getFormat() instanceof VideoFormat)
                        tc[i].setFormat(new RGBFormat(null, -1, Format.byteArray, -1.0F, 24, 3, 2, 1));
                        videoTrack = tc[i];
                   else
                   tc[i].setEnabled(false);
              if(videoTrack == null)
                   System.out.println("The input media does not contain a video track.");
                   return false;
              System.out.println("Video format: " + videoTrack.getFormat());
              p.realize();
              if(!waitForState(p.Realized))
                   System.out.println("Failed to realize the processor.");
                   return false;
              // Get the output DataSource from the processor and set it to the DataSourceHandler.
              DataSource ods = p.getDataOutput();
              handler = new DataSourceHandler();
              try
                   handler.setSource(ods);     // also determines image size
              catch(IncompatibleSourceException e)
                   System.out.println("Cannot handle the output DataSource from the processor: " + ods);
                   return false;
         //     setLayout(new FlowLayout(FlowLayout.LEFT));
    //          currPanel = new imgPanel(new Dimension(imgWidth,imgHeight));
         //     add(currPanel);
         //     pack();
              //setLocation(100,100);
         //     setVisible(true);
              handler.start();
              // Prefetch the processor.
              p.prefetch();
              if(!waitForState(p.Prefetched))
                   System.out.println("Failed to prefetch the processor.");
                   return false;
              // Start the processor
              //p.setStopTime(new Time(20.00));
              p.start();
              return true;
         * Sets image size
         private void imageProfile(VideoFormat vidFormat)
              System.out.println("Push Format "+vidFormat);
              Dimension d = (vidFormat).getSize();
              System.out.println("Video frame size: "+ d.width+"x"+d.height);
              imgWidth=d.width;
              imgHeight=d.height;
         * Called on each new frame buffer
         int nextframetime = 0;
    private void useFrameData(Buffer inBuffer)
    try
    if(inBuffer.getData()!=null) // vfw://0 can deliver nulls
    if(sunjava) // and with import javax.imageio.*;
    int frametimesecs = (int)(inBuffer.getTimeStamp()/1000000000);
    if(frametimesecs%10 == 0 && frametimesecs==nextframetime)
    nextframetime+=10;
    BufferedImage bi = new BufferedImage(outputImage.getWidth(null), outputImage.getHeight(null), BufferedImage.TYPE_INT_RGB);
    Graphics g = bi.getGraphics();
    ImageIO.write(bi, "png", new File("images"+sep+"image_"+(inBuffer.getTimeStamp()/1000000000)+".png"));
    catch(Exception e){}
         * Tidy on finish
         public void tidyClose()
              handler.close();
              p.close();
         * Block until the processor has transitioned to the given state
         private boolean waitForState(int state)
              synchronized(waitObj)
                   try
                        while(p.getState() < state && stateOK)
                        waitObj.wait();
                   catch (Exception e)
              return stateOK;
         * Controller Listener.
         public void controllerUpdate(ControllerEvent evt)
              if(evt instanceof ConfigureCompleteEvent ||     evt instanceof RealizeCompleteEvent || evt instanceof PrefetchCompleteEvent)
                   synchronized(waitObj)
                        stateOK = true;
                        waitObj.notifyAll();
              else
              if(evt instanceof ResourceUnavailableEvent)
                   synchronized(waitObj)
                        stateOK = false;
                        waitObj.notifyAll();
              else
              if(evt instanceof EndOfMediaEvent || evt instanceof StopAtTimeEvent)
                   tidyClose();
         * Inner classes
         * A DataSourceHandler class to read from a DataSource and displays
         * information of each frame of data received.
         class DataSourceHandler implements BufferTransferHandler
              DataSource source;
              PullBufferStream pullStrms[] = null;
              PushBufferStream pushStrms[] = null;
              Buffer readBuffer;
              * Sets the media source this MediaHandler should use to obtain content.
              private void setSource(DataSource source) throws IncompatibleSourceException
                   // Different types of DataSources need to handled differently.
                   if(source instanceof PushBufferDataSource)
                        pushStrms = ((PushBufferDataSource) source).getStreams();
                        // Set the transfer handler to receive pushed data from the push DataSource.
                        pushStrms[0].setTransferHandler(this);
                        // Set image size
                        imageProfile((VideoFormat)pushStrms[0].getFormat());
                   else
                   if(source instanceof PullBufferDataSource)
                        System.out.println("PullBufferDataSource!");
                        // This handler only handles push buffer datasource.
                        throw new IncompatibleSourceException();
                   this.source = source;
                   readBuffer = new Buffer();
              * This will get called when there's data pushed from the PushBufferDataSource.
              public void transferData(PushBufferStream stream)
                   try
                        stream.read(readBuffer);
                   catch(Exception e)
                        System.out.println(e);
                        return;
                   // Just in case contents of data object changed by some other thread
                   Buffer inBuffer = (Buffer)(readBuffer.clone());
                   // Check for end of stream
                   if(readBuffer.isEOM())
                        System.out.println("End of stream");
                        return;
                   // Do useful stuff or wait
                   useFrameData(inBuffer);
              public void start()
                   try{source.start();}catch(Exception e){System.out.println(e);}
              public void stop()
                   try{source.stop();}catch(Exception e){System.out.println(e);}
              public void close(){stop();}
              public Object[] getControls()
                   return new Object[0];
              public Object getControl(String name)
                   return null;
    below is the servlet code.
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    public class ShowMovie extends HttpServlet {
    String rootURL="http://127.0.0.1:8080/Video/";
    public void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
         //String movie=request.getParameter("movie");
         String movie ="son";
         getStart(movie);
              response.sendRedirect(rootURL+"View.jsp");
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    processRequest(request, response);
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    processRequest(request, response);
         public void getStart(String url){
              new vid2jpg(url);
    this is the error from the server. Im using tomkat 5
    exception
    javax.servlet.ServletException: Servlet execution threw an exception
    root cause
    java.lang.NoClassDefFoundError: javax/media/ControllerListener
         java.lang.ClassLoader.defineClass1(Native Method)
         java.lang.ClassLoader.defineClass(Unknown Source)
         java.security.SecureClassLoader.defineClass(Unknown Source)
         org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1812)
         org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:866)
         org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1319)
         org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1198)
         java.lang.ClassLoader.loadClassInternal(Unknown Source)
         ShowMovie.getStart(ShowMovie.java:31)
         ShowMovie.processRequest(ShowMovie.java:14)
         ShowMovie.doGet(ShowMovie.java:22)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    note The full stack trace of the root cause is available in the Apache Tomcat/5.5.17 logs.

  • (I can't compile it .I don't know how to write constructor in Initial Class

    All class and main program is OK except the inital class.
    Author Class
    class Author {
    private String authorName;
    private Initials inits;
    private int numTitles = 0;
    // PRE True POST Prompts user for details
    // and RETURNS new Author constructed from details
    public Author(BufferedReader in) {
    System.out.print("\nSurname ==> ");
    authorName = Text.ReadString(in);
    inits = new Initials(in);
    numTitles = 0;
    // PRE TRUE
    // POST RETURNS String representation of Author
    public String toString() {
    String result;
    result = "NAME : " + authorName + " " + inits.toString() + "\n";
    result = result + "Number of titles is " + numTitles;
    return(result);
    // PRE TRUE
    // POST Increments number of titles
    public void incTitles() {
    numTitles++;
    Book Class
    public class Book {
    private String title;
    private Author author;
    // PRE TRUE // POST Prompts user for details
    // and RETURNS new Author constructed from details
    public Book(Author author, BufferedReader in) {
    System.out.print("\nTitle ==> ");
    title = Text.ReadString(in);
    this.author = author;
    author.incTitles();
    // PRE TRUE
    // POST RETURNS String representation of Book
    public String toString() {
    String result;
    result = "TITLE : " + title + "\n";
    result = result + "AUTHOR\n" + author.toString() + "\n";
    return(result);
    *****Initial Class (I can't compile it . I don't know how to write constructor
    class Initials
    {   private char[] inits;
         public Initials(BufferedReader in)
         System.out.print("\nInitails Testing ==> ");
         inits = Text.ReadString(in);
         public String toString()
              String result;
              result="Testing";
              return(result);
    Main program
    public class BookMain {
    static private BufferedReader in = new BufferedReader(new                                    InputStreamReader(System.in));
    public static void main(String[] args) {
    Author authorRec1, authorRec2;
    Book bookRec1, bookRec2;
    System.out.println("\n\n****** First author input");
    authorRec1 = new Author(in);
    System.out.println("\n\n****** First author output\n" + authorRec1.toString());
    System.out.println("\n\n****** Second author input");
    authorRec2 = new Author(in);
    System.out.println("\n\n****** Second author output\n" + authorRec2.toString());
         System.out.println("\n\n****** First book input");
    bookRec1 = new Book(authorRec2, in);
    System.out.println("\n\n****** First book output\n" + bookRec1.toString());
    System.out.println("\n\n****** Second book input");
    bookRec2 = new Book(authorRec2, in);
    System.out.println("\n\n****** Second book output\n" + bookRec2.toString());
    System.out.println("\n\n****** First book output\n" + bookRec1.toString());

    Change this
    class Initials {
    private char[] inits;
    to this
    class Initials {
    private String inits;
    import java.io.*;
    public class BookTest {
      static private BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
      public static void main(String[] args) {
        Author authorRec1, authorRec2;
        Book bookRec1, bookRec2;
        System.out.println("\n\n****** First author input");
        authorRec1 = new Author(in);
        System.out.println("\n\n****** First author output\n" + authorRec1.toString());
        System.out.println("\n\n****** Second author input");
        authorRec2 = new Author(in);
        System.out.println("\n\n****** Second author output\n" + authorRec2.toString());
        System.out.println("\n\n****** First book input");
        bookRec1 = new Book(authorRec2, in);
        System.out.println("\n\n****** First book output\n" + bookRec1.toString());
        System.out.println("\n\n****** Second book input");
        bookRec2 = new Book(authorRec2, in);
        System.out.println("\n\n****** Second book output\n" + bookRec2.toString());
        System.out.println("\n\n****** First book output\n" + bookRec1.toString());
    class Author {
      private String authorName;
      private Initials inits;
      private int numTitles = 0;
      // PRE True POST Prompts user for details
      // and RETURNS new Author constructed from details
      public Author(BufferedReader in) {
        System.out.print("\nSurname ==> ");
        authorName = Text.ReadString(in);
        inits = new Initials(in);
        numTitles = 0;
      // PRE TRUE
      // POST RETURNS String representation of Author
      public String toString() {
        String result;
        result = "NAME : " + authorName + " " + inits.toString() + "\n";
        result = result + "Number of titles is " + numTitles;
        return(result);
      // PRE TRUE
      // POST Increments number of titles
      public void incTitles() {
        numTitles++;
    class Book {
      private String title;
      private Author author;
      // PRE TRUE // POST Prompts user for details
      // and RETURNS new Author constructed from details
      public Book(Author author, BufferedReader in) {
        System.out.print("\nTitle ==> ");
        title = Text.ReadString(in);
        this.author = author;
        author.incTitles();
      // PRE TRUE
      // POST RETURNS String representation of Book
      public String toString() {
        String result;
        result = "TITLE : " + title + "\n";
        result = result + "AUTHOR\n" + author.toString() + "\n";
        return(result);
    class Initials {
      private String inits;
      public Initials(BufferedReader in) {
        System.out.print("\nInitails Testing ==> ");
        inits = Text.ReadString(in);
      public String toString() {
        String result;
        result = inits;
        return(result);
    class Text {
      static String ReadString(BufferedReader in) {
        String text = "";
        try {
          text = in.readLine();
        catch (IOException e) {
          System.out.println(e.getMessage());
          System.exit(0);
        return text;
    }

Maybe you are looking for

  • Deploying a web app under 9.2

    Hello, I am trying to deploy a web app using bea 9.2 console and i am getting error with deployment descriptor (which 8.2 specific). So i tried to use appc and got the same error (listed below). Can anyone tell me what is wrong with my descriptor? Th

  • Sound from 1 out of 5 speak

    I have a Audigy 2 ZS with a 5. Altec Lansing speaker setup and the problem I am having is I can hear audio on one out of fi've of my speakers (rear left) and very loud crackling noise from the others. I get the same thing from all audio formats (mp3,

  • MAC pro monitor

    Can someone guide me: I cnnot align the mac pro screen to the large external screen that sits behind the laptop so that both images appear in sme location. One set of images is off screen on one monitor and on screen in the other and vice versa.  

  • Block The Vendor Payment

    Dear All, I need to Block the Vendor Payment .But I need to do MIGO,and MIRO Transaction.Without payment block .I want that while doing miro it automatically block for payment without any manual intervention. Thanks & Regards Meruta

  • Include asset in inventory list - asset master record

    Hi What is the importance of "include asset in inventory list" in asset master record. Thanks in advance prasad