ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Not able to compile

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Not able to compile

    Hi all,

    I am trying to compile simple Hello1 program . Can any body pl help me y I am getting these errors


    class Hello1 {
    public static void main (String args[]) {
    System.out.println("Hello World");
    }
    }


    avac Hello1.java
    Hello1.java:1: 'ä' expected
    class Hello1 {
    ¬
    Hello1.java:2: illegal character: Ö172
    public static void main (String args[]) {
    ¬
    Hello1.java:6: ';' expected
    ¬
    3 errors



    Thanks in Advance

  • #2
    Re: Not able to compile

    Change from "class Hello1 {"
    to "public class Hello1 {"

    You should be fine now.

    Comment


    • #3
      Re: Not able to compile

      A class doesn't have to be public and the original code posted should work. To test this I pasted this code into a file called Hello1.java and compiled and ran it successfully.

      One thing you must be sure of is that your class has exactly the same name as the *.java file that contains it. I tried recreating this problem but you would get the following compile error.
      "the public type xxx must be contained in it's own file"

      The only other thing it could be then is an encoding issue. You either need to change the encoding of your source file or use the -encoding parameter of the Java compiler.

      Out of interest the legal access modifiers for a class are public, abstract, final or the default access modifier. This means the only illegal access modifiers are private and protected. The access modifiers are as follows.

      default
      If you don't specify an access modifier then you get the default. This is sometimes known as the package private modifier because it is effectively publicly accessible to objects of the same package but private to objects in different packages. This applies to classes, methods and class attributes.

      public
      This means all objects regardless of package can access this class, method or attribute.

      abstract
      An abstract class is a class that can never be instantiated. Abstract methods can be added to an abstract class. These look like the method signatures you see in an interface. Other classes can then extend the abstract class and provide implementation for the abstract methods. So it's a bit like an interface with some implementation.

      final
      A final class or method is one that cannot be extended. A final attribute is basically a constant as you cannot modify it's value.

      private
      A private method or attribute is one that is only accessible within it's enclosing class. An objects private attributes and methods cannot be accessed by other objects, even those of the same class or type. It is considered good OO practice to make all class attributes private and expose them to other objects using methods.

      protected
      This is the most complicated one. It's the same as the default modifier except that methods and attributes will also be accessible to sub classes, even if they are in another package!

      Where I have said methods I am also including constructors.
      Ben

      Comment

      Working...
      X