Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Day 1 Java Notes Codesy Center

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

CODESY TRAINING CENTRE

Core Java Concepts:


Why Programming Languages:

Let’s understand this by an example:

Two people want to communicate with each other. One is from Punjab and another person is from
Tamil Nadu. Now if a Punjabi person talks in Punjabi language then Tamil person will not understand
anything. Also if a Tamil person talks in Tamil language then Punjabi person will not understand
anything.

So both of them have to use a language which both can understand. Now let’s assume that English is a
language which both of them can understand and speak. So if both of them start speaking in English,
then both can easily communicate.

Same is the case with humans and computers. We use computers to perform many tasks. But
computers do not understand human languages like English, Hindi, Marathi, Tamil etc. Computers only
understand Binary Language, which is a language of 0 and 1.

But it is difficult for humans to instruct computers in Binary Language. So programming languages were
invented which humans can easily understand and use to give instructions to computers. These
instructions will be converted into Binary Code by computer programs (compiler and interpreter) so
computers can understand these instructions and perform the desired tasks.

Journey of Programming Languages:

When computers were invented, programming was done with the help of binary machine instructions.
But it was not possible to write bigger and complex programs with the help of Binary Code.

Example of Binary Code:

Contact Us on: +91 9405224852 / codesytraining@gmail.comPage 1


CODESY TRAINING CENTRE

Hence, Assembly Language was invented. Assembly language is designed for specific processors.
Assembly Language is just a symbolic representation of the machine instructions. It uses an assembler
to convert the assembly language to machine language. Programmers were able to write bigger and
complex programs with the help of Assembly Language but up to a certain limit only.

Contact Us on: +91 9405224852 / codesytraining@gmail.comPage 2


CODESY TRAINING CENTRE

As programs continued to grow, High Level programming languages were invented so programmers can
develop more complex and bigger programmers.

Contact Us on: +91 9405224852 / codesytraining@gmail.comPage 3


CODESY TRAINING CENTRE

Problem with early high level languages like BASIC, COBOL, FORTRAIN was these languages were not
designed around Structured Principals. These languages were based on the GOTO principle as a primary
means of program control.

By the early 1970s, the computer revolution was started, and the demand for software was rapidly
increasing. At the same time, Computer hardware was becoming common enough and was reached till
common people. This allowed programmers to begin to create their own compute
computerr programming
language.

Result of this was the invention of the C programming language.

During the late 1970s and early 1980s, C became the dominant computer programming language, and it
is still widely used today. But then what was the need for some othe
other languages?

The answer is complexity. With structured programming languages like C, once a project reaches a
certain size, its complexity exceeds and it is difficult for a programmer to manage.

To solve this problem, a new way to program was invented, cal


called object-oriented
oriented programming (OOP).

C++ was invented in 1979 and the initial name was ““C with Classes.”
.” However, in 1983, the name was
changed to C++.

C++ extends C language by adding objectobject-oriented


oriented features. Because C++ is built on the foundation of C,
it includes all of C’s features, attributes, and benefits. This is a crucial reason for the success of C++ as a
language.

Contact Us on: +91 9405224852 / codesytraining@gmail.comPage 4


CODESY TRAINING CENTRE

Why was Java invented?

During the early phase of 1990's, the electronic market was at its peak. Hence, programmers were
looking for a platform-independent (that is, architecture-neutral) language that could be used to create
software to be embedded in various consumer electronic devices, such as microwave ovens and remote
controls.

Reason for that is, many different types of CPUs are used as controllers in these electronic devices.
Problem with C and C++ was that they are designed to be compiled for a specific CPU. So if we use C or
C++ to create these software then we need to develop a software and compiler targeted for that CPU.

The problem is that this is expensive and time-consuming to create.

An easier—and more cost-efficient—solution was needed. In an attempt to find such a solution, Gosling
and others began work on a portable, platform-independent language that could be used to produce
code that would run on a variety of CPUs under differing environments. This effort ultimately led to the
creation of Java.

When the team was working on the creation of Java, the World Wide Web came. This web also needed
programs that can be executed on different CPUs having different OS and other configurations.

By 1993, Java developers observed that, the problems of portability frequently encountered when
creating code for embedded controllers are also found when attempting to create code for the Internet.
In fact, the same problem that Java was initially designed to solve on a small scale could also be applied
to the Internet on a large scale. This realization caused the focus of Java to switch from consumer
electronics to Internet programming and hence Java became the Internet language.

Another reason for Java to be very famous is that Java is a programmer’s language and is designed,
tested, and refined by real working programmers.

Java introduced APPLET and that changed the way the online world thought about content. Java also
solved the most important issues associated with the Internet: portability and security.

An applet is a special kind of Java program that is designed to be transmitted over the Internet and
automatically executed by a Java-compatible web browser. If the user clicks a link that contains an
applet, the applet will be automatically downloaded and run in the browser. Applets are intended to be
small programs. They are typically used to display data provided by the server, handle user input, or
provide simple functions, such as a loan calculator, that execute locally, rather than on the server.

But when a program downloads and executes automatically on the client computer then that program
must be prevented from doing harm. It must also be able to run in a variety of different environments
and under different operating systems. Let's see how Java solves these problems:

Contact Us on: +91 9405224852 / codesytraining@gmail.comPage 5


CODESY TRAINING CENTRE

Security:

As you already know, when you download a normal program from the internet, there is always a risk,
because the code you are downloading might contain a virus, Trojan horse, or other harmful code. That
code can get unauthorized access to system resources.

For example, a virus program might gather private information, such as credit card numbers, bank
account balances, and passwords, by searching the contents of your computer’s local file system.

In order for Java to enable applets to be downloaded and executed on the client computer safely, it was
necessary to prevent an applet from launching such an attack.

Java achieved this protection by restricting an applet to the Java execution environment and not
allowing it access to other parts of the computer. This ability of Java to download applets with
confidence that no harm will be done and that no security will be breached made Java the language of
the internet.

Portability:

Portability is a major aspect of the Internet because there are many different types of computers and
operating systems connected to it. If a Java program were to be run on virtually any computer
connected to the Internet, then there needed to be some way to enable that program to execute on
different systems.

For example, in the case of an applet, the same applet must be able to be downloaded and executed by
the wide variety of CPUs, operating systems, and browsers connected to the Internet. It is not practical
to have different versions of the applet for different computers. The same code must work on all
computers.

Hence there was a need to generate portable code which can be developed once and executed anytime,
anywhere.

Java solves both the problem (Security and Portability) because output of a Java compiler is not
executable code. Rather, it is bytecode.

Bytecode is a highly optimized set of instructions designed to be executed by the Java run-time system,
which is called the Java Virtual Machine (JVM).

Translating a Java program into bytecode makes it much easier to run a program in a wide variety of
environments because only the JVM needs to be implemented for each platform. Once the run-time
package exists for a given system, any Java program can run on it.

Although the details of the JVM will differ from platform to platform, all understand the same Java
bytecode.

If a Java program were compiled to native code, then different versions of the same program would
have to exist for each type of CPU connected to the Internet. This is, of course, not a feasible solution.
Thus, the execution of bytecode by the JVM is the easiest way to create truly portable programs.

Contact Us on: +91 9405224852 / codesytraining@gmail.comPage 6


CODESY TRAINING CENTRE

The fact that a Java


ava program is executed by the JVM also helps to make it secure. Because the JVM is in
control, it can contain the program and prevent it from generating side effects outside of the system. As
you will see, safety is also enhanced by certain restrictions tthat
hat exist in the Java language.

Contact Us on: +91 9405224852 / codesytraining@gmail.comPage 7


CODESY TRAINING CENTRE

Features of Java:
Simple :

Java was designed to be easy for the professional programmer to learn and use effectively. Java derives
its syntax from the C programming language and many of the object oriented features from C++. So if
you have knowledge of C or C++, learning Java will be very easy for you.

Secure:

As discussed earlier, Java source code will be converted to Byte Code by compiler and then JVM
executes ByteCode. Hence ByteCode is executed within JVM only and prevents it from accessing other
parts of our computer and generating side effects outside of the system.

Portable:

As discussed earlier, Java source code will be converted to Byte Code by the compiler and then JVM
executes ByteCode. Translating a Java program into bytecode makes it much easier to run a program in
a wide variety of environments because only the JVM needs to be implemented for each platform. Once
the run-time package exists for a given system, any Java program can run on it.

Architecture-neutral:

One of the main problems while designing Java was that no guarantee existed that if you wrote a
program today, it would 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.

But Java developers developed Java with the goal “write once; run anywhere, any time, forever.” With
the help of JVM, Java developers achieved this goal.

Interpreted and High performance:

As described earlier, Java enables the creation of cross-platform programs by compiling source code into
an intermediate representation called Java bytecode. This Byte code can be executed on any system
that implements the Java Virtual Machine. Java bytecode was carefully designed so that it would be easy
to translate directly into native machine code for very high performance by using a just-in-time
compiler.

Robust:

Java helps programmers to create robust programs by

- Finding your mistakes early in program development -> Java is a strictly typed language and hence it
checks our code at compile time and at run time as well. Hence hard-to-track-down bugs that often turn
up in hard-to-reproduce run-time situations are simply impossible to create in Java.

- Freeing you from having to worry about many of the most common causes of programming errors - >
Java provides automatic garbage collection for unused objects and hence you don't need to worry about

Contact Us on: +91 9405224852 / codesytraining@gmail.comPage 8


CODESY TRAINING CENTRE

memory management mistakes. Also Java provides object- oriented exception handling to handle
exceptions like divide by Zero, File Not Found etc.

Multithreaded:

Java supports multithreaded programming, which allows you to write programs that do many things
simultaneously. The Java run-time system provides a solution for multi process synchronization that
enables you to construct smoothly running interactive systems. Java’s easy-to-use approach to
multithreading allows you to think about the specific behavior of your program, not the multitasking
subsystem.

Distributed:

Java is designed for the distributed environment of the Internet because it handles TCP/IP protocols. In
fact, accessing a resource using a URL is not much different from accessing a file. Java also supports
Remote Method Invocation (RMI). This feature enables a program to invoke methods across a network.

Dynamic:

In Java, many times method calls will be decided at run time (Method overriding). This makes it possible
to dynamically link code in a safe and expedient manner.

Most of the character of Java is inherited from C and C++ programming languages.

From C language –> Java has taken its Syntax

From C++ language -> Most of Object Oriented features of Java are taken from C++

Contact Us on: +91 9405224852 / codesytraining@gmail.comPage 9

You might also like