Core Java Part I: Computer Science YouTube Lecture Handouts

Get unlimited access to the best preparation resource for UGC : Get detailed illustrated notes covering entire syllabus: point-by-point for high retention.

Topics To Be Discussed

Introduction

  • JAVA is an object oriented Language
  • It is platform independent. Whenever the JAVA program is compiled, it is converted into Byte codes which can be executed on any machine.
JAVA is an Object Oriented Language
  • It is the only language that is used for Window Application Development, Web Application Development and Mobile Application Development.
  • It is a secure language as its code can run in JAVA Runtime Environment (JRE) only. There is not any interference of additional software even not of an OS.
  • There is no implementation dependency like a specific version of a software is required. This makes JAVA is portable language. Java code written in one machine can be interpreted/executed in another machine due to its portability.
  • It is multithreading language that means a program written in JAVA can perform multiple task simultaneously. Execution of multithreads at the same time helps to utilize the same memory. That saves memory and makes execution faster.

Java Development Kit (JDK)

It provides a complete framework that includes various tools to develop a software. These tools are:

  • JVM (JAVA Virtual Machine) - It provides a runtime environment to execute the byte code.
  • JRE (JAVA Runtime Environment) - JVM is the part of JRE. It also includes Java core classes and other supporting files that helps to execute the code smoothly.
  • Javac (JAVA Compiler) - It compiles the code and show the errors if occurs.
  • JAVA (JAVA Interpreter) - It interprets the java code and execute the code.
  • Jar (An archiver) - It creates a single jar file (executable) of complete project. In other words, it binds all the files made with a single file to execute the software.

Environmental Variable

An environmental variable is a global system variable used by all the users or processors running in the operating system. It provides reference about the software/operating system when asked. It also provides the path of directories where a particular file is stored.

How to Set Environmental Variable

To set Environmental variable in java, follow these steps:

  • Copy the path from C: ⧵Program Files⧵JAVA⧵jdk-11.0. 4 (which ever version is available)
  • Go to the Control PanelSystem and SecuritySystemAdvanced System Settings.
  • System Properties dialog box will open. In the System tabClick on the Environmental Variable.
  • Under System Variable boxClick on pathClick on Edit buttonErase the old and paste the copied path. ◊ Click on OK.

Snapshots-1 (Copying the Path of JDK)

Snapshots-1 (Copying the Path of JDK)

SNAPSHOT-II (Pasting the path in Environmental Variable)

Environmental Variable
Environmental Variable
Environmental Variable

JAVA Program Structure

JAVA Program Structure

Classes in JAVA

CLASS: A class is a building block for a program. In java ′ class; keyword is used to declare the class. Class name should be the same as the file name. There are three types of classes in JAVA.

  • Main Class
  • Base/Parent/Extended Class
  • Child Class/Sub Class/Derived Class

Main Class: Main Class is that class which has the main function i.e..

Public static void main (String [] args) {}

Base Class: A Base class is that which is extended by another class. It means one or more its data members are used/implemented in derived class. It has the authority to control the access of its data members whether they can be used in derived or not.

Derived Class: A derived class is that which is derived from its Base class. It derives its features as well as its data member to access and implement them. A derived class can be main class also.

Classes in JAVA

Main Function

In the JAVA Program we see,

  • public static void main (String [] args) {}
  • public: It is an access specifier used in programming. ‘public’ means accessible for all.
  • static: static is a reserved word (keyword) that makes a data member ‘static’ . It means to execute the function, there is no need to create object/instance of the class. that՚s Why we do create object of main class.
  • void: void means this function will not return any value.
  • main: It is the function name. It is the main method in JAVA that is executed whenever a program runs. that՚s why we use to create objects of another classes in the main () so that all the classes can function whenever main () executes.
  • String [] args: Here, String is a data type is used to represent an array as an argument of main function. Any value which we takes dynamically (at run time) is in the form of String type. To use those values, they need to be converted. In the function, ‘args’ is an identifier. You can use any name instead of ‘args’ .

Saving a Program

While saving a java program you should ensure that file name must be same as the class name and save it with [. java] extension.

Example

class sample

{

public static void main (String [] args) {/ ⚹⚹ ⚹⚹ ⚹⚹ ⚹⚹ ⚹⚹ ⚹⚹ ⚹⚹ ⚹ /}

}

While saving file name should be sample. java. When you compile this program, it will generate a class with same name as sample. Class with byte code character.

Path where to compile java program

Path Where to Compile Java Program

Compilation/Execution

  • To compile java program, open cmd (Command Prompt) .
  • Set the path where you have saved your program as highlighted in previous snapshot.
  • Type ‘javac < filename > . java’
  • If a compiler doesn՚t detect any error. You can start execution by typing ‘java < filename >’ .
Compilation/Execution

MCQs

Q-1 Which is to be set first to compile or interpret a java program?

1. Environmental Variable

2. Screen Resolution

3. Variables

4. Data types

Answer: 1

Q-2 Which keyword allows a function to be executed without making any instance of its class?

1. Public

2. Private

3. Static

4. String

Answer: 3

Developed by: