0% found this document useful (0 votes)
7 views32 pages

ICT 143-2 Data Structures 01

Uploaded by

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

ICT 143-2 Data Structures 01

Uploaded by

dinithi ravindra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 32

ICT 143-2 Data

Structures
and Algorithms

Practical 1 –Introduction to Java Programming


JAVA
• Java is a high-level programming language originally developed by Sun
Microsystems and releases in 1995

• Runs on a variety of platforms (Windows, Mac OS and various


versions of UNIX)

• Object Oriented – Everything is an Object.


JAVA

– Originally for intelligent consumer-electronic devices (cell


phones)

– Then used for creating Web pages with dynamic content

– Now also used for:


• Develop large-scale enterprise applications
The Java Programming Language
A high-level language that can be characterized by all of the following:

Object-orientated programming language


Platform independent
Strongly-typed programming language
Interpreted and compiled language
Automatic memory management
The Java Platform
• The Java Platform differs from most of the other platforms..

• Because it’s a software only platform.

• Which will run on the top of other Hardware based platforms.


Terminology
 The Java Application Programming Interface (API)

• A large collection of ready-made software components.


• It is grouped into packages of related classes and interfaces
Java

• Simple – Easy to learn


• Secure - With Java's secure feature it enables to develop virus-free, tamper-
free systems Authentication techniques are based on public-key encryption.
• Portable - Being architecture-neutral and having no implementation
dependent aspects of the specification makes Java portable. Compiler in
Java is written in ANSI C with a clean portability boundary, which is a POSIX
subset.
• Robust - Java makes an effort to eliminate error prone situations by
emphasizing mainly on compile time error checking and runtime checking.
Java Virtual Machine (JVM)

• JVM is the foundation of the Java Platform.

• The environment in which java runs.

• The JVM is responsible for executing the byte codes and responsible for fundamental
capabilities of java.

• Byte codes are platform independent therefore will not depend on a particular
hardware platform.

• So these byte codes may execute on any platform containing a JVM.


Write application once, runs on any………!!!
Java life cycle
• Java programs normally undergo four phases
• Edit
• Programmer writes program (and stores program on disk)
• Compile
• Compiler creates bytecodes from program (.class)
• Load
• Class loader stores bytecodes in memory
• Execute
• Interpreter: translates bytecodes into machine language
• In the Java programming language, all source code is first written in plain text files
ending with the FileName.java extension.

• Those source files are then compiled into .class files by the javac compiler.

• FileName .class file does not contain code that is native to your processor; it
instead contains bytecodes — the machine language of the Java Virtual Machine
(Java VM).

• The java launcher tool then runs your application with an instance of the Java
Virtual Machine.
Java Environment Setup
Java Environment Setup
• Set the environment variable for Windows
• ◦ Assuming you have installed Java in c:\Program Files\java\jdk directory -
• ◦ Right-click on 'My Computer' and select 'Properties'.
• ◦ Click the 'Environment variables' button under the 'Advanced' tab.
• ◦ Now, alter the 'Path' variable so that it also contains the path to the Java
• executable. Example, if the path is currently set to 'C:\WINDOWS\
SYSTEM32',
• then change your path to read 'C:\WINDOWS\SYSTEM32;c:\Program
• Files\java\jdk\bin'.
Popular Java Editors

• Notepad - On Windows machine, you can use any simple text editor like
Notepad

• NetBeans - A Java IDE that is open-source and free which can be downloaded
from https://www.netbeans.org/index.html

• Eclipse - A Java IDE developed by the eclipse open-source community and can
be downloaded from https://www.eclipse.org/
Visual Studio Code
Visual Studio Code
• Java in Visual Studio Code
First Java Program

public class TestClass {

public static void main(String[] args) {

System.out.println("My First Java Program.");

}
Comments

• Single line comments are created by using //.


• Multi-line comments are created by starting with /* and ending with
*/.
main() method

• In Java, every application must contain a main() method, which is the


entry point for the application.
• All other methods are invoked from the main() method.
• The signature of the method is public static void main(String[] args)
{ }. It accepts a single argument: an array of elements of type String
Java Identifiers and Modifiers

• All Java components require names. Names used for classes,


variables, and methods are called identifiers.
• Access Modifiers - default, public , protected, private
• Non-access Modifiers - final, abstract, strictfp
Java Variables

• Local Variables: Variables defined inside methods, constructors or blocks


are called local variables. The variable will be declared and initialized
within the method and the variable will be destroyed when the method
has completed.
• •Class Variables (Static Variables): Class variables are variables declared
within a class, outside any method, with the static keyword.
• •Instance Variables (Non-static Variables): Instance variables are variables
within a class but outside any method. These variables are initialized when
the class is instantiated. Instance variables can be accessed from inside
any method, constructor or blocks of that particular class.
Example
Data Types
• Primitive Data Types:
◦ byte
◦ short
◦ int
◦ long
◦ float
◦ double
◦ boolean
◦ char
Reference/ Object Data Types:
◦ A reference variable can be used to refer any object of the declared type or any compatible
type.
◦ Example: Animal animal = new Animal("giraffe");
Object and Class
• Object - Objects have states and behaviors.
◦ Example: A dog has,
◦ states - color, name, breed
◦ behaviors – wagging the tail, barking, eating.
◦ An object is an instance of a class.

• Class - A class can be defined as a template/blueprint that describes the


behavior/state that the object of its type support.
• Constructor. Every class has a constructor.
• If we do not explicitly write a constructor for a class, the Java compiler builds a default
constructor for that class.
• Each time a new object is created, at least one constructor will be invoked. The main rule of
constructors is that they should have the same name as the class. A class can have more than one
constructor.
Method

• Syntax

• modifier - It defines the access type of the method, and it is optional to use.

•returnType - Method may return a value.

•nameOfMethod - This is the method name. The method signature consists of the method name and the
parameter list.

•Parameter List - The list of parameters, it is the type, order, and number of parameters of a method. These are
optional, method may contain zero parameters.
•method body - The method body defines what the method does with the statements
Method call

• For using a method, it should be called


• There are two ways in which a method is called
◦ method returns a value
◦ returning nothing (no return value)
Thankyou

You might also like