What is Java?
A brief summary.
Java is a high-level computer programming language that was developed in Sun Microsystems by James Gosling in 1991 but has now owned by Oracle.
- Fun Fact: Java was originally called OAK because of the tree that stood outside James Gosling’s office. Was later renamed Java because trademark research discovered that OAK was already used by Oak Technology or because the large amount of coffee programmers drink while writing code using this program. I tend to think it’s the latter.
- Java is based off C++ language. C++ is an intermediate-level computer programming language.
- Java has what some call platform independence which loosely means that programs build in Java can be run on many different types of Operating Systems.
- Java runs on Java Runtime Environment (JRE) and the good thing about the JRE is that there are many different versions of it that can be installed in a wide variety of Operating systems, hence making Java programs be able to run in: Windows, Macintosh, Unix, Linux and even cell phones.
- It is generally purposed to be Object-Oriented: Which means that each java program is build out of elements called objects. These objects can represent either some real-world object or an abstract concept.
- Objects in Java can have inside them information. For example you can have an Object of type TV Show that has data inside it like Director, Actors, producers, etc.
- When you want to know the attributes of the object: You are talking about it’s current state.
Java has garbage collection at first when my professor started talking about garbage collection I really didn’t understand it. But since I’m in my second year studying CSC here is what I do know about GC.
- Garbage collection diminishes a java programmer’s need to keep tabs in memory management. Unlike where in C++ memory management is a very essential part when writing code. Less time worrying about memory management gives the programmer more time to focus on their logic when writing code in Java.
- Objects in Java are created on heaps. (Will cover that in later blogs.)
Garbage collection in Java is run by a daemon thread called Garbage Collector.
What is a daemon thread?
“A daemon thread is a thread, that does not prevent the JVM from exiting when the program finishes but the thread is still running. An example for a daemon thread is the garbage collection.” by PartlyCloudy in StackOverflow.com
- The Java Virtual Machine allows the Garbage Collection mechanism which reclaims heap space from objects created in Java that are eligible for Garbage Collection.
- As your writing code you will find out that you can’t invoke or call on Garbage Collection in Java. Java will utilize Garbage collection if the JVM thinks it needs it based on Java heap size
- Designed for easy web/internet applications.
Java is simpler because it has no pointers, fixes some annoying features of C++, has garbage collection as mentioned above and it has a rich pre-defined class library.
- Pre-defined Class Libraries just means that Java has loadable libraries that can be called at run-time. This goes back to the fact that Java is not OS dependent and cannot rely on platform-native libraries. Hence Java provides itself with standard class libraries. Containing some functions that are common to modern OS.
- Dynamic and Multi-threaded: Multiple concurrent threads of execution can run simultaneously. Java uses a complex set of synchronization primitives to achieve this. It is dynamic because the interfaces contribute flexibility and reusability in code by specifying a set of methods an object is allowed to perform, but gives room on how these methods should be implemented. Java also is designed to adapt to evolving environment. The standard class libraries can freely add new methods and instance variables without any effect on their clients.
- Java has better code organization and easy to reuse.
- Almost all data types are objects.
Java is an interpreted language not a compiled one like Objective-C.
- The Java compiler generates byte-codes, not not machine code. These byte-codes are platform-independent hence making it cross-platform compatible. At run-time this generated byte-code is translated to machine readable instructions. Java Run-time Environment is in fact an OS. The JRE is the interpreter that is running your program. Java requires the run-time support. All these features make Java a multi-purpose language.
- As long as you have a JVM that is compatible with your OS, your ready to use Java. This is what makes Java very popular nowadays.
- Java is very reliable and secure. But it is only reliable and secure as the application that is build on it. Memory corruptions or unauthorized memory accesses are impossible. Extensive compile-time and run-time error checking is done. Automated garbage collection keeps track of objects usage. Memory allocation model is great defense. Access restrictions are forces. Ex. private, public, protected.
- All functions are associated with objects.
- Focuses mainly on objects and methods manipulating the data.
One thing that is important to remember when programming in Java is that Java is CASE SENSITIVE. When I first started writing code in Java I found this concept to be the most annoying one. Also never for get your semi-colons.
Some key concepts I’ve learned as a first year CSC and IT major are:
- Algorithm analysis in a computer science course is essential.
- If an algorithm is not efficient a faster CPU will not help it in the long run.
- Software must make productive use of resources such as CPU time and memory.