GETTING STARTED WITH JAVA In this section, you will explore the salient features of java, how to install Java Development Kit and write a sample java code
TOP FEATURES OF JAVA Simple Object-Oriented Platform independent Secured Robust - Automatic garbage collection Multithreaded
OBJECT-ORIENTED Object-Oriented Programming (OOP) is a way of designing and writing programs where real-world things are represented as objects in the code. These objects have two key features: Properties (data): What the object has or knows. Example : A car has a color, brand, and model. Behaviors (methods): What the object can do. Example : A car can start and stop. The main idea of OOP is to group related data and actions into a single unit (an object), making the code more organized and reusable
WHY IT’S PLATFORM-INDEPENDENT You only need to write and compile your Java program once. The bytecode can run on any device or operating system that has a JVM installed
MULTITHREADED Thread : A lightweight unit of a process. Think of it as a small task within a larger program. Multithreading: Running multiple threads at once to improve performance, especially for tasks like downloading files, processing data, or updating a UI.
JDK (Java Development Kit) What it is : A complete package for Java development. It includes tools needed to write, compile, and debug Java programs. What it contains : JRE (Java Runtime Environment): For running Java programs . Compiler (javac): Converts Java code into bytecode . Development tools: Debuggers and other utilities. Use : You need JDK to write and develop Java applications.
JRE (JAVA RUNTIME ENVIRONMENT) What it is : The environment required to run Java programs. It contains all the necessary libraries and files for executing Java applications. What it contains: JVM : Runs the Java bytecode. Libraries and APIs: Pre-built code for tasks like input/output and networking .
JVM (Java Virtual Machine) What it is: The engine that runs Java bytecode. It converts bytecode into machine-specific code (instructions your computer understands). What it does: Loads, verifies, and executes Java bytecode.Handles memory management (e.g., garbage collection). Use: JVM is part of the JRE and is responsible for running Java applications on any device or platform.
HOW TO DOWNLOAD JDK
SIMPLE "HELLO WORLD" PROGRAM IN JAVA public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); } }
public class HelloWorld What it is: Declares a class named HelloWorld. In Java, every program must have at least one class . CLASS : A class in Java is a blueprint or template that defines how objects (instances) are created and what properties (fields) and behaviors (methods) they have . public : Makes the class accessible from anywhere .
public static void main(String[] args) This is the main method, where the program starts execution. public : Allows the method to be accessible from anywhere. static : The method can run without creating an instance of the class. void : Means the method doesn’t return anything. String[] args : An array of strings that holds command-line arguments. It can be empty if no arguments are passed.
System.out.println("Hello, World!"); What it does : Prints the text Hello, World! to the console, followed by a new line. println : A method of PrintStream that prints the given text and moves to the next line.
TASK A coffee shop wants to display the message " Thank you for your order " on the screen for the customers who have placed their orders. Write a Java program to print that message. Note : In the Sample Input / Output provided, the highlighted text in bold corresponds to the input given by the user, and the rest of the text represents the output. Adhere to the code template, if provided . Sample Input /Output : Thank you for your order
DATA TYPES In Java, data types specify the type of data that a variable can store. They define what kind of value a variable can hold (e.g., a number, a character, or a boolean).
Variable Naming Rules in Java 1) Start with a Letter, Underscore, or Dollar Sign Example : int age; String _name; double $price;
2) Subsequent Characters Can Be Letters, Digits, Underscore, or Dollar Sign Example: int student2; String full_name; double $amount ;
3) Cannot Start with a Number Example : Incorrect Example : int 2ndPlace; is invalid . Correct Example : int secondPlace; is valid . 4) No Reserved Keywords Example : Incorrect Example : int class = 5; is invalid. Correct Example : int studentClass = 5; is valid .
5) Case Sensitive Example: int student; and int Student; are different variables .
Naming Conventions (Best Practices ) While these aren't strict rules, following naming conventions makes your code more readable and maintainable. Use Descriptive Names : Example : int totalAmount ; instead of int a ; . Camel Case for Variable Names : Example : int totalAmount; String firstName;
Naming Conventions (Best Practices ) Avoid Using Underscores in Variable Names (Except for constants): Example: int totalAmount; (for normal variables) final int MAX_SIZE = 100; (for constants ) Use Meaningful Abbreviations : Example : int numItems instead of int nI .