• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Is an int array (int[]) apart of the Java Collections or Java Library?

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I have an assignment for class and the teacher has explicitly said No use of Java libraries, or any other libraries. (That precludes, for instance, the use of any Java Collections.) This means that NO IMPORT CLAUSES ARE ALLOWED.

I have used:



I didn't use any imports and from what I can see, is not apart of the Java Collections or Libraries. I just want to make sure otherwise I get a 0. Is it?

Thanks.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Arrays are a built-in Java language feature. They're not part of the Java collection classes or standard Java library.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Make sure you also don't use anything from java.lang. These don't need to be imported but are part of the core library. That means you can't use String, Object, Integer etc.
 
Luke Winter
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Spoor wrote:Make sure you also don't use anything from java.lang. These don't need to be imported but are part of the core library. That means you can't use String, Object, Integer etc.



Thank-you Rob!
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Luke Winter wrote:

Rob Spoor wrote:Make sure you also don't use anything from java.lang. These don't need to be imported but are part of the core library. That means you can't use String, Object, Integer etc.

Thank-you Rob!


Hmmm. It depends what your tutor's 'rule' actually means. Is it "no import statements" or "no use of any libraries"?
Rob's quite right that java.lang is a library; but not allowing it means that you can't use any objects at all except arrays (because Object itself is also part of java.lang), which seems an odd way to learn an Object-Oriented language.

You might want to check with him/her to make sure exactly what the rule means.

Winston
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The teaching goal of this exercise completely eludes me. "Here's a bicycle, learn how to ride it but don't use the pedals." WTH?
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I also wonder how strict the rules are - because really, it's impossible to write a Java program without using anything from the java.lang package at all.

Look at this super simple program.

What could be "wrong" with this?

  • Class Example implicitly extends java.lang.Object. So, we're already (implictly) using a class from java.lang there.
  • The main method takes a String[] as its argument. That's just how you have to write it. No escaping from using class java.lang.String here.
  • Class System is also a class from the java.lang package. If you were not allowed to use this, your program couldn't print any output at all.

  •  
    Rob Spoor
    Sheriff
    Posts: 22783
    131
    Eclipse IDE Spring VI Editor Chrome Java Windows
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Don't forget the PrintStream (from java.io!) you're using there.
     
    Bartender
    Posts: 4568
    9
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Of course, if the rule was just "no imports", you can fully qualify all your class names and use whatever you want!
     
    lowercase baba
    Posts: 13089
    67
    Chrome Java Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    This assignment seems about as useful as

    Can you write a program that doesn't use the letter 'e' in it anywhere. Even if you can, what would be the point?

     
    Matthew Brown
    Bartender
    Posts: 4568
    9
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    More seriously, I suspect it's a clumsy way of phrasing an exercise in using arrays and loops to stop people using collection classes that would make life too easy and side-step the things that are actually being tested.
     
    Winston Gutkowski
    Bartender
    Posts: 10780
    71
    Hibernate Eclipse IDE Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Jesper de Jong wrote:Class Example implicitly extends java.lang.Object...


    Which raises an interesting point. Does xxx[] actually extend java.lang.Object or not? I suspect so since, as we all know, arrays are objects; but since it's part of the language it could simply be a structure dressed up to look like an Object.

    I suspect it's stated in the JLS somewhere; I've just never had reason to find out.

    Winston
     
    Marshal
    Posts: 79178
    377
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Winston Gutkowski wrote: . . . Does xxx[] actually extend java.lang.Object or not? . . . I suspect it's stated in the JLS somewhere; . . . Winston

    Of course it is in the JLS.
     
    Jesper de Jong
    Java Cowboy
    Posts: 16084
    88
    Android Scala IntelliJ IDE Spring Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Winston Gutkowski wrote:Does xxx[] actually extend java.lang.Object or not? I suspect so since, as we all know, arrays are objects; but since it's part of the language it could simply be a structure dressed up to look like an Object.


    That's really a theoretical discussion for which I'm not sure if there's an answer, but it doesn't matter. If an int[] looks like an Object, behaves like an Object, has all the methods of class Object, then does it matter if it really extends Object or if the compiler just makes it look like an Object? What does the difference even mean if there's no practical difference when using arrays?

    The JLS paragraph that Campbell linked to says that arrays inherit the members from Object, which seems to imply that arrays indeed extend Object.
     
    Campbell Ritchie
    Marshal
    Posts: 79178
    377
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    …And if you scroll up, it says you can assign any array to an Object reference. If you scroll down there is an example where it prints the name of the superclass.
     
    Winston Gutkowski
    Bartender
    Posts: 10780
    71
    Hibernate Eclipse IDE Ubuntu
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Jesper de Jong wrote:If an int[] looks like an Object, behaves like an Object, has all the methods of class Object, then does it matter if it really extends Object or if the compiler just makes it look like an Object?


    Because of the rather ambiguous "rules" that started off this whole thread. It may be splitting hairs to you, but it might mean a 0 for poor Luke.

    Winston
     
    What a stench! Central nervous system shutting down. Save yourself tiny ad!
    a bit of art, as a gift, the permaculture playing cards
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic