Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the meta-box domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home2/bhtinstitute/public_html/knowhow/wp-includes/functions.php on line 6114

Warning: Cannot modify header information - headers already sent by (output started at /home2/bhtinstitute/public_html/knowhow/wp-includes/functions.php:6114) in /home2/bhtinstitute/public_html/knowhow/wp-includes/feed-rss2.php on line 8
Java – Know How https://bhtinstitute.com/knowhow Bir Hassan Institute Fri, 04 Dec 2020 17:49:57 +0000 en-US hourly 1 https://wordpress.org/?v=6.7.1 194820497 III- How to Set JAVA_HOME in Windows https://bhtinstitute.com/knowhow/?p=186&utm_source=rss&utm_medium=rss&utm_campaign=iii-how-to-set-java_home-in-windows Fri, 04 Dec 2020 17:49:24 +0000 http://bhtinstitute.com/knowhow/?p=186 First, check if JAVA_HOME is already set by start a CMD and issue:

set JAVA_HOME

If JAVA_HOME is not set, you will receive “Environment variable JAVA_HOME not defined”. Otherwise, the current setting will be shown.

To set/change JAVA_HOME in Windows:

  1. Launch “Control Panel”
  2. “System”
  3. “Advanced system settings”
  4. Switch to “Advanced” tab
  5. “Environment variables”
  6. Choose “System Variables” (for all users)
  7. To add a new environment variable “JAVA_HOME“:
    1. Choose “New”
    2. In “Variable Name”, enter “JAVA_HOME”.
    3. In “Variable Value”, click “Browse Directory…” and navigate to the JDK installed directory (e.g., “C:\Program Files\Java\jdk-13.0.1“).
    4. OK ⇒ OK ⇒ OK.
  8. To change the existing “JAVA_HOME” setting:
    1. Select “JAVA_HOME” ⇒ “Edit”
    2. In “Variable Value”, click “Browse Directory…” and navigate to the JDK installed directory (e.g., “C:\Program Files\Java\jdk-13.0.1“).
    3. OK ⇒ OK ⇒ OK.

You need to RE-START CMD for the new setting to take effect!

To verify the new setting, re-start CMD:

set JAVA_HOME
JAVA_NAME=C:\Program Files\Java\jdk-13.0.1

NB:Replace jdk-13.0.1 by your current version

]]>
186
II – Get Started with Java Programming https://bhtinstitute.com/knowhow/?p=181&utm_source=rss&utm_medium=rss&utm_campaign=ii-get-started-with-java-programming Fri, 04 Dec 2020 17:42:18 +0000 http://bhtinstitute.com/knowhow/?p=181 1.  How To Install JDK on Windows
Step 0: Un-Install Older Version(s) of JDK/JRE

I recommend that you install only the latest JDK. Although you can install multiple versions of JDK/JRE concurrently, it is messy.

If you have previously installed older version(s) of JDK/JRE, un-install ALL of them. Goto “Control Panel” ⇒ (optional) “Programs” ⇒ “Programs and Features” ⇒ Un-install ALL programs begin with “Java”, such as “Java SE Development Kit …”, “Java SE Runtime …”, “Java X Update …”, and etc.

Step 1: Download JDK
  1. Goto Java SE download site @ http://www.oracle.com/technetwork/java/javase/downloads/index.html.
  2. Under “Java Platform, Standard Edition” ⇒ “Java SE 13.0.{x}”, where {x} denotes a fast running security-update number ⇒ Click the “Oracle JDK Download” button.
  3. Under “Java SE Development Kit 13.0.{x}” ⇒ Check “Accept License Agreement”.
  4. Choose the JDK for your operating system, i.e., “Windows”. Download the “exe” installer (e.g., “jdk-13.0.{x}_windows-x64_bin.exe” – about 159MB).
Step 2: Install JDK

Run the downloaded installer (e.g., “jdk-13.0.{x}_windows-x64_bin.exe“), which installs both the JDK and JRE.

By default, JDK is installed in directory “C:\Program Files\Java\jdk-13.0.{x}“, where {x} denotes the update number. Accept the defaults and follow the screen instructions to install JDK.

Use your “File Explorer”, navigate to "C:\Program Files\Java" to inspect the sub-directories. Take note of your JDK installed directory jdk-13.0.{x}, in particular, the update number {x}, which you will need in the next step.

I shall refer to the JDK installed directory as <JAVA_HOME>, hereafter, in this article.

Step 3: Include JDK’s “bin” Directory in the PATH

Windows’ Command Prompt (CMD) searches the current directory and the directories listed in the PATH environment variable (or system variable) for executable programs. JDK’s programs (such as Java compiler "javac.exe” and Java runtime "java.exe“) reside in the sub-directory “bin” of the JDK installed directory. You need to include JDK’s “bin” in the PATH to run the JDK programs.

To edit the PATH environment variable in Windows 10:

  1. Launch “Control Panel” ⇒ (Optional) “System and Security” ⇒ “System” ⇒ Click “Advanced system settings” on the left pane.
  2. Switch to “Advanced” tab ⇒ Click “Environment Variables” button.
  3. Under “System Variables” (the bottom pane), scroll down to select variable “Path” ⇒ Click “Edit…”.
  4. For Newer Windows 10:
    You shall see a TABLE listing all the existing PATH entries (if not, goto next step). Click “New” ⇒ Click “Browse” and navigate to your JDK’s “bin” directory, i.e., “c:\Program Files\Java\jdk-13.0.{x}\bin“, where {x} is your installation update number ⇒ Select “Move Up” to move this entry all the way to the TOP.
  5. For Older Windows 10 (Time to change your computer!):
    (CAUTION: Read this paragraph 3 times before doing this step! Don’t push “Apply” or “OK” until you are 101% sure. There is no UNDO!!!)
    (To be SAFE, copy the content of the “Variable value” to Notepad before changing it!!!)
    In “Variable value” field, APPEND “c:\Program Files\Java\jdk-13.0.{x}\bin” (where {x} is your installation update number) IN FRONT of all the existing directories, followed by a semi-colon (;) to separate the JDK’s bin directory from the rest of the existing directories. DO NOT DELETE any existing entries; otherwise, some existing applications may not run.Variable name : PATH Variable value : c:\Program Files\Java\jdk-13.0.{x}\bin;[do not delete exiting entries…]

Note: If you have started CMD, you need to re-start for the new environment settings to take effect.

Step 4: Verify the JDK Installation

Launch a CMD via one of the following means:

  1. Click “Search” button ⇒ Type “cmd” ⇒ Choose “Command Prompt”, or
  2. Right-click “Start” button ⇒ run… ⇒ enter “cmd”, or
  3. Click “Start” button ⇒ Windows System ⇒ Command Prompt

Issue the following commands to verify your JDK installation:

  1. Issue “path” command to list the contents of the PATH environment variable. Check to make sure that your JDK’s “bin” is listed in the PATH.path PATH=c:\Program Files\Java\jdk-13.0.{x}\bin;other entries…
  2. Issue the following commands to verify that JDK/JRE are properly installed and display their version:// Display the JDK version javac -version javac 13.0.1 // Display the JRE version java -version java version “13.0.1” 2019-10-15 Java(TM) SE Runtime Environment (build 13.0.1+9) Java HotSpot(TM) 64-Bit Server VM (build 13.0.1+9, mixed mode, sharing)
Step 5: Write a Hello-World Java Program
  1. Create a directory to keep your works, e.g., “d:\myProject” or “c:\myProject“. Do NOT save your works in “Desktop” or “Documents” as they are hard to locate. The directory name shall not contain blank or special characters. Use meaningful but short name as it is easier to type.
  2. Launch a programming text editor (such as TextPadNotePad++, Sublime Text, Atom). Begin with a new file and enter the following source code. Save the file as “Hello.java“, under your work directory (e.g., d:\myProject)./* * First Java program to say Hello */ public class Hello { // Save as “Hello.java” under “d:\myProject” public static void main(String[] args) { System.out.println(“Hello, world!”); } }
Step 6: Compile and Run the Hello-World Java Program
JavaBasics_GettingStarted.png

To compile the source code “Hello.java“:

  1. Start a CMD Shell (Search ⇒ enter “cmd” ⇒ select “Command Prompt”).
  2. Set the Current Drive to the drive where you saved your source file “Hello.java“.
    If you use drive “c”, skip this step.
    Else if you use drive “d“, enter “d:” as follow:d: D:\xxx>
  3. Set the Current Working Directory to the directory that you saved your source file via the cd (Change Directory) command. For example, suppose that your source file is saved in directory “myProject“.
    cd \myProject D:\myProject>
  4. Issue a dir (List Directory) command to confirm that your source file is present in the current directory.dir …… xx-xxx-xx xx:xx PM 277 Hello.java ……
  5. Invoke the JDK compiler “javac” to compile the source code “Hello.java“.javac Hello.java // If error message appears, correct your source code and re-compileThe compilation is successful if the command prompt returns. Otherwise, error messages would be shown. Correct the errors in your source file and re-compile. Check “Common JDK Installation Errors“, if you encounter problem compiling your program.
  6. The output of the compilation is a Java class called “Hello.class“. Issue a dir (List Directory) command again to check for the output.dir …… xx-xxx-xx xx:xx PM 416 Hello.class xx-xxx-xx xx:xx PM 277 Hello.java ……

To run the program, invoke the Java Runtime “java“:

java Hello
Hello, world!

Everything that can possibly go wrong will go wrong: Read “JDK Installation Common Errors“.

Step 7: (For Advanced Users Only) JDK’s Source Code

Source code for JDK is provided and kept in “<JAVA_HOME>\lib\src.zip” (or “<JAVA_HOME>\src.zip” prior to JDK 9). I strongly recommend that you to go through some of the source files such as “String.java“, “Math.java“, and “Integer.java“, under “java\lang“, to learn how experts program.

]]>
181
I- Java https://bhtinstitute.com/knowhow/?p=172&utm_source=rss&utm_medium=rss&utm_campaign=java Fri, 04 Dec 2020 09:21:34 +0000 http://bhtinstitute.com/knowhow/?p=172 Let us see a brief history of Java.

History 

Java is a programming language developed by James Gosling with other team members named Mike Sheridan and Patrick Naughton also called as Green Team in 1995 for Sun Microsystems for digital devices such as set-top boxes, televisions etc. Now, let us explore the language in detail.

What is Java?

It is an object-oriented language similar to C++, but with advanced and simplified features.This language is free to access and can run on all platforms.

Java Definition - What is Java - Edureka

Java is: –

  • Concurrent where you can execute many statements instead of sequentially executing it.
  • Class-based and an object-oriented programming language.
  • Independent programming language that follows the logic of “Write once, Run anywhere” i.e. the compiled code can run on all platforms which supports java.

In simple words, it is a computing platform where you can develop applications.

You may go through this session where our Certification Training expert has explained the topics in a detailed manner with examples which will help you to understand the concepts better.

]]>
172