Skip to content

danielurra/java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

97 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Java

java-220x110px
Java is a computer programming language that is concurrent, class-based and object-oriented.
The advantages of object oriented software development are shown below:

  • Modular development of code, which leads to easy maintenance and modification
  • Reusability of code
  • Improved reliability and flexibility of code
  • Increased understanding of code

Object-oriented programming contains many significant features, such as:

  • Encapsulation
  • Inheritance
  • Polymorphism
  • Abstraction

java-oops

Compile and run Java code

In order to be able to compile and run Java code in your computer, Java JDK must be installed on your computer

JDK stands for "Java Development Kit"

Once you have JDK installed on your computer you can navigate to the folder where all the executable files are located

Java's Bin folder location

C:\Program Files\Java\jdk-22\bin

java-bin-folder

The first thing you'll have to do is to add the Java's bin folder path inside the system's PATH

PATH is an "environment variable" that tells the OS where to find executable files

You must use the "set path" CLI command as shown below:

set path=%path%;C:\Program Files\Java\jdk-19\bin

set-path
You can echo the variable to see if the new entry is there now

echo %PATH%

echo path

Java version

java --version

image

Java Hello World!

See below the classic "Hello World" in Java

Compile then run

We are going to use 2(two) executable files, "javac.exe" when compiling and "java.exe" when running
java.exe will invoke the java Virtual Machine in the background, totally transparent for us

Before Compilation

Compiling with javac



After Compilation
Immediately after the compilation is done, you'll see that another file was created
that file with extension ".class" is what in Java is known as "bytecode"

Running java code


JShell

Those of you who are new to Java programming, could take advantage of "JShell" which is often helpful for trying out the code snippets.
JDK 9 and above include this tool that lets you execute a snippet of Java code instead of writing a full Java program.

  • For Beginners -> Practice and Learn the syntax
  • For Developers -> Execute part of program in simple way

JShell is a Read-Evaluate-Print-Loop (REPL), which evaluates declarations, statements, and expressions as they are entered and immediately shows the results.

Launch JShell

jshell

jshell-01

Eexecute your first Java snippet of code

No semicolons needed

System.out.println("Hello JDK 19!")

jshell-02

Exit JShell

/exit

jshell-03

Eclipse IDE

Eclipse-Luna-Logo
A Package declaration is something needed when running the java Hello World code using Eclipe IDE eclipse-ide-hello-world

Declare a Variable as Integer and set a value

package package01;

public class HelloWorld {

	public static void main(String[] args) {
//		Declare and set in one line 
		Integer myfirstvar = 77;
//		 Print the value concatenated (plus sign +) with some random text for better understanding
		System.out.println("My first variable has a value of: " + myfirstvar);
	}
}

See the console

declare-and-set-in-one-line

About

Java is network-savvy or network-ready.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages