This program must compile or not?

Hi,
I tried to compile the following program under JDK 1.3.0 and it does not compile. Of course it will not compile.
Nevertheles, I think it should compile, since f() returns a void, and so g(), so there is no type checking error there.
public class pru {
     public void f() {
          System.out.println("entered in f");
          return g();
     public void g() {
          System.out.println("entered in g");
     public static void main(String[] argv) {
          pru p = new pru();
          p.f();
I'll wait for your opinions.
Gabriel

The question that I wanted to know is if the compiler
treats the void type as just another type, it has
special semantics. I guess it has special semantics.Are you sure that void is really a type?
What would you expect to be:
private void XXX; //the compiler casts, of course, '(' expected
I thought it's just a reserved word which has some semantical meaning in the language (like private, while, etc.)
If you want a reason, you probably need to step back to the 60's to Algol (I know it from Pascal, which is an Algol's derivate): there were 2 ways of calling a subprogram
- procedures (returning no result, called as a 'user-specified' command)
- functions (returning exactly one result, if I remember it well, only of primitive types, called only as a part of an expression of the same type)
- then in C, everything turned to be a function (void was introduced - probably to prove that C designers could beat the poor Pascal in everything) but as you could ignore the returned parameter the only real difference was that you could call 'return;' instead of 'return XXX;', and I'm not sure whether you could, on the other hand, call a function defined with 'void' as a part of an expression (but in C everything had a value, so even this is possible)

Similar Messages

  • Cannot Get This Program To Compile

    Can someone please review this question and help me to fix the syntax. I will also post the question so that you have an idea of what is going on. I am very frustrated about this problem. I just can't get it to work and I really don't know all of the commands. I am a novice to Java.
    The letters of a word are stored in an array str with the first letter in str(1), the second in str(2), and so on. The character ?$? is placed in the array after the last letter of the word to indicate the end of the word.
    Suppose that str contains m letters (excluding ?$?).
    Write a program to:
    1. Allow the user to read a word into the array str. Assume that there is no word longer than 100 characters.
    2. Read an integer value (n > 0) and a letter, ?letter?. Your program must insert letter after the nth letter in str. The letters to the right of the nth letter (including ?$?) must be shifted right by one position to make room for letter. Validate the value of n.
    3. To delete a letter, 'error', from the word all the letters following 'error' must be shifted left by one position to overwrite 'error'. Your program must prompt the user for the letter 'error' and delete the letter from the word.
    import java.io.*;
    public class Assign5
    public static void main(String[]args) throws IOException
    char str[] = new char[100];
    int count =0;
    BufferedReader read = new BufferedReader (new InputStreamReader (System.in));
    String word;
    String letter;
    String input;
    System.out.println("******Word Count, Formation & Reformation Function******");
    System.out.println("\nEnter your word of choice ending with $ e.g. Scavenger$ ");
    word = read.readLine();
    do
    if (Character.isSpaceChar(word.charAt(count)) == true)
    System.out.println("You forgot the $ to indicate the end of the word");
    System.out.println( "Enter word to which manipulation must be done, ending with $ e.g. Scavenger$");
    word = read.readLine();
    str[count]= word.charAt(count);
    count ++;
    }while (str[count -1] != '$');
    int m = count -1;
    System.out.println("\nThe number of letters in the word is " +m);
    //Word Re-Formation Function
    System.out.println("\nEnter a letter that you wish to stuff into your word");
    letter = read.readLine();
    System.out.println( "\nEnter the letter position (an integer) after which to stuff your letter");
    input = read.readLine();
    int n = Integer.parseInt(input);
    n = n - 1 ;
    while(n <= 0)
    System.out.println("\nI am sorry...that position is invalid");
    System.out.println("\nEnter the letter position (an integer) after which to stuff your letter");
    input = read.readLine();
    n = Integer.parseInt(input);
    n = n-1;
    char temp[] = new char[100];
    int index = 0;
    for(int i = (n+1);i <= m; i++)
    index = index +1;
    temp[index] = str;
    str[n +1] = letter.charAt(0);
    index = 1;
    for(int i = (n+2); i <= (m+1) ; i++)
    str = temp[index];
    index = index + 1;
    //Printing the new word
    System.out.print("\nThe new reconstructed word is: ");
    for(int i = 0; i <= m ; i++)
    System.out.print(str);
    System.out.println();
    int newM = m + 1;
    //Error Correction Module
    System.out.print("\nThe new reconstructed word is: ");
    for(int i = 0; i <= m ; i++)
    System.out.print(str);
    char errorLetter[] = new char[1];
    do
    System.out.println("Enter a letter that you wish to remove from your word");
    input = read.readLine();
    errorLetter[1] = input.charAt(1);
    int position = 0;
    for(int findLetter = 1; findLetter <= newM; findLetter++)
    if(errorLetter[1] == str[findLetter])
    position = findLetter;
    if(position == 0)
    System.out.println("I am sorry?that letter is NOT contained in the word.");
    errorLetter[1] = ' ';
    position = 0;
    }while (errorLetter[1] == ' ');
    System.out.println("The new word formed after removing your letter is: ");
    for(i = 1; i = 100; i++)
    if(i = position)
    str = temp[i + 1];
    for(fillLoop = i + 1; fillLoop = 99; fillLoop++)
    str[fillLoop] = temp[fillLoop + 1];
    for(i = 0; i = 100; i++)
    System.out.print(str[fillLoop]);
    }

    As I'm sure the compiler would help you find out, there are a few problems in this:
    1. You treat str as if it's a single char, when in fact it's a char array (char[]). If you want to copy an element in str to temp, you have to do it like str[i] = temp
    2. You are not properly declaring your variables in your loops. You have to declare every variable before you use it, so this is wrong:
              for (i = 1; i = 100; i++) {
                   if (i = position) {
                        str = temp[i + 1];
                        for (fillLoop = i + 1; fillLoop = 99; fillLoop++) {
                             str[fillLoop] = temp[fillLoop + 1];
              }It should instead be
              for (int i = 1; i = 100; i++) {
                   if (i = position) {
                        str = temp[i + 1];
                        for (int fillLoop = i + 1; fillLoop = 99; fillLoop++) {
                             str[fillLoop] = temp[fillLoop + 1];

  • I am running MAC and when I try to open lightroom5, I am getting the following: "This program must be run under Win32" The download link says WIN /MAC. I have no other option.

    What can I do so that I can download this to my MAC?

    Lightroom - all versions
    Windows
    http://www.adobe.com/support/downloads/product.jsp?product=113&platform=Windows
    Mac
    http://www.adobe.com/support/downloads/product.jsp?product=113&platform=Macintosh

  • 'this program must be run under win32'

    ...drivers meant for 'mac' from 'Empia dvd maker2' bring up the above response . Is there a 'non Terminal window' solution. Thanks

    Where did you get these "drivers"?  If they are true mac drivers the filename extension will usually be ".kext".  If they are windows executables those will usually have ".exe". 

  • Anyone can compile this program?Duke will be rewarded

    Anyone can help me compile this program..I try debugging a lot of time but it is not working!
    import java.lang.*;
    import java.awt.*;
    import java.applet.*;
    import java.awt.event.*;
    public class ChatApplet extends Applet implements ActionListener,Runnable
    String user;
    String msg;
         public void init() {
              super.init();
              //{{INIT_CONTROLS
              setLayout(new BorderLayout(0,0));
              addNotify();
              resize(518,347);
              setBackground(new Color(12632256));
    msgbox = new java.awt.TextArea("",2,0,TextArea.SCROLLBARS_NONE);
              msgbox.setEditable(false);
    msgbox.disable();
    //msgbox.hide();
              msgbox.reshape(0,0,380,216);
              add(msgbox);
              idbox = new java.awt.TextField();
              idbox.reshape(84,288,284,24);
              add(idbox);
              button1 = new java.awt.Button("EnterRoom");
              button1.reshape(384,288,72,21);
              add(button1);
    list = new java.awt.List();
    //list.TOP_ALIGNMENT();
    //list.disable();
    list = new java.awt.List(5);
    list.add("#Default User"+"\n");
    list.reshape(384,24,128,196);
    list.setFont(new Font("Helvetica", Font.BOLD, 12));
    add(list);
              label2 = new java.awt.Label("Members");
              label2.reshape(396,0,100,19);
              add(label2);
              label1 = new java.awt.Label("UserName");
              label1.reshape(0,288,72,27);
              add(label1);
              textbox = new java.awt.TextField();
              textbox.reshape(84,240,431,44);
              add(textbox);
              label3 = new java.awt.Label("EnterText");
              label3.reshape(0,252,72,25);
              add(label3);
    //uf = new UserFrame();
              button1.addActionListener(this);
    idbox.addActionListener(this);
    textbox.addActionListener(this);
    list.addActionListener(this);
    public void actionPerformed(ActionEvent ae)
              if(ae.getSource()==idbox)
    user = idbox.getText()+"\n";
    list.addItem(user.trim());
    idbox.setText("");
                             msgbox.append(user+" HAS JOINED THE GROUP");
         if(ae.getSource().equals(button1))
    user = idbox.getText()+"\n";
    list.addItem(user.trim());
    idbox.setText("");
                             msgbox.append(user+" HAS JOINED THE GROUP");
    if(ae.getSource().equals(textbox))
    msg = textbox.getText();
    msgbox.append(msg+"\n");
    textbox.setText("");
    if(ae.getSource().equals(list))
    String l = list.getSelectedItem();
                             //uf.setTitle(l);
                             //Frame i[] = uf.getFrames();
                             //uf.setVisible(true);
    public void start()
    if(vt == null)
    vt = new Thread(this,getClass().getName());
    vt.start();
    public void run()
    try{
    for(int i=0;i<10;i++)
    msgbox.append("One stop Java source code - www.globalleafs.com"+"\n");
    msgbox.setForeground(Color.red);
    vt.sleep(30000);
    vt.resume();
    }catch(Exception e){e.printStackTrace();}
         java.awt.TextArea msgbox;
         java.awt.TextField idbox;
         java.awt.Button button1;
    java.awt.List list;
    java.awt.Label label2;
         java.awt.Label label1;
         java.awt.TextField textbox;
         java.awt.Label label3;
    private Thread vt;

    The program compiles over here. It just has some deprecation warnings ...or is that what you wanted debugged?
    Don't use reshape() ...I think in AWT you should now use setBounds();
    Don't use list.addItem(); ...looks like the API steers us to list.add();
    Don't use Thread.resume() ...I don't think there is a replacement (unneccessary?).
    Gee, this program must have ran the chat program in Ford's old model T ... !! (??)

  • How come this program compiles?

    class Base
         Base()
              int i = 100;
              System.out.println(i);
    public class Pri extends Base
         static int i = 200;
         public static void main(String[] args)
              System.out.println(i);
              Pri p = new Pri();
    i get very confused here. in the main, the value of "i" will be printed to the standard output even before the class Pri is instantiated! how come this program can compile?
    your help will be very much appreciated.
    eileen2

    This is because your class Pri extends Base. Because you didn't specify any class Pri constructor, java automatilcally created a no-argument constructor of class Pri with a call to the superclass constructor Base(). You can validate this by adding another Base constructor with arguments and then removing the no-argument Base constructor. Pri() will not compile.

  • How do I stop firefox from sending a message or note that " do I want this program to change my computer?" It changes some of the settings in my computer; like the color of my task bar changed and other settings too.

    Before nothing happened until just recently when box messages would appear and tell me to click "yes or no" if I want the program to change my laptop. I clicked "No", but sometimes it didn't work, and when it didn't work. When it failed, fire fox changed some of the settings in my laptop. For example, the task bar's color would be changed. Also, it seemed as if fire fox had changed some of the settings into an old version. Yesterday I restarted my laptop, and it just went back to normal like nothing happened. But, for a few minutes later, the box will appear and you have to click yes or no. I clicked the "x" button, and it just changed automatically.

    Check that you do not run Firefox as Administrator.<br />
    Right-click the Firefox desktop shortcut and choose "Properties".<br />
    In the Compatibility tab, make sure that Privilege Level: "Run this program as Administrator" is not selected.<br />
    You also need to check the Properties of the firefox.exe program in the Firefox program directory.<br />

  • I could previously open my itunes program on my computer. Not now as when it asks, Do you want to allow this program to make changes to your computer and I select, Yes, it shuts down.  I have removed and re-installed itunes, checked firewall. Pls help

    I could previously open my itunes program on my computer and sync with ipad, ipod and iphone but no longer. When I select itunes a dialogue box opens  with question - "Do you want to allow this program to make changes to your computer"  When I select YES, it just shuts down.   I have removed and reinstalled itunes. have checked firewall and spent hours trying to fix. Please help.

    A possible cause of this error is that Firefox is set to run as Administrator.
    Check that Firefox isn't set to run as Administrator.
    Right-click the Firefox desktop shortcut and choose "Properties".
    Make sure that all items are deselected in the "Compatibility" tab of the Properties window.
    * Privilege Level: "Run this program as Administrator" should not be selected
    * "Run this program in compatibility mode for:" should not be selected
    Also check the Properties of the firefox.exe program in the Firefox program folder (C:\Program Files\Mozilla Firefox\).

  • I have Adobe premiere 12 elements I have Buy it but this program is Corrupt. the are no sound on the time line. I have sound in my computer, this is no problem, I can listen every another things but NO Elements 12 OK I make ia video take down to the time

    i have Adobe premiere 12 elements I have Buy it but this program is Corrupt. the are no sound on the time line. I have sound in my computer, this is no problem, I can listen every another things but NO Elements 12 OK I make ia video take down to the time line. Video is OK BUT NO sound I have makit in 2 veeks from monday to next vek here whit this very bad program so i go to garbags I think I buy a another program is be better and have a Sound. This is very bad I am not god to English. I Have a pro camera and I will have a god support but this is very bad. I is bad to English. But this Program I buy i think this is very Corrupt. The mast find a sound in this program. I cvan not understan if You can sell this very bad program Videoredigering and this program have nothing sound. This is crazy.

    i have Adobe premiere 12 elements I have Buy it but this program is Corrupt. the are no sound on the time line. I have sound in my computer, this is no problem, I can listen every another things but NO Elements 12 OK I make ia video take down to the time line. Video is OK BUT NO sound I have makit in 2 veeks from monday to next vek here whit this very bad program so i go to garbags I think I buy a another program is be better and have a Sound. This is very bad I am not god to English. I Have a pro camera and I will have a god support but this is very bad. I is bad to English. But this Program I buy i think this is very Corrupt. The mast find a sound in this program. I cvan not understan if You can sell this very bad program Videoredigering and this program have nothing sound. This is crazy.

  • I have Windows 7. When I start Firefox 4, I get a warning, "Do you want to allow this program to make changes to this computer"? Is there a way to stop this warning?

    Question
    I have Windows 7 Home Premium. When I start Firefox 4, I get a User Account Control warning, "Do you want to allow the following program to make changes to this computer"? Is there a way to stop this warning?

    Check that you do not run Firefox as Administrator.
    Right-click the Firefox desktop shortcut and choose "Properties".
    In the Compatibility tab, make sure that Privilege Level: "Run this program as Administrator" is not selected.
    Also check the Properties of the firefox.exe program in the Firefox program directory.

  • Lately when I launch Firefox an alert window comes up asking of I want this program to make changes to the computer. Also, I am unable to download PDF files from other sites.

    This Problem started about two weeks ago.

    Check that you do not run Firefox as Administrator.
    Right-click the Firefox desktop shortcut and choose "Properties".
    Make sure that all items are deselected in the "Compatibility" tab of the Properties window.
    * Privilege Level: "Run this program as Administrator" should not be selected
    * "Run this program in compatibility mode for:" should not be selected
    Also check the Properties of the firefox.exe program in the Firefox program directory.

  • How do I discontinue this program

    how do I discontinue this program?

    I'm not sure what you want to discontinue, but if you want to stop receiving e-mail messages from these forums, see:
    Stopping emails from ASC
    If that's not what you're talking about, you'll need to be more specific.

  • Is anyone actually making music with this program?

    I am a Producer/Engineer and teacher at a top London music school (also apple training center) and regular user of Logic studio 8 and it doesn't work. Lets face it constant error messages system overloads etc on a variety of machines is not a professional piece of software.
    Logic 7 had its bugs but at least it worked on high track count recordings without cpu overloads etc in the middle of a take or crashing using minimal amount of software instruments. It seems there are many solutions to the problems that don't work, e.g. Turn off airport, load logic with a script, run activity monitor in the background or turn round three times whilst patting your head and standing on one leg. This all ********, we should not be suffering this. At the end of the day, I am sure you all just want to make music like i do. After all that is why we bought this program. I do not (when I know the computers that i use are powerful enough) want to spend my valuable time troubleshooting for Apple. On our session today we abandoned using Logic 8 with many clients and also potential customers for Apple being turned off by all the ******** goings on.
    Ah well back to 7 at least we can get through a take. Logic Pro or Garage band pro what is it
    SORT IT NOW before its too late.

    Er... well my Logic 8 runs perfectly. Just as stable as 7 if not better. And in answer to your question, yes TONS of people are making music with Logic 8 without problems. If you're a top London Music school and an Apple cert training centre, then you should have access to the resources to sort the problem out, because whilst everyone gets the odd crash, it sounds like your setup is practically a no-starter. Which means its probably system specific. Which also means your going to have to go back to square one and identify the problem. Do post more info about your issues if you want them fixing rather than ranting about Logic because its not helpful or constructive. Then maybe people will try and help!

  • This program is well compiled but does not work.

    I would like to know why this program does not work properly:
    the idea is :
    1. the user introduces a text as a string
    2.the progam creates a file (with a FileOutputStream)
    3. then this file is encripted according to DES (using JCE, cipheroutputStream)
    4.the new filw is an encripte file, whose content is introduced in a string (with a FileInputStream)
    (gives no probles of compilation!!)
    (don know why it does not work)
    here goes the code:
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    import java.io.*;
    import java.security.*;
    import javax.crypto.*;
    public class cuadro extends Applet{
         private TextArea area1 =new TextArea(5,50);
         private TextArea area2 =new TextArea(5,50);
         private Button encriptar=new Button("encriptar");
         private Button decriptar=new Button("decriptar");
         public cuadro(){
              layoutApplet();
              encriptar.addActionListener(new ButtonHandler());
              decriptar.addActionListener(new ButtonHandler());
              resize(400,400);
              private void layoutApplet(){
              Panel keyPanel = new Panel();
              keyPanel.add(encriptar);
              keyPanel.add(decriptar);
              Panel textPanel = new Panel();
              Panel texto1 = new Panel();
              Panel texto2 = new Panel();
              texto1.add(new Label("               plain text"));
              texto1.add(area1);
              texto2.add(new Label("               cipher text"));
              texto2.add(area2);
              textPanel.setLayout(new GridLayout(2,1));
              textPanel.add(texto1);
              textPanel.add(texto2);
              setLayout(new BorderLayout());
              add("North", keyPanel);
              add("Center", textPanel);
              public static String encriptar(String text1){
              //generar una clave
              SecretKey clave=null;
              String text2="";
              try{
              FileOutputStream fs =new FileOutputStream ("c:/javasoft/ti.txt");
              DataOutputStream es= new DataOutputStream(fs);
                   for(int i=0;i<text1.length();++i){
                        int j=text1.charAt(i);
                        es.write(j);
                   es.close();
              }catch(IOException e){
                   System.out.println("no funciona escritura");
              }catch(SecurityException e){
                   System.out.println("el fichero existe pero es un directorio");
              try{
                   //existe archivo DESkey.ser?
                   ObjectInputStream claveFich =new ObjectInputStream(new FileInputStream ("DESKey.ser"));
                   clave = (SecretKey) claveFich.readObject();
                   claveFich.close();
              }catch(FileNotFoundException e){
                   System.out.println("creando DESkey.ser");
                   //si no, generar generar y guardar clave nueva
              try{
                   KeyGenerator claveGen = KeyGenerator.getInstance("DES");
                   clave= claveGen.generateKey();
                   ObjectOutputStream claveFich = new ObjectOutputStream(new FileOutputStream("DESKey.ser"));
                   claveFich.writeObject(clave);
                   claveFich.close();
              }catch(NoSuchAlgorithmException ex){
                   System.out.println("DES key Generator no encontrado.");
                   System.exit(0);
              }catch(IOException ex){
                   System.out.println("error al salvar la clave");
                   System.exit(0);
         }catch(Exception e){
              System.out.println("error leyendo clave");
              System.exit(0);
         //crear una cifra
         Cipher cifra = null;
         try{
              cifra= Cipher.getInstance("DES/ECB/PKCS5Padding");
              cifra.init(Cipher.ENCRYPT_MODE,clave);
         }catch(InvalidKeyException e){
              System.out.println("clave no valida");
              System.exit(0);
         }catch(Exception e){
              System.out.println("error creando cifra");
              System.exit(0);
         //leer y encriptar el archivo
         try{
              DataInputStream in = new DataInputStream(new FileInputStream("c:/javasoft/ti.txt"));
              CipherOutputStream out = new CipherOutputStream(new DataOutputStream(new FileOutputStream("c:/javasoft/t.txt")),cifra);
              int i;
              do{
                   i=in.read();
                   if(i!=-1) out.write(i);
              }while (i!=-1);
              in.close();
              out.close();
         }catch(IOException e){
              System.out.println("error en lectura y encriptacion");
              System.exit(0);
         try{
              FileInputStream fe=new FileInputStream("c:/javasoft/t.txt");
              DataInputStream le =new DataInputStream(fe);
                   int i;
                   char c;
                   do{
                        i=le.read();
                        c= (char)i;
                        if(i!=-1){
                        text2 += text2.valueOf(c);
                   }while(i!=-1);
                        le.close();
              /*}catch(FileNotFoundException e){
                   System.out.println("fichero no encontrado");
                   System.exit(0);
              }catch(ClassNotFoundException e){
                   System.out.println("clase no encontrada");
                   System.exit(0);
              */}catch(IOException e){
                   System.out.println("error e/s");
                   System.exit(0);
              return text2;
         class ButtonHandler implements ActionListener{
         public void actionPerformed(ActionEvent e){
              try{
              if (e.getActionCommand().equals(encriptar.getLabel()))
                   //     area2.setText(t1)
                   area2.setText(encriptar(area1.getText()));
                   //area2.setText("escribe algo");
                   else if (e.getActionCommand().equals(decriptar.getLabel()))
                        System.out.println("esto es decriptar");
                        //area2.setText("hola");
         }catch(Exception ex){
              System.out.println("error en motor de encriptacion");
                   //else System.out.println("no coge el boton encriptado/decript");

    If you don't require your code to run as an applet, you will probably get more mileage from refactoring it to run as an application.
    As sudha_mp implied, an unsigned applet will fail on the line
    FileInputStream fe=new FileInputStream("c:/javasoft/t.txt");
    due to security restrictions. (Which, incidentally, are there for a very good reason)

  • Why does Firefox give this message when I do not have another program running "Firefox is already running, but is not responding. To open a new window, you must first close the existing Firefox process, or restart your system."

    Question
    why does Firefox give this message when I do not have another program running or another window open - "Firefox is already running, but is not responding. To open a new window, you must first close the existing Firefox process, or restart your system." edit

    See also "Hang at exit":
    *http://kb.mozillazine.org/Firefox_hangs
    *https://support.mozilla.com/kb/Firefox+hangs

Maybe you are looking for

  • Zen V: Proble

    About a year ago. (9 months, to be exact), I got a Creative Zen V for my birthday. I was very excited and happy, as I use Creative products and software for building computers and didn't think I'd have much of a problem with my MP3 player. I was wron

  • Text elements in the Bex Report

    Bex Gurus, When we execute the Bex report, it will display with icons on top as Chart, Filter and Information - Information will display all the text elements as standard. Right now I want to modify these standard elements and disply the text element

  • Site collections, or sub-sites, in SharePoint Online?

    We have an established SharePoint 2010 intranet portal, which has many and various team sub-sites.  These sub-sites are created on request - sometimes it's because one of our locations wants their own little area to share documents, or it might be fo

  • Cannot save multiple tabs in firefox 4.0. NO OPTION

    in new firefox, i canno save multiple tabs....there no option about.

  • Activation coded needed

    Please I want the code for activation for Nokia. Lumia 710