Makindo Medical Notes.com |
|
---|---|
Download all this content in the Apps now Android App and Apple iPhone/Pad App | |
MEDICAL DISCLAIMER:The contents are under continuing development and improvements and despite all efforts may contain errors of omission or fact. This is not to be used for the assessment, diagnosis or management of patients. It should not be regarded as medical advice by healthcare workers or laypeople. It is for educational purposes only. Please adhere to your local protocols. Use the BNF for drug information. If you are unwell please seek urgent healthcare advice. If you do not accept this then please do not use the website. Makindo Ltd |
Java is a high-level, class-based, object-oriented programming language that is designed to have as few implementation dependencies as possible. It is widely used for building enterprise-scale applications, web applications, and Android apps. Java's platform independence, strong memory management, and robustness make it a popular choice for developers.
// This is a single-line comment
/* This is a multi-line comment spanning multiple lines */
/** * This is a documentation comment * It can be used to generate documentation */
public class Main { public static void main(String[] args) { System.out.println("Hello, World!"); } }
int age = 25; float height = 5.9f; double pi = 3.14159; char initial = 'A'; boolean isActive = true;
if (age > 18) { System.out.println("Adult"); } else { System.out.println("Minor"); }
switch (initial) { case 'A': System.out.println("Grade A"); break; case 'B': System.out.println("Grade B"); break; default: System.out.println("Other Grade"); }
for (int i = 0; i < 5; i++) { System.out.println(i); } int j = 0; while (j < 5) { System.out.println(j); j++; } int k = 0; do { System.out.println(k); k++; } while (k < 5);
public static int add(int a, int b) { return a + b; } public static void main(String[] args) { int sum = add(5, 3); System.out.println("Sum: " + sum); }
public static void greet() { System.out.println("Hello, World!"); } public static void main(String[] args) { greet(); }
class Dog { String name; int age; Dog(String name, int age) { this.name = name; this.age = age; } void bark() { System.out.println(name + " says woof!"); } } public class Main { public static void main(String[] args) { Dog myDog = new Dog("Buddy", 3); myDog.bark(); } }
class Animal { String name; void speak() { System.out.println("Animal speaks"); } } class Dog extends Animal { void speak() { System.out.println(name + " says woof!"); } } public class Main { public static void main(String[] args) { Dog myDog = new Dog(); myDog.name = "Buddy"; myDog.speak(); } }
class Animal { void speak() { System.out.println("Animal speaks"); } } class Dog extends Animal { void speak() { System.out.println("Dog barks"); } } class Cat extends Animal { void speak() { System.out.println("Cat meows"); } } public class Main { public static void main(String[] args) { Animal myDog = new Dog(); Animal myCat = new Cat(); myDog.speak(); // Output: Dog barks myCat.speak(); // Output: Cat meows } }
interface Animal { void speak(); } class Dog implements Animal { public void speak() { System.out.println("Dog barks"); } } class Cat implements Animal { public void speak() { System.out.println("Cat meows"); } } public class Main { public static void main(String[] args) { Animal myDog = new Dog(); Animal myCat = new Cat(); myDog.speak(); // Output: Dog barks myCat.speak(); // Output: Cat meows } }
abstract class Animal { abstract void speak(); } class Dog extends Animal { void speak() { System.out.println("Dog barks"); } } class Cat extends Animal { void speak() { System.out.println("Cat meows"); } } public class Main { public static void main(String[] args) { Animal myDog = new Dog(); Animal myCat = new Cat(); myDog.speak(); // Output: Dog barks myCat.speak(); // Output: Cat meows } }
try { int result = 10 / 0; } catch (ArithmeticException e) { System.out.println("Cannot divide by zero!"); }
try { int result = 10 / 0; } catch (ArithmeticException e) { System.out.println("Cannot divide by zero!"); } finally { System.out.println("This will always be printed"); }
import java.util.ArrayList; import java.util.List; public class Main { public static void main(String[] args) { Listfruits = new ArrayList<>(); fruits.add("Apple"); fruits.add("Banana"); fruits.add("Cherry"); System.out.println(fruits.get(0)); // Output: Apple } }
import java.util.HashSet; import java.util.Set; public class Main { public static void main(String[] args) { SetuniqueNumbers = new HashSet<>(); uniqueNumbers.add("One"); uniqueNumbers.add("Two"); uniqueNumbers.add("Two"); // Duplicate entry System.out.println(uniqueNumbers); // Output: [One, Two] } }
import java.util.HashMap; import java.util.Map; public class Main { public static void main(String[] args) { Mapages = new HashMap<>(); ages.put("Alice", 30); ages.put("Bob", 25); System.out.println(ages.get("Alice")); // Output: 30 } }
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class Main { public static void main(String[] args) { try (BufferedReader reader = new BufferedReader(new FileReader("example.txt"))) { String line; while ((line = reader.readLine()) != null) { System.out.println(line); } } catch (IOException e) { e.printStackTrace(); } } }
import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; public class Main { public static void main(String[] args) { try (BufferedWriter writer = new BufferedWriter(new FileWriter("example.txt"))) { writer.write("Hello, World!"); } catch (IOException e) { e.printStackTrace(); } } }
Java is a versatile and widely-used programming language that supports object-oriented programming. Understanding its basic syntax, control structures, functions (methods), object-oriented principles, collections framework, file I/O, and standard libraries is essential for developing robust and efficient applications. Java's platform independence and extensive standard libraries make it a popular choice for building a wide range of applications.