Java Introduction BSC - It
Java Introduction BSC - It
Java Introduction BSC - It
Getting Started with Java: To start programming in Java, you need to set up a
development environment. Here’s a basic overview of the steps:
1. Install Java Development Kit (JDK): JDK includes the Java compiler
(javac) and other tools needed for Java development. You can download it
from Oracle's website or use OpenJDK, which is an open-source alternative.
2. Set Up an Integrated Development Environment (IDE): IDEs like
Eclipse, IntelliJ IDEA, or NetBeans provide a user-friendly environment for
writing, compiling, and debugging Java programs. Choose one and install it
on your computer.
3. Write Your First Java Program: Here's a simple "Hello, World!" program
in Java to get started:
java
Copy code
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Getting Started with JavaScript: To start programming in JavaScript, you only need a web
browser and a text editor. Here’s a simple example to get you started:
1. Write Your First JavaScript Program: Create an HTML file (index.html) and add
the following code:
html
Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My First JavaScript Program</title>
</head>
<body>
<h1>JavaScript Example</h1>
<script>
// JavaScript code goes here
alert('Hello, World!');
</script>
</body>
</html>
1. Objects:
Example:
java
Copy code
// Define a class
public class Car {
// Attributes (instance variables)
private String brand;
private int year;
// Constructor
public Car(String brand, int year) {
this.brand = brand;
this.year = year;
}
// Method
public void displayInfo() {
System.out.println("Car brand: " + brand
+ ", Year: " + year);
}
2. Classes:
Classes are blueprints or templates for creating objects. They define the
properties (attributes) and behaviors (methods) that objects of that class
will have.
Example:
java
Copy code
public class Car {
// Attributes
private String brand;
private int year;
// Constructor
public Car(String brand, int year) {
this.brand = brand;
this.year = year;
}
// Method
public void displayInfo() {
System.out.println("Car brand: " + brand
+ ", Year: " + year);
}
3. Encapsulation:
Example:
java
Copy code
public class Car {
// Private attributes
private String brand;
private int year;
// Constructor
public Car(String brand, int year) {
this.brand = brand;
this.year = year;
}
// Method
public void displayInfo() {
System.out.println("Car brand: " + brand
+ ", Year: " + year);
}
4. Inheritance:
Example:
java
Copy code
// Parent class
public class Vehicle {
// Method
public void start() {
System.out.println("Vehicle is
starting...");
}
}
5. Polymorphism:
// Child class 1
public class Car extends Vehicle {
// Method overriding
@Override
public void start() {
System.out.println("Car is
starting...");
}
}
// Child class 2
public class Motorcycle extends Vehicle {
// Method overriding
@Override
public void start() {
System.out.println("Motorcycle is
starting...");
}
6. Abstraction:
Example:
java
Copy code
// Abstract class with an abstract method
public abstract class Vehicle {
// Abstract method (no implementation)
public abstract void start();
}
3.5