Home > Java > javaTutorial > Java Foundation

Java Foundation

Barbara Streisand
Release: 2025-01-10 09:24:42
Original
885 people have browsed it

Java Foundation

What is Java

Java is a high-level, object-oriented, and platform-independent programming language. It is widely used for building web applications, mobile applications, enterprise software, and more. Its "write once, run anywhere" capability is powered by the Java Virtual Machine (JVM).


Key Characteristics of Java

  • Platform Independence: Code written in Java can run on any platform with a JVM.
  • Object-Oriented: It uses concepts like classes, inheritance, and polymorphism to structure programs.
  • Robustness: Strong memory management and exception handling make Java less prone to crashes.
  • Security: Features like a security manager and bytecode verification ensure secure execution.
  • Multithreading: Java supports concurrent programming to run multiple tasks simultaneously.
  • Rich Libraries: Extensive standard libraries for networking, file handling, and more.

JVM (Java Virtual Machine)

The JVM is a runtime environment that executes Java bytecode, making Java platform-independent. It interprets or compiles bytecode into machine code specific to the host system. It also handles memory management, garbage collection, and security checks.


JDK (Java Development Kit)

The JDK is a software development environment that provides tools for developing, debugging, and running Java applications. It includes the Java Compiler (javac), libraries, and the JRE (Java Runtime Environment).


Java Compiler (javac) and How It Works

The javac compiler translates Java source code (files with .java extension) into bytecode (files with .class extension). Bytecode is an intermediate, platform-independent representation of the program, which is then executed by the JVM.


JRE (Java Runtime Environment)

The JRE provides the libraries, JVM, and other components necessary to run Java applications. It does not include development tools like the compiler. It is intended solely for end-users who want to execute Java programs.

Variables

In Java, a variable is a container for storing data that can be used and manipulated within a program. Each variable has a type that defines the kind of data it can hold.

Example:

int age = 25; // An integer variable
String name = "John"; // A string variable
Copy after login
Copy after login

Data Types

Data types define the type of data that a variable can store. Java is statically typed, so each variable must be declared with a data type.

Common Data Types:

Primitive: int, double, boolean, char, etc.
Non-Primitive: String, arrays, objects, etc.

Example:

int age = 25; // An integer variable
String name = "John"; // A string variable
Copy after login
Copy after login

Concatenation

Concatenation in Java is the process of joining two or more strings or combining strings with other data types. The operator is commonly used for this purpose.

Example:

int number = 10; // Integer
double price = 19.99; // Decimal number
boolean isAvailable = true; // Boolean
char grade = 'A'; // Character
Copy after login

Constants

Constants are variables whose values cannot be changed once assigned. In Java, the final keyword is used to declare constants.

Example:

String firstName = "Jane";
String lastName = "Doe";
String fullName = firstName + " " + lastName; // "Jane Doe"

int age = 30;
String message = "Age: " + age; // "Age: 30"
Copy after login

Summary Example

final double PI = 3.14159;
final String WELCOME_MESSAGE = "Welcome to Java Programming";

// Uncommenting the line below will cause an error
// PI = 3.14;
Copy after login

The above is the detailed content of Java Foundation. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template