Integrated Development Environment (IDE)
Eclipse is like a powerful toolbox for programmers, often used for Java development. It helps in writing and fixing code, managing projects, and more. Eclipse is popular because it supports many languages through plugins and is excellent for creating desktop applications, web applications, and even cloud-based software.
In simple terms, it’s a versatile tool that makes a programmer’s job easier.
Link to download: Click Here
Reference Link: Watch Here
Overview of IDE:
To create a new Java project in Eclipse, follow these steps:
1. Open Eclipse: After downloading and installing Eclipse, launch the IDE.
2. Click on File: In the top menu bar, click on the File option.
3. Select New: From the dropdown, hover over New.
4. Click on Java Project: In the submenu that appears, click on Java Project.
5. Enter Project Name: In the “New Java Project” dialog box, enter the name of your project.
6. Configure Project Settings (Optional):
Use default location: Leave this checked to store the project in the default Eclipse workspace.
JRE: Select the Java Runtime Environment (JRE) version you want to use.
Project layout: Choose the project structure (typically, use the default setting).
7. Click Finish: After configuring, click Finish to create your new Java project.
You can now start adding classes, methods, and other elements to your Java project.
If you’ve created a project named Hello in Eclipse, and now want to add code by clicking on the src folder, follow these steps:
- Locate the src Folder:
- In the Package Explorer on the left side of the Eclipse window, expand your Hello project by clicking the small triangle next to the project name.
- You will see a folder named src. This is where you add your Java code.
- Add a New Class:
- Right-click on the src folder.
From the context menu, select New > Class.
3. Enter Class Details:
In the dialog box that appears, enter a name for your class (e.g., Main).
Optionally, you can check the box that says public static void main(String[] args) to automatically create the main method.
4. Click Finish:
Once you’ve named your class, click Finish.
5. Write Code:
The new class will open in the editor, and you can add your code inside the main method. For example:
public class Main {
public static void main(String[] args) {
System.out.println(“Hello, World!”);
}
}
6. Run Your Program:
To run the program, right-click on the Main.java file or anywhere in the code editor and select Run As > Java Application.
Most Commonly Used Java Packages
Here are some commonly used Java packages that are essential for most Java applications
You just need to import them to use it:
- java.lang: This is automatically imported in every Java program and contains essential classes like:
- String
- Math
- Integer
- System
- java.util: This package contains utility classes and collections like:
- ArrayList, HashMap, HashSet, LinkedList
- Date, Calendar
- Random
- Scanner
- java.io: For input and output operations, such as:
- File, FileReader, FileWriter
- BufferedReader, BufferedWriter
- InputStream, OutputStream
- java.nio: For more advanced file handling and network I/O operations:
- FileChannel, ByteBuffer
- Path, Files
- java.sql: Provides classes for database operations, like:
- Connection
- Statement, PreparedStatement
- ResultSet
- javax.swing: For creating graphical user interfaces (GUIs):
- JFrame, JPanel, JButton
- JTextField, JLabel
- java.net: For network programming:
- URL, HttpURLConnection
- Socket, ServerSocket
- java.math: For performing precise mathematical operations:
- BigInteger
- BigDecimal
Typical Java Program
Java program execution starts from the main method.
Code is written inside classes.
Methods/Functions are used to define actions.
// Importing necessary classes
public class Person {
// Fields
public String name;
public int age;
// Method to introduce the person
public void introduce() {
System.out.println(“Hi, I’m ” + name + ” and I’m ” + age + ” years old.”);
}
// Main method to execute the program
public static void main(String[] args) {
// Creating an object of the Person class
Person person = new Person();
person.name = “John”;
person.age = 25;
person.introduce();
}
}