Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

Java Basics Notes

This document provides an introduction to Java programming, covering its installation, basic syntax, data types, input/output, operators, conditional statements, loops, arrays, functions, and object-oriented programming concepts. It includes sample code snippets for better understanding. Java is highlighted as a platform-independent, object-oriented language developed by Sun Microsystems and owned by Oracle.

Uploaded by

Mehakpreet Kaur
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Java Basics Notes

This document provides an introduction to Java programming, covering its installation, basic syntax, data types, input/output, operators, conditional statements, loops, arrays, functions, and object-oriented programming concepts. It includes sample code snippets for better understanding. Java is highlighted as a platform-independent, object-oriented language developed by Sun Microsystems and owned by Oracle.

Uploaded by

Mehakpreet Kaur
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Java Programming Notes for Beginners

1. Introduction to Java

Java is a high-level, class-based, object-oriented programming language. It was developed by Sun

Microsystems and is now owned by Oracle. Java is platform-independent, thanks to the Java Virtual Machine

(JVM).

2. Java Installation & First Program

To run Java programs:

- Install JDK from Oracle's website

- Use any IDE (like IntelliJ, Eclipse) or a text editor.

Sample Program:

public class Main {

public static void main(String[] args) {

System.out.println("Hello, World!");

Output:

Hello, World!

3. Variables and Data Types

Java has strong data typing. Common types:

- int (integers)

- float (decimals)

- char (characters)

- boolean (true/false)

- String (text)

Example:
Java Programming Notes for Beginners

int age = 20;

String name = "Mehak";

4. Input/Output using Scanner

To take input from the user:

import java.util.Scanner;

Scanner sc = new Scanner(System.in);

int num = sc.nextInt();

String str = sc.nextLine();

5. Operators

Types of operators in Java:

- Arithmetic: +, -, *, /, %

- Relational: ==, !=, >, <, >=, <=

- Logical: &&, ||, !

6. Conditional Statements

if-else:

if (condition) {

// code

} else {

// code

switch:

switch (var) {

case 1: ...; break;

default: ...;
Java Programming Notes for Beginners

7. Loops

for loop:

for (int i = 0; i < 5; i++) {

System.out.println(i);

while loop:

int i = 0;

while (i < 5) {

i++;

8. Arrays

int[] arr = new int[5];

int[] nums = {1, 2, 3, 4};

System.out.println(nums[0]); // prints 1

9. Functions (Methods)

Methods are blocks of code that perform a task.

Example:

public static int add(int a, int b) {

return a + b;

10. OOP Basics

Class is a blueprint. Object is an instance.


Java Programming Notes for Beginners

class Dog {

String name;

Dog(String n) {

name = n;

Dog d = new Dog("Bruno");

You might also like