Java Buzzwords/Features
- Simple
- Java was designed to be easy for a professional programmer to learn and use effectively.
- It's simple and easy to learn if you already know the basic concepts of Object Oriented Programming.
- If you are an experienced C++ programmer, moving to Java will require very little effort. Because Java inherits the C/C++ syntax and many of the object-oriented features of C++, most programmers have little trouble learning Java.
- Java has removed many complicated or rarely-used features of C++, for example, pointers, operator overloading, etc.
- Java was simple till Java 1.4. Later many new features were added to the language to make it powerful (but complex too).
- Object Oriented
- Java is a object-oriented programming language.
- Almost the "Everything is an Object" paradigm. All program code and data reside within objects and classes.
- The object model in Java is simple and easy to extend.
- Java comes with an extensive set of classes, arranged in packages that can be used in our programs through inheritance.
- The basic concepts of OOPs are:
- Object
- Class
- Abstraction
- Encapsulation
- Inheritance
- Composition
- Polymorphism
- Distributed
- Java is designed to create distributed applications connected over the network.
- Java applications can access remote objects on the Internet as easily as they can do in the local system.
- Java is designed for the distributed environment of the Internet. It handles TCP/IP protocols.
- Compiled and Interpreted
- Usually, a computer language is either compiled or interpreted. Java combines both this approach and makes it a two-stage system.
- Compiled: Java enables the creation of cross-platform programs by compiling them into an intermediate representation called Java Bytecode.
- Interpreted: Bytecode is then interpreted, which generates machine code that can be directly executed by the machine/CPU.
- Robust
- It provides many features that make the program execute reliably in a variety of environments.
- Java is a strictly typed language. It checks code both at compile time and runtime.
- Java takes care of all memory management problems with garbage collection.
- Exception handling captures all types of serious errors and eliminates any risk of crashing the system.
- Secure
- When a Java Compatible Web browser is used, downloading applets can be done safely without fear of infection or malicious intent.
- Java achieves this protection by confining a Java program to the Java execution environment and not allowing it to access other parts of the computer.
- Architecture Neutral
- Java language and Java Virtual Machine helped in achieving the goal of WORA - Write (Compile) Once Run Anywhere.
- Java byte code is interpreted and converted into CPU machine code/native code. So Java byte code can execute on any CPU architecture (on which JVM is available) like x86, SPARC, PPC, MIPS, etc.
- Portable
- Java is portable because of the Java Virtual Machine (JVM). The JVM is an abstract computing machine that provides a runtime environment for Java programs to execute.
- The JVM provides a consistent environment for Java programs to run on, regardless of the underlying operating system. Java program can be written on one device and run on any other device with a JVM installed, without any changes or modifications.
- High Performance
- Java performance is high because of the use of bytecode.
- The bytecode is used so that it can be efficiently translated into native machine code by JIT compiler (in JVM).
- Multithreaded
- Multithreaded Programs handle multiple tasks simultaneously (within a process), which is helpful in creating interactive, networked programs.
- Java supports multi-process/thread communication and synchronization.
- Dynamic
- Java is capable of linking in new class libraries, methods, and objects.
- Java classes have run-time type information (reflection) that is used to verify and resolve accesses to objects/members at runtime. This makes it possible to dynamically link code in a safe and expedient manner.
CLASSPATH
- CLASSPATH: Contains a set of directories separated by ; (Windows) or : (Linux).
- Java's environment variable by which one can inform Java compiler, application launcher, JVM and other Java tools about the directories in which Java classes/packages are kept.
- CLASSPATH variable can be modified using "set" command (Windows) or "export" command (Linux).
- Set/Modified using:
- Windows:
set CLASSPATH=\\\\path\\\\to\\\\set\\\\%CLASSPATH%
- Linux:
export CLASSPATH=/path/to/set:$CLASSPATH
- Display current CLASSPATH:
- Windows:
set CLASSPATH
- Linux:
echo $CLASSPATH
- Compilation and Execution (source code in "src" directory and .class file in "bin" directory)
- terminal> cd \path\of\src directory
- terminal> javac -d ..\bin Program.java
- terminal> set CLASSPATH=..\bin
- terminal> java Program
Console Input/Output
- Java has several ways to take input and print output. Most popular ways in Java 8 are given below: