NetBeans/JDK on Windows

NetBeans/JDK on Windows

Windows Essentials

For the sake of program development, it is important to make some
changes in a Windows system.
The Windows version used is 7,
but the instructions should be adaptable to later versions.

Set informative folders/files view

You need to know exactly the full names of files, including the file
extension that Windows prefers to keep hidden from the naïve user.
Make Windows to stop treating you like a baby! Make it show you file
extensions as well as other “hidden” features.

  • Open any folder, such as (My) Documents and select

    Organize ⇾ Folder and search options

  • Select the View tab.

Then make these changes:

  • (crucial) uncheck: Hide file extensions for known file types.
  • (useful) check: Show hidden files and folders radio button in
    Hidden files and folders.
  • (optional)
    uncheck: Hide protected operating system files (Recommended).

Replace Notepad by Notepad++

Notepad++ is free Windows software which can effectively replace that
poor excuse for an editor called Notepad.
Even if you have only a few brain cells,
you should try to
never use Notepad on your own Windows system. In contrast,
Notepad++ provides very good syntax highlighting, multi-file editing,
Unix text file support, etc. Furthermore, it remembers the files you’ve
been editing so that they are readily available whenever you start it up.
The home page is this:
.txt, .ini, .conf, etc.), right-click and select

Edit with Notepad++

You can also get Notepad++ to edit by file extension editing
through Settings ⇾ Preferences ⇾
File Associations
.

Use a improved archive extraction tool

Windows built-in extraction of zip archives with many files is notoriously slow.
You can easily fix this problem by getting a decent archive handling utility.
The one I particularly like is 7zip with this home page:
.zip file), by right-clicking and selecting

7-zip ⇾ Open Archive

JDK Installation

The JDK installation file can be obtained from the Oracle website with
download page:

http://www.oracle.com/technetwork/java/javase/downloads (look
for Java SE version 8
)

jdk1.8.0_202

JDK installs into the following directory
(assuming C:\ is the system drive root):

C:\Program Files\Java\jdk1.8.0_202

Netbeans Installation

NetBeans is Oracle’s community-based Integrated Development Environment (IDE)
for a variety of software development interests including Java, Php, C/C++, etc.
It requires a JDK installation. The home and download pages are these:

For the sake of program development, it is important to make some changes in a Windows system. The Windows version used is 7, but the instructions should be adaptable to later versions.You need to knowthenames of files, including the file extension that Windows prefers to keep hidden from the naïve user. Make Windows to stop treating you like a baby! Make it show you file extensions as well as other “hidden” features.Then make these changes:Notepad++ is free Windows software which can effectively replace that poor excuse for an editor called Notepad. Even if you have only a few brain cells, you should try to never use Notepad on your own Windows system. In contrast, Notepad++ provides very good syntax highlighting, multi-file editing, Unix text file support, etc. Furthermore, it remembers the files you’ve been editing so that they are readily available whenever you start it up. The home page is this:From this home page the download is obvious and the installation is trivial. Once installed, to edit any text file (, etc.), right-click and selectYou can also get Notepad++ to edit by file extension editing throughWindows built-in extraction of zip archives with many files is notoriously slow. You can easily fix this problem by getting a decent archive handling utility. The one I particularly like iswith this home page:The download link is right in front of you. Just download and double-click to install. Once installed, open any archive file (in particular afile), by right-clicking and selectingThe JDK installation file can be obtained from the Oracle website with download page:For definiteness, I’ll assume this JDK version:JDK installs into the following directory (assumingis the system drive root):NetBeans is Oracle’s community-based Integrated Development Environment (IDE) for a variety of software development interests including Java, Php, C/C++, etc. It requires a JDK installation. The home and download pages are these:


The download link on the home page currently points to Apache/NetBeans, version 10.0.

The download I prefer is:

netbeans-8.2-javase-windows.exe

Reinstall NetBeans to change JDK versions

If you change JDK versions (like an upgrade) or want to go from JDK 11 to
JDK 8, reinstall NetBeans.
Go to Programs and Features from the
Control Panel. Find you current NetBeans installation; right-click
and uninstall it. You won’t lose anything at all!
Then re-install Netbeans and you will be presented with a choice of
which version of JDK to use.

C:\Program Files\Java\jdk1.8.0_jdk1.8.0_202

Personalize NetBeans

I recommend spending some time personalizing NetBeans’ settings.

Author and License

NetBeans automatically adds some level of documentation to Java (and other types of) files
it generates; in particular Licensing and Author information.

The licensing information is not particularly revelant to our needs,
but setting the user name is important.

  1. Set the user name which will
    be generated automatically in every class file.
    Go to Tools ⇾ Templates ⇾ Settings.
    Edit the file, setting the “user” variable.

    user = Your Name
    
  2. Next, get rid of the Licensing information.
    Go to Tools ⇾ Templates ⇾ Licenses.

    Save the current “Default License” by clicking on it and
    selecting Duplicate, thereby creating a copy

    Default License 1

    Here is the current content of the license file:

    Default License

    <

    #if licenseFirst??>

    $

    {

    licenseFirst

    }

    <

    /

    #if>

    $

    {

    licensePrefix

    }

    To change this license header

    ,

    choose License Headers ... $

    {

    licensePrefix

    }

    To change this template

    file

    ,

    choose Tools | Templates $

    {

    licensePrefix

    }

    and

    open

    the template

    in

    the editor.

    <

    #if licenseLast??>

    $

    {

    licenseLast

    }

    <

    /

    #if>

    DO NOT DELETE THIS FILE!
    Simply select the content and delete it, or replace it
    by something more meaningful to you.

Source formatting

NetBeans has a very useful feature called source formatting
accessible via Source &roarr; Format. By default, it will
format the entire file. If a region is selected, it will format
the region only. It is a good idea set these the way you like.

  1. Select Tools &roarr; Options, or on the MAC: Edit &roarr; Preferences.
  2. Choose Editor and then the Formatting tab.
  3. From the Language selection, choose All Languages
    (we’re only using Java, but these settings are useful across the board).

    Leave the “Expand Tabs to Spaces” checked and set these:

    Number of Spaces per indent:   2
    Tab Size:                      4
    
  4. From the Language selection, choose Java
    Set this:

    Continuation Indentation Size: 4
    
  5. Choose the Alignment category.
    In the New Lines section, check the checkboxes for these:

    “else”

    “while”

    “catch”

    “finally”

Hello World Program

NetBeans creates directories called src which consist of
one or more package of Java source files along with other types
of support files. The compiled classes are kept in a
separate build directory.

The download I prefer is:If you change JDK versions (like an upgrade) or want to go from JDK 11 to JDK 8, reinstall NetBeans. Go tofrom the. Find you current NetBeans installation; right-click andit. You won’t lose anything at all! Then re-install Netbeans and you will be presented with a choice of which version of JDK to use.I recommend spending some time personalizing NetBeans’ settings.NetBeans automatically adds some level of documentation to Java (and other types of) files it generates; in particular Licensing and Author information. The licensing information is not particularly revelant to our needs, but setting the user name is important.NetBeans has a very useful feature calledaccessible via. By default, it will format the entire file. If a region is selected, it will format the region only. It is a good idea set these the way you like.NetBeans creates directories calledwhich consist of one or more package of Java source files along with other types of support files. The compiled classes are kept in a separatedirectory.

To create a simple “Hello World” program, start up
NetBeans and follow the steps below.

  1. Select File &roarr; New Project
  2. In the New Project window,
    select the Java category,
    and choose Java Application, then Next.
  3. Choose the project name HelloWorld.
    The other settings have default values which you probably want to use.
    The project location cannot be an existing directory.

    NetBeans also pre-checks the box Create Main Class.
    Leave it checked.
    Click Finish.

  4. In the left-hand window there you can observe three views of
    the netbeans contents: Projects, Files,
    Services.
    For the most part you can work from the
    Projects view.
    In the Projects window you will
    see the file HelloWorld.java as part of the
    automatically-created helloworld package.
  5. Go to the Files view and observe the structure which
    NetBeans creates. The src folder is
    meant to hold all the source packages.
    The HelloWorld.java file is in a package directory
    HelloWorld
    within the src folder.

  6. Within the public static void main function, type

    System

    .

    out

    .

    println

    (

    "Hello World"

    )

    ;

    assists which the editor offers
    when you pause after typing a “.“.

  7. Select File &roarr; Save (or Ctrl-S) to save.
  8. There are several ways to compile and run this application.
    One way is to right-click on HelloWorld.java
    and select Run File from
    the popup menu.

    Look for
    the output in the Output window at the bottom.

  9. Another way to build and run the project is by selecting
    Run &roarr; Cean and Build Project
    or Shift+F11. This operation goes a step further and archives the compiled
    classes into the jar file HelloWorld.jar
    found in the newly created dist directory.
    Afterwards,
    select Run &roarr; Run Project or F6, or the

Shell Execution

Java is already part of a Windows system, but most commonly
JRE (Java Runtime Environment) which gives no access to the
development environment (JDK) necessary to run various
IDEs.
You will probably need to verify and/or set the PATH and CLASSPATH
environment variables.
The PATH specifies the list of folders searched
for executables. The CLASSPATH specifies the
list of folders and archives containing Java classes.

To create a simple “Hello World” program, start upand follow the steps below.Java is already part of a Windows system, but most commonly JRE (Java Runtime Environment) which gives no access to the development environment (JDK) necessary to run various IDEs. You will probably need to verify and/or set theand. Thespecifies the list of folders searched for executables. Thespecifies the list of folders and archives containing Java classes.

The Windows environment variables can be manipulated
through the Control Panel.
Start from the System and Security category and access:


System &roarr; Advanced System Settings &roarr; Advanced &roarr; Environment Variables

A good thing to do is to add the environment variable, JAVA_HOME,
and have the Path component added depend on this.
By doing so, changing Java versions requires only the change of
JAVA_HOME; futhermore, this environment variable is useful
for other Java-related software components.

The Windows environment variables can be manipulated through the. Start from thecategory and access:A good thing to do is to add the environment variable,, and have the Path component added depend on this. By doing so, changing Java versions requires only the change of; futhermore, this environment variable is useful for other Java-related software components.

Click on the New button in the System Variables section.
Enter the following information

Variable name:   JAVA_HOME
Variable value:  C:\Program Files\Java\jdk1.8.0_202 

Find the Path variable in the System Variables.
Select it and click Edit. It’s best to prepend the
new Path component with this addition:

%JAVA_HOME%\bin;

The Home button is a good way to get to the beginning of the Path expression.

Click on thebutton in thesection. Enter the following informationFind thevariable in the. Select it and click. It’s best tothe new Path component with this addition:Thebutton is a good way to get to the beginning of the Path expression.

Then check for presence of the CLASSPATH environment variable.
Software installations may have automatically set this variable in a way
which makes it unusable for shell execution. If it is defined,
make sure the CLASSPATH terminates with a semicolon (“;“).

Then check for presence of theenvironment variable. Software installations may have automatically set this variable in a way which makes it unusable for shell execution. If it is defined, make sure theterminates with a semicolon (“”).

After making these changes, click OK all the way out.
Afterwards, confirm by starting up a shell (Command Prompt) and executing these

java -version
javac -version

Executing a JAR file from the shell

NetBeans makes it easy to run its applications through
the shell, assuming that
your java executable is accessible.
First of all, you have to execute “Clean and Build
to create the JAR file.
The output of this operation indicates what should be done.

After doing so, open a command shell
and navigate to the dist folder in the
HelloWorld. From this folder run:

java -jar HelloWorld.jar

The dist folder is meant to be for “distribution.”
NetBeans will put all relevant libraries in this
folder as well so that this can act as a standalone
executable which can run on any system which has JRE
installed. All Windows systems will have it installed;
the only hitch is making sure that the version is up
to a suitable level.

After making these changes, clickall the way out. Afterwards, confirm by starting up a shell (Command Prompt) and executing theseNetBeans makes it easy to run its applications through the shell, assuming that yourexecutable is accessible. First of all, you have to execute “” to create the JAR file. The output of this operation indicates what should be done. After doing so, open a command shell and navigate to thefolder in the. From this folder run:Thefolder is meant to be for “distribution.” NetBeans will put all relevant libraries in this folder as well so that this can act as a standalone executable which can run on any system which has JRE installed. All Windows systems will have it installed; the only hitch is making sure that the version is up to a suitable level.