- Concepts: Learn about JDK, its installation, environment setup, and IDE usage.
- Practice: Verify JDK installation, create and run a Java program in IntelliJ IDEA, and set up a project structure.
- Installing Java JDK
- Explanation of JDK and its importance
- Java Development Kit (JDK): A software development environment used for developing Java applications.
- Importance: Provides the necessary tools (compiler, debugger, etc.) to write, compile, and run Java programs.
- Steps to download and install JDK from Oracle’s website
- Open a web browser and go to the Oracle JDK download page.
- Select the appropriate version for your operating system (Windows, macOS, Linux).
- Download the installer and run it.
- Follow the installation prompts to complete the installation.
- Setting up environment variables (JAVA_HOME, PATH)
- Windows:
- Open the Start menu, search for "Environment Variables", and select "Edit the system environment variables".
- In the System Properties window, click on "Environment Variables".
- Under System Variables, click "New" and add
JAVA_HOMEwith the path to the JDK installation directory (e.g.,C:\Program Files\Java\jdk-14). - Find the
Pathvariable, click "Edit", and add%JAVA_HOME%\binto the list.
- macOS/Linux:
-
Open the terminal.
-
Edit the
.bash_profileor.zshrcfile using a text editor (e.g.,nano ~/.bash_profile). -
Add the following lines:
export JAVA_HOME=/path/to/jdk export PATH=$JAVA_HOME/bin:$PATH
-
Save the file and run
source ~/.bash_profileorsource ~/.zshrc.
-
- Windows:
- Explanation of JDK and its importance
- Installing an IDE (IntelliJ IDEA)
- Explanation of IDE and why we use it
- Integrated Development Environment (IDE): A software application that provides comprehensive facilities to computer programmers for software development.
- Importance: Simplifies coding, debugging, and testing by providing tools and features like code editors, compilers, debuggers, and project management.
- Steps to download and install IntelliJ IDEA
- Open a web browser and go to the IntelliJ IDEA download page.
- Select the Community Edition (free) for your operating system (Windows, macOS or Linux).
- Download the installer and run it.
- Follow the installation prompts to complete the installation.
- Basic tour of the IDE interface: projects, editors, menus
- Projects: Contains the files and folders of your Java project.
- Editors: Where you write and edit your Java code.
- Menus: Provides access to various tools and settings, such as file management, code navigation, refactoring, and debugging.
- Explanation of IDE and why we use it
- Verify JDK installation by compiling and running a simple Java program via command line.
-
Open a text editor and write a simple Java program:
public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); } }
-
Save the file as
HelloWorld.java. -
Open a command line terminal.
-
Navigate to the directory where you saved
HelloWorld.java. -
Compile the program using
javac HelloWorld.java. -
Run the program using
java HelloWorld.
-
- Create and run a "Hello World" program in IntelliJ IDEA.
-
Open IntelliJ IDEA.
-
Create a new Java project.
-
In the project structure, right-click on
srcand selectNew -> Java Class. -
Name the class
HelloWorld. -
Write the "Hello World" program in the editor:
public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); } }
-
Run the program by clicking the Run button or right-clicking in the editor and selecting
Run 'HelloWorld.main()'.
-
- Set up a project structure in IntelliJ IDEA.
-
Create a new project in IntelliJ IDEA.
-
Familiarize yourself with the project structure:
srcfolder for source files,outorbuildfolder for compiled files. -
Add a package within the
srcfolder (right-clicksrc-> New -> Package). -
Create a new Java class within the package (right-click package -> New -> Java Class).
-
Write a simple Java program and run it to ensure everything is set up correctly.
- In the editor, replace the default code with the following:
package com.example; public class Main { public static void main(String[] args) { System.out.println("Hello, IntelliJ IDEA!"); } }
-