Geschreven door studenten die geslaagd zijn Direct beschikbaar na je betaling Online lezen of als PDF Verkeerd document? Gratis ruilen 4,6 TrustPilot
logo-home
College aantekeningen

Java Module 1 Part 3 Notes – OOP Concepts

Beoordeling
-
Verkocht
-
Pagina's
18
Geüpload op
18-05-2026
Geschreven in
2025/2026

The notes are written in a clear and beginner-friendly manner, making them useful for university exams, quick revision, lab preparation, viva questions, and understanding object-oriented programming concepts in Java.

Instelling
Vak

Voorbeeld van de inhoud

Java Programming – Module 1 (Part 3)
Java Program Structure, OOP Concepts, Collections & Java 8 Features



1. Structure of a Java Program
A Java source file is organized into specific sections. Understanding each part is essential before writing
any Java program.


1.1 Documentation Section
The documentation section consists of comments that improve the readability of the program. They may
include basic information such as a method's usage or functionality, making it easier for programmers to
understand while reviewing or debugging. Comments can appear anywhere in the code and are
completely ignored by the compiler during execution.
Java supports three types of comments:
• Single-line comment: // comment text
• Multi-line comment: /* comment spanning multiple lines */
• Documentation comment: /** starts with /** and ends with */
// a single line comment
/* a multi-line comment
can span multiple lines */
/** a documentation comment */


1.2 Package Statement
Java allows classes to be organized into a named collection called a package. There can be only one
package statement in a Java program, and it must appear at the very beginning of the source file, before
any class or interface declaration. This statement is optional.
• Declares that all classes and interfaces in the source file belong to that package.
package student;


1.3 Import Statement
Many predefined classes are stored in packages. An import statement is used to refer to classes stored in
other packages. It is always written after the package statement but before any class declaration.
import java.util.Date; // imports only the Date class
import java.applet.*; // imports all classes from the applet package
import java.io.*; // imports all classes from the IO package


1.4 Interface Section
This optional section is used to declare interfaces in Java. An interface is similar to a class but contains
only constants and method declarations (no implementation). It is mainly used to implement multiple
inheritance in Java.
interface stack {
void push(int item);
void pop();
}

,1.5 Class Definition
The class definition section contains the actual class. The class name must start with a capital letter. The
keyword public means the class is accessible from any other class.
class Main {
public static void main(String[] args) {
System.out.println("Hello World");
}
}


1.6 Complete Example – Hello Java
A complete Java program illustrating package, class, and method sections:
package basicPrograms;


public class HelloJava {
public static void main(String[] args) {
// Prints Hello, Java! on standard output.
System.out.println("Hello Java!");
}
}



2. Scanner Class – Taking User Input
The Scanner class (from java.util package) is used to read input from the user via the keyboard. It
provides methods for reading different data types.

Method Reads

sc.nextInt() Integer value

sc.nextFloat() Float value

sc.nextDouble() Double value

sc.next().charAt(0) Single character

sc.nextLine() Full string (including spaces)

Note: After reading an integer or float, call sc.nextLine() to clear the input buffer before reading a String.
import java.util.Scanner;
class Mains {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter an integer: ");
int n = sc.nextInt();
System.out.print("Enter a float value: ");
float f = sc.nextFloat();
System.out.print("Enter a character: ");
char c = sc.next().charAt(0);
sc.nextLine(); // Clear the buffer
System.out.print("Enter your name: ");

, String name = sc.nextLine();
System.out.println("Integer: " + n);
System.out.println("Float: " + f);
System.out.println("Character: " + c);
System.out.println("Name: " + name);
}
}



3. Classes and Objects
A class is a blueprint or template for creating objects. An object is an instance of a class. The class
defines attributes (data members) and behaviors (methods).
Example – Car class:
class Car {
String brand;
String model;
int year;


void display() {
System.out.println("Brand: " + brand);
System.out.println("Model: " + model);
System.out.println("Year: " + year);
}


public static void main(String[] args) {
Car c = new Car(); // creating object
c.brand = "Toyota";
c.model = "Corolla";
c.year = 2022;
c.display();
}
}

Example – Student class:
class Student {
String name;
int age;


void display(String a, int b) {
name = a;
age = b;
System.out.println("Name is " + name);
System.out.println("Age is " + age);
}
}
public class Details {
public static void main(String args[]) {

Geschreven voor

Instelling
Vak

Documentinformatie

Geüpload op
18 mei 2026
Aantal pagina's
18
Geschreven in
2025/2026
Type
College aantekeningen
Docent(en)
Mrs shyama
Bevat
Alle colleges

Onderwerpen

$3.49
Krijg toegang tot het volledige document:

Verkeerd document? Gratis ruilen Binnen 14 dagen na aankoop en voor het downloaden kun je een ander document kiezen. Je kunt het bedrag gewoon opnieuw besteden.
Geschreven door studenten die geslaagd zijn
Direct beschikbaar na je betaling
Online lezen of als PDF

Maak kennis met de verkoper
Seller avatar
azuz

Ook beschikbaar in voordeelbundel

Maak kennis met de verkoper

Seller avatar
azuz Rajagiri School of Engineering and Technology
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
-
Lid sinds
3 dagen
Aantal volgers
0
Documenten
6
Laatst verkocht
-

0.0

0 beoordelingen

5
0
4
0
3
0
2
0
1
0

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo makkelijk kan het dus zijn.”

Alisha Student

Bezig met je bronvermelding?

Maak nauwkeurige citaten in APA, MLA en Harvard met onze gratis bronnengenerator.

Bezig met je bronvermelding?

Veelgestelde vragen