1

I am learning Java and I have came across few packages like util package, swing package etc. I want to dig it more so my question is when we import any packages in our source code where can I see those packages and the class codes in my personal computer.

Let's say there is an util package and ArrayList class. So where can I find the util package and ArrayList class?

Can I make any changes to ArrayList class or any other class?

I am trying to have the packages and class code without Eclipse installation. I have installed JDK and JRE and running the Java files through command prompt and using Notepad++ for writing code.

Lii
  • 11,553
  • 8
  • 64
  • 88
  • 1
    Possible duplicate of [How do I view JRE's source code in Eclipse?](http://stackoverflow.com/questions/426084/how-do-i-view-jres-source-code-in-eclipse) – shmosel Aug 21 '16 at 06:42
  • You can see the `ArrayList` class of course but you don't have to change the class usually. You can write your custom `ArrayList` class and then you can import from your own package. The `ArrayList` from `util` package should not be modified. – Reaz Murshed Aug 21 '16 at 06:46
  • @shmosel I am trying to have the packages and class codes without Eclipse installation. I am running simple jdk and jre and the java files through command prompt and using notepad++ for writing codes –  Aug 21 '16 at 06:55
  • 2
    This is one of the reasons you want an ide like eclipse instead of a traditional editor. It helps you with all the things not in your own source code. I would suggest using https://docs.oracle.com/javase/8/docs/api/ in a browser as it is the web version of the public documentation for all standard Java classes – Thorbjørn Ravn Andersen Aug 21 '16 at 07:12
  • @ThorbjørnRavnAndersen I am beginner so i guess i should start with notepad++ . I think it gives the better understanding of how your code is executing –  Aug 21 '16 at 07:17
  • Yes. Then you need good documentation. – Thorbjørn Ravn Andersen Aug 21 '16 at 07:30

2 Answers2

4

java.util.ArrayList is provided by the JRE, it is in rt.jar (and you can see the source).

Can I make any changes to ArrayList class or any other class?

You could sub-class ArrayList (or simply implement List), but you can't really alter built-in classes (and even if you could, your code would then not be portable).

Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
  • when you say "your code would then not be portable" What do you mean by that ? –  Aug 21 '16 at 06:46
  • 1
    @luke Your `ArrayList` wouldn't exist on some other user's installation of Java (if you were to hack `rt.jar`), then your code might run on only one machine (instead of every installation of Java). Better to create your own sub-class and follow OOP. – Elliott Frisch Aug 21 '16 at 06:48
  • When i checked for the packages in my laptop they are executable jar file. So how can i check the packages class codes in my laptop. Or it can not be seen ? –  Aug 21 '16 at 06:52
  • It's shipped in compiled byte-code form. You **can** download the source code for Java. I already gave you a link to the source. – Elliott Frisch Aug 21 '16 at 06:59
1

where can I see those packages and the class codes in my personal computer.

Just click control key and right click of mouse at ArrayList Object if u use eclipse or netbeans

if not then you find it here C:\Program Files\Java\jdk1.6.0_11\jre\lib\rt.jar

Can I make any changes to ArrayList class or any other class?

You can't simply.java.util package contains the collections framework, legacy collection classes, event model, date and time facilities, internationalization, and miscellaneous utility classes and is provided by JRE

Bibek Shakya
  • 1,233
  • 2
  • 23
  • 45