0% found this document useful (0 votes)
6 views11 pages

Java Programming Basics and Setup Guide

java fundamentals .

Uploaded by

rajketan304
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views11 pages

Java Programming Basics and Setup Guide

java fundamentals .

Uploaded by

rajketan304
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

GenieAshwani

Introduction to Java Programming

Why Do We Need Programming Languages?

• Communication with Computers: Programming languages allow humans to


communicate instructions to computers in a way they can understand.

Java History

Home: SUN Mc Systems (Oracle Corporation)

Author: James Gosling

Objective: To prepare simple electronic consumer goods.

Project: Green

First Version: JDK 1.0 (1996, Jan-23rd)

Used Version: Some org JDK5.0, Some other JAVA 6, JAVA 7

Latest Version: JAVA7, JAVA8, This April – JAVA 9

Type of Software: Open-Source Software

Differences between Java and Others

C and C++ are static programming languages but JAVA is dynamic programming
language

• If any programming language allows memory allocation for primitive data types
at compilation time [Static Time] then that programming language is called as
Static Programming language.
GenieAshwani

EX: C and C++.

• In C and C++ applications, memory will be allocated for primitive data types at
compilation time only, not at runtime.
• If any programming language allows memory allocation for primitive data types
at runtime, not at compilation time then that programming language is called as
Dynamic Programming Language.

EX: JAVA

• In java applications, memory will be allocated for primitive data types at runtime
only, not at compilation time.
• Note: In Java applications, memory will be allocated for primitive data types at
the time of creating objects only, in java applications, objects are created at
runtime only

Pre-Processor is required in C and C++, but Pre-Processor is not required in Java:

In case of C and C++, the complete predefined library is provided in the form of
header files

If we want to use predefined library in C and C++ applications, we have to include


header files in C and C++ applications, for this, we have to use #include<> statement.

EX:

• #include<stdio.h>
• #include<conio.h>
• #include<math.h>

If we compile C and C++ applications then Pre-Processor will perform the following
actions.

1) Pre-Processor will recognize all #include<> statement


2) Pre-Processor will take all the specified header files from #include<>
statements.
3) If the specified header files are existed then Pre-Processor will load the specified
header files to the memory, this type of loading predefined library at compilation
time is called as "Static Loading"
GenieAshwani

In java, the complete predefined library is provided in the form of classes and interfaces
in packages

EX:

• [Link]
• [Link]
• [Link]

If we want to use predefined library in java applications then we have to include


packages in java application, for this we have to use "import" statements

EX:

• import [Link].*;
• import [Link].*;
• import [Link].*;

While executing java program, when JVM[Java Virtual Machine] encounter any class or
interface from the specified package then only JVM will load the required classes and
interfaces to the memory at runtime, loading predefined library at runtime is called as
"Dynamic Loading".
GenieAshwani

3. C and C++ are platform dependent programming languages, but JAVA is platform
independent programming language.

If any PL allows its applications to perform compilation and execution on the same
Operating System then that PL is called as Platform Dependent PL.
GenieAshwani

If any PL allows its applications to perform Compilation is on one OS and execution is


on another OS then that PL is called as Platform independent PL.

Platform Dependent vs. Platform Independent

Platform Dependent: A programming language that allows its applications to be


compiled and executed on the same operating system (e.g., C with .exe files).

Platform Independent: Java, with its .class files containing bytecode, can be executed
on any operating system.

What are the differences between .exe file and .class file?
GenieAshwani

Setting Up Java Enviroment

• Download Java 17: Oracle JDK 17 Archive


• Set Path: Ensure Java is properly installed by setting the system path.
• Verify Installation: Run java --version in the command prompt.

Writing Java Code

You can use various text editors like Notepad, Notepad++, EditPlus, or an IDE like
IntelliJ.

Java program Structure

1. package statement

2. import statement [A--->B]

3. class declaration

4. Methods

5. variable
GenieAshwani

Package Statement (Optional)

• What It Is: A way to group related classes and organize your code.
• Why It's Used: Helps avoid name conflicts and makes the code more
manageable.
• Example: package my package;
• Note: Your program can work without it.

Import Statements

• What It Is: Allows you to use classes from other packages.


• Why It's Used: Saves time by reusing code from the Java library or other
sources.
• Example: import [Link];
• Note: Think of it as bringing in tools from a toolbox to use in your program.

Class Declaration

• What It Is: Defines a new class.


• Why It's Used: All Java code must be inside a class.
• Note: If The class is public then name of file should match the class name.

Example
GenieAshwani

Methods

• What It Is: Blocks of code that perform specific tasks.


• Why It's Used: Helps to organize code into reusable chunks.
• Note: The main method is the entry point of any Java program

Variables:

• Variables are used to hold/share the data during the program execution
• We need to specify type of the variable to store the data
• To specify type of data we will use 'data types'

Translators in Programming

1. Interpreter: Translates code line-by-line.


2. Compiler: Translates entire code at once.
3. Assembler: Converts assembly language to machine code.

Class And Object:

Class is a blueprint or template for creating objects.

Example: Think of a class as the blueprint of a house. The blueprint itself isn't a house,
but it details the design and features of the house.

Object An instance of a class.

Example: An object is like a real house made from the blueprint. Each house can look
the same but is a separate, physical thing.
GenieAshwani

Data Type

Range:
GenieAshwani

JDK, JRE, and JVM

JDK (Java Development Kit)

• Role: It's the tool for making Java programs.


o How It Works: The JDK includes a compiler to turn your Java code into a
format the computer can understand (bytecode).
• It also includes the JRE to test and run the programs you make.

JRE (Java Runtime Environment)

• Role: It's the setup needed to run Java programs.


o How It Works: The JRE includes libraries and components that help your
Java programs run.
• It includes the JVM, which is the part that actually runs your programs.

JVM (Java Virtual Machine)

• Role: It's the part that runs Java programs.


o How It Works: The JVM reads the bytecode (compiled Java code) and
translates it into machine code that your computer can execute.

How They Work Together:

JDK: You use it to write and compile Java programs.

JRE: Provides the environment and libraries needed to run Java programs.

JVM: Runs the bytecode produced by the JDK, turning it into machine code your
computer can understand.
GenieAshwani

Java Identifiers

Identifiers are the names given to class, variable, method, interface.

Rules for naming Identifiers:

1. valid char : lower case , Upper case, digit, _, $

2. Start with : letter,_, $. it cannot start with digit

3. case Sensitivity : car, CAR , cAR, Car

4. Reserved Keyword’s: (int, for, if, class) cannot be used

Convention For Naming Identifiers (best for Identifiers):

1. CamelCase: for classes, method and variable eg: carName, cityName

2. Meaningful : String cityName = "10202" ,cityName="Agra"

Eg: Identifiers

age ----------> valid

_marks --------> valid

$value --------> valid

8marks ----------> invalid

class -----------> invalid

my-name ---------> invalid

@cityName -------> invalid

calCulater ------> valid

You might also like