Skip to content

Java

cotrVarBool

Java Create Boolean Variable

boolean ${1:myBool} = ${2:true};

cotrConst

Java Create Constant

final ${1:Type} ${2:myConst} = ${3:value};

cotrGenMap

Java Generate Map

Map<${1:Key}, ${2:Value}> ${3:myMap} = IntStream.range(0, ${4:length}).boxed().collect(Collectors.toMap(i -> ${5:key}, i -> ${6:value}));

cotrFuncSyntax

Java Function Syntax

// Java Function Syntax
// Basic function: public returnType functionName(parameters) { ... }
// Function with arguments: public returnType functionName(argType argName, ...) { ... }
// Note: Java does not support named arguments in function definitions.

cotrEqual

Java Equal To

==

cotrVarNullable

Java Create Nullable Variable

${1:Type} ${2:myVar} = null;

cotrInterpolate

Java Interpolate String

String.format("${1:%s}", ${2:value})

cotrVarMultiString

Java Create Multi-Line String Variable

String ${1:myString} =
"${2:Line 1}" +
"\n${3:Line 2}" +
"\n${4:Line 3}";

cotrVarList

Java Create List Variable

List<${1:Type}> ${2:myList} = new ArrayList<>();
${2:myList}.add(${3:value});

cotrTypeConvert

Java Type Conversion

// Java Type Conversion:
// Implicit conversions (compiler performs automatically):
// - Smaller numeric types to larger numeric types (e.g., int to double).
// Explicit conversions (using casts):
// - (Type)variable // C-style cast
// Conversion methods:
// - Integer.parseInt(string) // Converts string to int
// - Double.parseDouble(string) // Converts string to double
// - ... (Various conversion methods in wrapper classes and other packages)
// Note:
// - Be cautious with explicit conversions, as they can lead to data loss or errors if the conversion is not valid.

cotrTypesNum

Java Double Type

double

cotrConcat

Java Concatenate String

${1:"String1"} + ${2:"String2"}

cotrFunc

Java Function

public ${1:void} ${2:myFunction}(${3:parameters}) {
${4:// Your code here}
}

cotrVarStatic

Java Static Variable

static ${2:Type} ${3:myStaticVar} = ${4:value};
// Access the static variable
// MyClass.${3:myStaticVar}

cotrForEachLoop

Java For Each Loop

for (${1:Type} ${2:item} : ${3:iterable}) {
${4:// Your code here}
}

cotrWhileLoop

Java While Loop

while (${1:condition}) {
${2:// Your code here}
}

cotrTypeCompare

Java Type Comparison

// Check if two variables have the same type:
if (${1:variable1}.getClass() == ${2:variable2}.getClass()) {
// Your code here
}

cotrVarDate

Java Create Date Variable

import java.time.LocalDate;
LocalDate ${1:myDate} = LocalDate.of(${2:year}, ${3:month}, ${4:day});

cotrFuncLambda

Java Lambda Function

(${1:parameters}) -> ${2:expression}

cotrVarInt

Java Create Integer Variable

int ${1:myInt} = ${2:0};

cotrFuncArgs

Java Function Args

// In Java, functions do not support default argument values in definitions.
// You can achieve similar functionality using method overloading.
public ${1:void} ${2:myFunction}(${3:type1} ${4:arg1}, ${5:type2} ${6:arg2}) {
${7:// Your code here}
}
// Overloaded method with default value for arg2
public ${1:void} ${2:myFunction}(${3:type1} ${4:arg1}) {
${5:type2} ${6:arg2} = ${8:defaultValue};
${2:myFunction}(${4:arg1}, ${6:arg2});
}

cotrTypesDate

Java Date Type

import java.time.LocalDate;

cotrFuncArgsNamed

Java Function Named Args

// Note: Java does not support named arguments in function definitions.

cotrVarTyped

Java Create Typed Variable

${1:Type} ${2:myVar} = $3;

cotrForLoop

Java For Loop

for (int ${1:i} = 0; $1 < ${2:10}; $1++) {
// Your code here
}

cotrTypesList

Java List Type

List<${1:type}>

cotrPrintMulti

Java Print Multi

System.out.println(${1:"Line 1"} +
${2:"\nLine 2"} +
${3:"\nLine 3"});

cotrClass

Java Class

public class ${1:MyClass} {
${2:// Your code here}
}

cotrIf

Java If Statement

if (${1:condition}) {
${2:// Your code here}
}

cotrStructure

Java Project Structure (High-Level)

// Recommended High-Level Java Project Structure:
// - src/
// - main/
// - java/
// - Contains all Java source files organized by package, e.g.,
// - com/example/myapp/
// - resources/
// - Contains resources such as properties files, XML configurations, etc.
// - test/
// - java/
// - Contains all Java test files organized similarly to the main source files.
// - resources/
// - Contains resources used for testing, such as test configurations.
// - lib/
// - Contains external libraries or JAR files if not using a build tool like Maven or Gradle.
// - build/ or target/
// - Contains compiled bytecode and other build artifacts. 'target' is common with Maven.
// - docs/
// - Documentation related to the project.
// - scripts/
// - Contains build scripts, utility scripts, etc.
// Build Tools:
// - For Maven projects, the pom.xml file at the root defines build configurations and dependencies.
// - For Gradle projects, the build.gradle file at the root defines build configurations and dependencies.
// Note:
// - This structure can vary depending on the build tool (Maven, Gradle, etc.) and project needs.

cotrTypesBoolFalse

Java Boolean False

false

cotrTypesBool

Java Boolean Type

boolean

cotrVar

Java Create Variable

${1:Type} ${2:myVar} = ${3:value};

cotrVarSyntax

Variable Declaration Syntax

// Java Variable Declaration Syntax:
// - type: (Scope: Block or Class)
// - Explicitly specify the variable's type.
// - Can be declared without initialization (default value is assigned).
// - final: (Scope: Block or Class)
// - Cannot be reassigned after initialization.
// - Use for values that should remain constant.
// Note:
// - Java does not have a direct equivalent to 'var' or 'let'.
// - Use explicit type declaration for all variables.
// - Use 'final' for values that should not change.

cotrVarString

Java Create String Variable

String ${1:myString} = ${2:'Your string here'};

cotrOperatorsBool

Java Boolean Operators

// Java Boolean Operators
// Logical AND: &&
// Logical OR: ||
// Logical NOT: !
// Equality: ==
// Inequality: !=
// Greater than: >
// Less than: <
// Greater than or equal to: >=
// Less than or equal to: <=

cotrTypes

Java Types

$BLOCK_COMMENT_START
Java is a statically typed language.
Types in Java include:
- int: Integer
- float: Single-precision floating-point number
- double: Double-precision floating-point number
- char: Character
- boolean: Boolean
- String: String
- int[]: Array of integers
- ArrayList<Integer>: List of integers
- HashMap<K, V>: Map with key type K and value type V
- MyCustomClass: Custom class with named fields
- enum MyEnum: Enumeration type
- void: Type representing the absence of a value
- Object: Base type of all other types
- List<T>: Interface for lists in the Collections framework
- Set<T>: Interface for sets in the Collections framework
- Map<K, V>: Interface for maps in the Collections framework
$BLOCK_COMMENT_END

cotrTypesNumAlt

Java Float Type

float

cotrComment

Java Comment

// ${1:Your comment here}

cotrDoWhileLoop

Java Do While Loop

do {
${1:// Your code here}
} while (${2:condition});

cotrSwitch

Java Switch Statement

switch (${1:variable}) {
case ${2:value1}:
${3:// Your code here}
break;
case ${4:value2}:
${5:// Your code here}
break;
default:
${6:// Your code here}
}

cotrEntry

Java Entry Point

// Java Entry Point
// To run this program, use: `java Main.java`
public class Main {
public static void main(String[] args) {
// Your code here
}
}

cotrTypesNull

Java Null Type

null

cotrTypesDynamic

Java Dynamic Type

Object

cotrVarMap

Java Create Map Variable

Map<${1:Key}, ${2:Value}> ${3:myMap} = new HashMap<>();
${3:myMap}.put(${4:key}, ${5:value});

cotrEnum

Java Enum

enum ${1:MyEnum} {
${2:value1},
${3:value2},
// Add more values here
}

cotrNotEqual

Java Not Equal To

!=

cotrTypesBoolTrue

Java Boolean True

true

cotrNow

Java Date Now

import java.time.LocalDate;
LocalDate now = LocalDate.now();

cotrTernary

Java Ternary Operator

${1:condition} ? ${2:trueValue} : ${3:falseValue}

cotrInfo

Java Info

Typing: Statically typed
Paradigm: Multi-paradigm: object-oriented, imperative, concurrent
Compilation: Compiled to bytecode, executed on the Java Virtual Machine (JVM)
Concurrency: Supports multi-threading and concurrent programming with the java.util.concurrent package

cotrTypesString

Java String Type

String

cotrTypesMap

Java Map Type

Map<${1:keyType}, ${2:valueType}>

cotrVarDouble

Java Create Double Variable

double ${1:myDouble} = ${2:0.0};

cotrTryCatch

Java Try Catch

try {
${1:// Your code here}
} catch (${2:Exception} ${3:e}) {
${4:// Your code here}
}

cotrIfElse

Java If Else Statement

if (${1:condition}) {
${2:// Your code here}
} else if (${3:condition}) {
${4:// Your code here}
} else {
${5:// Your code here}
}

cotrOperators

Java Mathematical Operators

// Java Mathematical Operators
// Addition: +
// Subtraction: -
// Multiplication: *
// Exponentiation: Math.pow(base, exponent)
// Division: /
// Modulus: %
// Increment: ++
// Decrement: --
// Assignment: =
// Addition assignment: +=
// Subtraction assignment: -=
// Multiplication assignment: *=
// Division assignment: /=
// Modulus assignment: %=

cotrPrint

Java Print

System.out.println(${1:'Your message here'});

cotrCommentMulti

Java Multi-Line Comment

/*
* ${1:Your comment here}
*/

cotrThrow

Java Throw Exception

throw new ${1:Exception}(${2:'Your message here'});

cotrTypeCheck

Java Type Check

${1:variable}.getClass()

cotrTypesInt

Java Integer Type

int

cotrFuncAnon

Java Anonymous Function

new ${1:InterfaceName}() {
@Override
public ${2:returnType} ${3:methodName}(${4:parameters}) {
${5:// Your code here}
}
}

cotrGenList

Java Generate List

List<${1:Type}> ${2:myList} = IntStream.range(0, ${3:length}).mapToObj(i -> ${4:value}).collect(Collectors.toList());

cotrFuncArrow

Java Arrow Function

(${2:parameters}) -> ${1:returnType} {
${3:// Your code here}
}