0

Started coding in java , just wanted to see the implementation of classes and interfaces we actually import to use their methods. Ex:

import java.util.Scanner;

I am curious to see what's inside the class Scanner(){} Is that possible?

Tried Searching but couldn't find the implementation and definitely did not understand how they hide them from public.

Zain Arshad
  • 1,885
  • 1
  • 11
  • 26
BHARATH CHANDRA
  • 339
  • 1
  • 4
  • 13

2 Answers2

1

Please follow the following Steps to See Java predefined classes implementation

1) Get rt.jar (It contains all Core Java API Classes which required for JRE at Runtime)

Download it from the internet directly or Search it in JDK at Path like C:\Program Files\Java\jdk1.8.0_181\jre\lib and copy it to other location on your Desktop rt.jar Location

2) Extract the copy of rt.jar

Extracting .jar file with command line

https://www.wikihow.com/Extract-a-JAR-File

After extracting you can see all the Core Java Classes in .class file (cant read it Directly) which we use normally in our programs

3) Download tools like cavaj java decompiler to open and read .class file open .class file in Decompiler

You Can see any code in Any jar with this approach... Its very smart way to understand basics of java with fun ..

Ajinkya
  • 325
  • 3
  • 12
  • Understood , Just extracted the Hipster package , it's unreal to see all that code! ..Lot's to learn , Thank You! – BHARATH CHANDRA Apr 10 '19 at 08:13
  • 1
    @BHARATH CHANDRA .. for better Under standing start with `rt.jar` And see code in classes in Packages like **java.lang** , **java.util** – Ajinkya Apr 10 '19 at 09:47
0

There is nothing "hidden from public" concerning java.util.Scanner.

@shmosel already linked to the source of it, @Stultuske pointed out, that there are various websites covering source code of java.

Modern IDEs also allow you to view into source for your libraries (aka .jar files). My Netbeans IDE shows source from known jar files whenever I ctrl-click on a class. Same goes with Eclipse, IntelliJ, ...

For a lot of open-source libraries (e.g. from Apache) there is also source code available. Just by cloning the version control repository, downloading source packages (zip, ...-source.jar) or browsing the version control repository online. If project is buildable with maven, the IDE can even download and show sources for open source project automatically.

SirFartALot
  • 1,215
  • 5
  • 25