What is Java? Computer notes by home academy

 

What is Java?

  • Java is a high-level, object-oriented, class-based programming language.

  • Developed by James Gosling at Sun Microsystems in 1995.

  • Java follows the principle: “Write Once, Run Anywhere” (WORA).


📌 Key Features of Java

FeatureDescription
Platform IndependentRuns on JVM (Java Virtual Machine)
Object-OrientedBased on objects, classes, and inheritance
Simple & SecureEasy to learn with secure memory management
Robust & ReliableStrong exception handling
MultithreadedSupports concurrent execution
PortableRuns on any OS with JVM
Compiled + InterpretedUses both compiler and interpreter

🧱 Structure of a Java Program

java
public class Hello { public static void main(String[] args) { System.out.println("Hello, Java!"); } }

🔍 Explanation:

  • class Hello – Declares a class

  • main() – Entry point of any Java program

  • System.out.println() – Prints output to console


📚 Basic Concepts

1. Data Types

java
int age = 25; float marks = 87.5f; char grade = 'A'; boolean isPassed = true; String name = "Afzal";

2. Operators

java
+ - * / % // Arithmetic == != > < >= <= // Relational && || ! // Logical = += -= *= /= // Assignment

🔁 Control Statements

If-else

java
if (age >= 18) { System.out.println("Adult"); } else { System.out.println("Minor"); }

Switch

java
switch (day) { case 1: System.out.println("Monday"); break; default: System.out.println("Other"); }

Loops

java
for(int i = 0; i < 5; i++) { System.out.println(i); } int i = 0; while(i < 5) { System.out.println(i); i++; }

🔤 Functions (Methods)

java
public static int add(int a, int b) { return a + b; }

🧠 Object-Oriented Concepts

ConceptDescription
ClassBlueprint for creating objects
ObjectInstance of a class
InheritanceOne class inherits another
PolymorphismSame name, different behaviors
EncapsulationWrapping data and code together
AbstractionHiding internal implementation

Example of Class & Object:

java
class Car { String brand = "BMW"; void show() { System.out.println(brand); } } public class Main { public static void main(String[] args) { Car c = new Car(); c.show(); // Output: BMW } }

📦 Packages and Import

java
import java.util.Scanner; Scanner sc = new Scanner(System.in);

🔐 Exception Handling

java
try { int result = 10 / 0; } catch (ArithmeticException e) { System.out.println("Cannot divide by zero"); }

🧩 Arrays and Strings

Arrays

java
int[] nums = {1, 2, 3}; System.out.println(nums[0]);

Strings

java
String name = "Java"; System.out.println(name.length());

🌍 Practical Applications of Java

AreaExamples
Web ApplicationsSpring, JSP
Mobile AppsAndroid development
Desktop SoftwareSwing, JavaFX
Enterprise AppsBanking systems
Game Development2D/3D games
Embedded SystemsSmart devices

Frequently Asked MCQs

  1. Who developed Java?
    a) Brendan Eich
    b) Bjarne Stroustrup
    c) James Gosling ✅
    d) Dennis Ritchie

  2. Which of these is not a Java keyword?
    a) class
    b) public
    c) integer ✅
    d) static

  3. Java is:
    a) Compiled only
    b) Interpreted only
    c) Both compiled and interpreted ✅
    d) None

  4. Which method is the entry point of a Java program?
    a) start()
    b) init()
    c) main() ✅
    d) run()

  5. Which keyword is used to inherit a class in Java?
    a) implements
    b) extends ✅
    c) include
    d) inherit


📌 Important Points for Exams

  • .java is the source file, .class is the compiled bytecode.

  • Java uses automatic garbage collection.

  • JDK = Java Development Kit (contains JRE + compiler)

  • JRE = Java Runtime Environment

  • JVM = Java Virtual Machine (executes bytecode)


📝 Conclusion

Java is one of the most powerful, secure, and scalable languages, widely used for enterprise, Android, and web development. It’s essential for OOP, backend programming, and job interviews.

homeacademy

Home academy is JK's First e-learning platform started by Er. Afzal Malik For Competitive examination and Academics K12. We have true desire to serve to society by way of making educational content easy . We are expertise in STEM We conduct workshops in schools Deals with Science Engineering Projects . We also Write Thesis for your Research Work in Physics Chemistry Biology Mechanical engineering Robotics Nanotechnology Material Science Industrial Engineering Spectroscopy Automotive technology ,We write Content For Coaching Centers also infohomeacademy786@gmail.com

إرسال تعليق (0)
أحدث أقدم