Java Documentation

Introduction to Java

HELLO WORLD

Welcome to the world of Java programming!

Programming languages enable humans to write instructions that a computer can perform. With precise instructions, computers coordinate applications and systems that run the modern world.

Sun Microsystems released the Java programming language in 1995. Java is known for being simple, portable, secure, and robust. Though it was released over twenty years ago, Java remains one of the most popular programming languages today.

One reason people love Java is the Java Virtual Machine, which ensures the same Java code can be run on different operating systems and platforms. Sun Microsystems’ slogan for Java was “write once, run everywhere”.

Programming languages are composed of syntax, the specific instructions which Java understands. We write syntax in files to create programs, which are executed by the computer to perform the desired task.

Let’s start with the universal greeting for a programming language. We’ll explore the syntax in the next exercise.


  • You’re looking at a computer program written in Java. Run the code in the text editor to see what is printed to the screen.
public class HelloWorld {
  public static void main(String[] args) {
    System.out.println("Hello World!");
  }
}
Java Projects

Database Connection

Java – MySQL Database Connection

package <1. type your package name>;


import java.sql.Connection;
import java.sql.DriverManager;
import javax.swing.JOptionPane;
import java.sql.*;

public class databaseConnection {
    
  
    final static String JDBC_DRIVER = "com.mysql.jdbc.Driver";
    final static String DB_URL = "jdbc:mysql://localhost:3306/<2. add your database name>;
    
    final static String USER = "<3.username of the server (username of localhost)>";
    final static String PASS ="<4. password of the server>";
    
    public static Connection connection(){
        
        try {
            Class.forName(JDBC_DRIVER);
            
            Connection conn = DriverManager.getConnection(DB_URL, USER, PASS);
            return conn;
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e);
        }
            return null;
    }
}

  • First Create the class call “databaseConnection”
  • Then Copy the code
  • Fill the steps 1 to 4
    • <1. type your package name>
    • <2. add your database name>
    • <3.username of the server (username of localhost)>
    • <4. password of the server>

Then we have to add below libraries,