01 - Java Fundamental Concepts
01 - Java Fundamental Concepts
• James Gosling, Mike Sheridan, and Patrick Naughton initiated the Java language
project in June 1991.
• The language was initially called Oak. Now, Java it is the name of a platform
and language.
• Java applications are typically compiled to bytecode (class file) that can run on
any Java Virtual Machine (JVM) regardless of computer architecture.
• The original and reference implementation Java compilers, virtual machines,
and class libraries were developed by Sun from 1995 (May 23, 1995, Java 1.0).
• With the advent of Java 2 (JDK 1.2, released initially as J2SE 1.2 in December
1998–1999), new versions had multiple configurations built for different types
of platforms.
Introduction to Java Platform
• Specification Java 2 (JDK 1.2) – 1998/1999 (collection support; Swing; reflection;
Unicode; JIT compiler). Sun renamed new J2 versions as Java EE, Java ME, and
Java SE.
• Oracle Corporation is the current owner of the official implementation of the
Java SE platform, following their acquisition of Sun Microsystems on January
27, 2010.
• This implementation is based on the original implementation of Java by Sun.
• The Java 13 was released on September 17, 2019 and includes the following
new features, as well as "hundreds of smaller enhancements and thousands of
bug fixes".
• The Oracle implementation is available for Microsoft Windows, macOS, Linux,
and Solaris.
https://www.geeksforgeeks.org/the-complete-history
-of-java-programming-language/
Java Platform Components
java -version
First Java Program
Compile and Run Java Program
Java Archive
manifest.mf Example.jar
• It must be static because, before your program starts, there aren’t any objects to
send messages to.
• This is a static context (a class static method):
̶ you can send messages to objects, if you have some objects;
̶ you cannot send a message to yourself, or use any instance variables – this is a static
context, not an object.
Setting an Entry Point
• The parameter of the main() method is an array of type String, which contains the
additional arguments after the class name argument in the "java" command line.
public static void main(String[] a) {
System.out.println("Number of arguments = "+a.length);
for (int i=0; i<a.length; i++) {
System.out.println(" a["+i+"] = " + a[i]);
}
}
• You can directly invoke this application by running the following command:
$ java -jar HelloJava.jar hello java!
Number of arguments = 2
a[0] = hello
a[1] = java!
Java Program Console Output
• For displaying simple text messages to the user:
System.out.print(...) – prints the required output on the same line
continuously again and again on the screen;
System.out.println(...) – prints the output in the next line of the previous
result on the screen.
public class Main {
public static void main(String[] args) {
System.out.print("Hello ");
System.out.print("Java!");
System.out.println(" How are you?");
System.out.println("Goodbye Java!");
}
}
Java Comments
• The Java language supports three kinds of comments:
• the compiler ignores everything from // to the end of the line.
// This example demonstrates the use of single line comments
• /** and */ indicates a documentation comment. The compiler ignores this kind
of comment, just like it ignores comments that use /* and */.
• The JDK javadoc tool uses documentation comment when preparing automatically
generated documentation.
Java Variables
Variable – symbolic name associated with a value and whose associated value
may be changed.
Declaration – process of variable's specifying. Usually declaration consist of
defining: type, name and default value of variable.
Value Type
10 Integer
25.38 Floating point
'A' '/u0040' Unicode character
"Java is programming language" String
true Boolean value
Java Escape Sequences
• Java language supports few special escape sequences for String and char
literals as well.
* (multiplication) Multiplies values on either side of the operator. a * b will give 200
int a = 4; // a = 4
a++; // a = 5
int b = a++; // a = 6 b = 5
b = ++a; // a = 7 b = 7
Java Bitwise Operators
• The Java language introduces the bitwise operators, which help in
manipulating a single bit of a byte.
Operator Description
& Bitwise AND
Truth table
^ Bitwise XOR 0 0 0 0 0
0 1 0 1 1
>> Shift right
1 0 0 1 1
>>> Shift right zero fill 1 1 1 1 0
int b = -64;
b = b >>> 1; // (+)0 1111111 11111111 11111111 11100000