Saturday, April 4, 2020

Java : CASem-2 Lecture-1


MARWARI COLLEGE, RANCHI
(AN AUTONOMOUS UNIT OF RANCHI UNIVERSITY FROM 2009)

- Prakash Kumar, Dept. of CA
-Raju Manjhi, Dept. of CA 
__________________________________________________________________________________ 

JAVA
BCA- Sem-II(CBCS)

Java history: It starts from Green Team. Java team members (also known as Green Team), initiated a revolutionary task to develop a language for digital devices such as set-top boxes, televisions etc.
Java is used in internet programming, mobile devices, games, e-business solutions etc. There are given the major point that describes the history of java.
1) James GoslingMike Sheridan, and Patrick Naughton initiated the Java language project in June 1991. The small team of sun engineers called Green Team.
2) Originally designed for small, embedded systems in electronic appliances like set-top boxes.
3) Firstly, it was called "Greentalk" by James Gosling and file extension was .gt.
4) After that, it was called Oak and was developed as a part of the Green project.

 

Some Java versions and its year of release:-
1.   JDK Alpha and Beta     (1995)
2.   JDK 1.0                      (23rd Jan, 1996)
3.   JDK 1.1                      (19th Feb, 1997)
4.   J2SE 1.2                     (8th Dec, 1998)
5.   J2SE 1.3                     (8th May, 2000)
6.   J2SE 1.4                     (6th Feb, 2002)
7.   J2SE 5.0                     (30th Sep, 2004)
8.   Java SE 6                    (11th Dec, 2006)
9.   Java SE 7                    (28th July, 2011)
10.        Java SE 8                (18th March, 2014)
11.        Java SE 9                (21st September 2017)
12.        Java SE 10              (20th March 2018)
13.        Java SE 11              (25th September 2018)
14.        Java SE 12              (19th March 2019)
15.        Java SE 13              (17th September 2019)
16.        Java SE 14              (17th March 2020)
17.        Java SE 15              (Expected in September 2020)

 

Java is Simple

According to Sun, Java language is simple because:
Syntax is based on C++ (so easier for programmers to learn it after C++).
Removed many confusing and/or rarely-used features e.g., explicit pointers, operator overloading etc.
No need to remove unreferenced objects because there is Automatic Garbage Collection in java.

 

Object-oriented

Object-oriented means we organize our software as a combination of different types of objects that incorporates both data and behaviour.
Object-oriented programming (OOPs) is a methodology that simplifies software development and maintenance by providing some rules.
Basic concepts of OOPs are:
    1.   Object
    2.   Class
    3.   Inheritance
    4.   Polymorphism
    5.   Abstraction
    6.   Encapsulation

 

Features of Java:

1.   Platform Independent

A platform is the hardware or software environment in which a program runs. There are two types of platforms software-based and hardware-based. Java provides software-based platform. The Java platform differs from most other platforms in the sense that it's a software-based platform that runs on top of other hardware-based platforms. It has two components:
    1.   Runtime Environment
    2.   API(Application Programming Interface)


Java code can be run on multiple platforms e.g.Windows, Linux, Sun Solaris, and Mac/OS etc. Java code is compiled by the compiler and converted into bytecode.This bytecode is a platform independent code because it can be run on multiple platforms i.e. Write Once and Run Anywhere(WORA).

 

2.   Secured

Java is secured because:
·         No explicit pointer
·         Programs run inside virtual machine sandbox.


·         Classloader- adds security by separating the package for the classes of the local file system from those that are imported from network sources.
·         Bytecode Verifier- checks the code fragments for illegal code that can violate access right to objects.
·         Security Manager- determines what resources a class can access such as reading and writing to the local disk.
These securities are provided by java language. Some security can also be provided by application developer through SSL,JAAS,cryptography etc.

3.   Robust

Robust simply means strong. Java uses strong memory management. There are lack of pointers that avoids security problem. There is automatic garbage collection in java. There is exception handling and type checking mechanism in java. All these points makes java robust.

4.   Architecture-neutral

There are no implementation dependent features e.g. size of primitive types is set.
Central issue for the Java designers was that of code longevity and portability. One of the main problems facing programmers is that no guarantee exists that if you write a program today, it will run tomorrow—even on the same machine. Operating system upgrades, processor upgrades, and changes in core system resources can all combine to make a program malfunction. The Java designers made several hard decisions in the Java language and the Java Virtual Machine in an attempt to alter this situation. Their goal was “write once; run anywhere, anytime, forever.” To a great extent, this goal was accomplished.

5.   Portable

We may carry the java bytecode to any platform.

6.   High-performance

Java is faster than traditional interpretation since byte code is "close" to native code still somewhat slower than a compiled language (e.g., C++)

7.   Distributed

We can create distributed applications in java. RMI and EJB are used for creating distributed applications. We may access files by calling the methods from any machine on the internet.

 

8.   Multi-threaded

A thread is like a separate program, executing concurrently. We can write Java programs that deal with many tasks at once by defining multiple threads. The main advantage of multi-threading is that it shares the same memory. Threads are important for multi-media, Web applications etc.

 

Creating First Program

Let's create the hello baba program:
class A
{  
    public static void main(String args[])
   {  
     System.out.println("Hello Baba! It’s Java");  
   }  
}  

 Save this file as A.java
Compile:
javac A.java
Execute:
java A

 

Understanding first java program

Let's see what is the meaning of class, public, static, void, main, String[], System.out.println().
·     class keyword is used to declare a class in java.
·     public keyword is an access modifier which represents visibility, it means it is visible to all.
·   static is a keyword, if we declare any method as static, it is known as static method. The core advantage of static method is that there is no need to create object to invoke the static method. The main method is executed by the JVM, so it doesn't require to create object to invoke the main method. So it saves memory.
·     void is the return type of the method, it means it doesn't return any value.
·     main represents startup of the program.
·     String[] args is used for command line argument.
·     System.out.println() is used print statement.

Note:
Valid java main method signature
1.           public static void main(String[] args)  
2.           final strictfp public static void main(String[] args)  

 



1 comment: