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

1-COE312 Lecture - Introduction to Java

Java is an object-oriented programming language similar to C++, designed to be platform-independent through the use of Java Bytecode and the Java Virtual Machine (JVM). It does not support pointers, operator overloading, or multiple inheritance, and relies on external libraries for functionality. The tutorial will cover various aspects of Java, including its access levels, constructors, and garbage collection.

Uploaded by

toshionoeiyu
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)
3 views11 pages

1-COE312 Lecture - Introduction to Java

Java is an object-oriented programming language similar to C++, designed to be platform-independent through the use of Java Bytecode and the Java Virtual Machine (JVM). It does not support pointers, operator overloading, or multiple inheritance, and relies on external libraries for functionality. The tutorial will cover various aspects of Java, including its access levels, constructors, and garbage collection.

Uploaded by

toshionoeiyu
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/ 11

Introduction to Java

Omar Arif

COE312
Slides adapted from Dr Imran Zualkernan
 Java is very similar to C++
 It is an object-oriented language
 Independent of host platform
 The Java compiler takes Java code and compiles it to
Java Java Bytecode which is a cross-platform format
 Java virtual machine (JVM) takes the byte code and
converts it into native code

 Relies heavily on external libraries


 Java does not have:
 Use of Pointers
 Operator overloading

Java  Multiple inheritance


 Friend classes (access another object’s private
members)
IEEE Spectrum
Top Programming
Languages 2023
IEEE Spectrum
Top Programming
Languages 2023
 We will now follow the tutorial here to explore
various basic aspects of Java.

Tutorial:
https://www.w3schools.com/JAVA/default.asp
Java Tutorial Compiler:
https://www.onlinegdb.com/online_java_compiler
For the course we will use the Eclipse compiler
available for free download at.
https://www.eclipse.org/downloads/packages/
Cover the
following topics
in the tutorial
Cover the
following in OO
Programming
in Java
 Java has inheritance but does not support multiple
inheritance.
 Java is strictly pass by value.
 Similar to namespaces, Java has the concept of a
Package that is a collection of classes.
 There is no delete operator. A program called
garbage collector cleans up memory
Review automatically.
 Default access levels in Java are different than C+
+.
 Java default is package-private while in C++ is
public

 Constructors behave slightly differently than C++.


 Constructors are always called using a new operator
in java
 Each field and method in Java class has an access
level:
 private: accessible only in this class
 default: accessible only in this package
 protected: accessible only in this package and in all
subclasses of this class
 public: accessible everywhere this class is available

Review  Similarly, each class has one of two possible


access levels:
 default: class objects can only be declared and
manipulated by code in the same package
 public: class objects can be declared and
manipulated by code in any package
 If a constructor has arguments, you supply corresponding values when
using new.
 Even if it has no arguments, you still need the parentheses (unlike C+
+). For example, Flower f = new Flower; is not legal in java.
 Just like C++ there can be multiple constructors, with different
numbers or types of arguments. This is called constructor overloading.
 Default constructor is created only if there are no
constructors. If you define any constructor for your class, no default
constructor is automatically created.

Review  this(...) - Calls another constructor in same class.


 super(...). Use super to call a constructor in a parent class.
 The Java compiler inserts a call to the parent constructor (super) if you
don't have a constructor call as the first statement of you constructor.
 Unlike C++, you cannot overload operators.
 Every Class in Java is implicitly a subclass of Object.
This allows common methods and attributes to be automatically
available upon creation of a new object. Some of the common methods
are for example: toString() and equals()

You might also like