java Flashcards
java environment
is the entire ecosystem where java applications are developed ,managed and executed
components and concepts of java environment
java development kit
java runtime environment
java virtual machine
java compiler
cross path
java standard libraries
integrated development environment
java development kit
it is a package that has everything needed to develop, manage and run java applications
java runtime environment
it has the needed libraries for executing java applications
java virtual machine
it interprets and executes java bytecodes
Java Compiler
it compiles java source code to bytecode
Java Standard Library
it provide ready-made functionality for tasks
Class path
it tells the JVM where to find classes and libraries required by a Java application.
Integrated Development Environments
provide a convenient development environment for Java programmer
Case Sensitivity
meaning that it distinguishes between uppercase and lowercase letters
Operators
various operators, including arithmetic (+, -, *, /), comparison (==, ===, !=, !==, >, <), logical (&&, ||, !), and assignment (=).
class names
Java class names must start with an uppercase letter and follow the CamelCase convention (e.g., MyClass
).
. Method Names
Method names in Java start with a lowercase letter and also follow CamelCase (e.g., myMethod
).
.Variables
Java requires explicit data type declarations for variables, e.g., int myVariable = 10;
specifies that myVariable
is an integer
public static void main
Java programs start executing from a public static void main(String[] args)
method within a class. This method serves as the entry point for the program
Program File Name
the file name must match the public class name defined in that file, including capitalization (e.g., MyClass.java
for class MyClass
).
. Identifiers
must start with a letter, underscore (_), or dollar sign ($) and can be followed by letters, digits, underscores, and dollar signs.
.Arrays
Java arrays are strongly typed, meaning they can hold only elements of a specific data type. For example, you declare an integer array as int[] myArray
.
Enums
Java supports enumerated types (enums), which define a fixed set of constants or values
Java data types
integer-whole numbers
float-decimals
string-text
boolean-true or false
Java statements
statements are individual instructions that make up a Java program
Declaration Statements
Declaration statements are used to declare variables. They specify the name and data type of a variable.
int age; // Declaration statement for an integer variable named “age”
Assignment Statements
Assignment statements are used to assign values to variables.
age = 25; // Assignment statement: assigning the value 25 to the “age” variable
```
Expression Statements
- Expression statements consist of expressions that are evaluated and may produce a result. They are often used for their side effects.int result = 5 + 7; // Expression statement: calculating the sum of 5 and 7 and assigning it to “result
Conditional Statements
Conditional statements allow you to control the flow of your program based on conditions. Commonly used conditional statements include if
, else if
, and else
.
if (age >= 18) {
System.out.println(“You are an adult.”);
} else {
System.out.println(“You are a minor.”);
}
```
.Loop Statements
Loop statements are used for repetitive tasks. Java provides several loop types, including for
, while
, and do-while
.
for (int i = 0; i < 5; i++) {
System.out.println(“Iteration “ + i);
}
Switch Statement
The switch
statement is used to select one of many code blocks to be executed.
int day = 2;
switch (day) {
case 1:
System.out.println(“Monday”);
break;
Local Variables
Local variables are declared within a method, constructor, or block of code and have limited scope.
public void someMethod() {
int localVar = 10; // Declaration and initialization of a local variable
// localVar is only accessible within this method
}
```
Class Variables (Static Variables)
Class variables, also known as static variables, belong to a class rather than an instance of the class.
- They are declared using the static
keyword and are shared among all instances of the class
public class MyClass {
static int classVar = 5; // Declaration of a class variable
}
```
Instance Variables (Non-Static Variables)
Instance variables are associated with an instance of a class and are not shared among different instances.
- They are declared within a class but outside of any method or constructor.
- Each instance of the class has its own set of instance variables
public class MyClass {
int instanceVar = 10; // Declaration of an instance variable
Integer Constants
Integer constants represent whole numbers and can be of various numeric types (e.g., int
, long
, short
, byte
).
- Example:
int integerConstant = 42
Real Constants (Floating-Point Constants)
- Real constants represent numbers with a fractional part and can be of types like
float
ordouble
.
. Strings
Example:
String text = "Hello, World!";
Variable Reading
Variable reading refers to retrieving the value stored in a variable. You can read the value of a variable by simply referencing its name in expressions, conditions, or method arguments
Variable Arithmetic
Java supports various arithmetic operations on numeric variables (e.g., int
, double
, float
) for performing calculations. Common arithmetic operators include addition (+), subtraction (-), multiplication (*), division (/), and modulus (%).
Object Instantiation
In Java, objects are instances of classes, and you can create objects using a process called instantiation. To instantiate an object, you use the new
keyword followed by the class constructor