Monday, December 29, 2014

About the interpreter in Java



We can run Java on most platforms provided a platform must has a Java interpreter. That is why Java applications are platform independent. Java interpreter translates the Java bytecode into the code that can be understood by the Operating System. Basically, A Java interpreter is a software that implements the Java virtual machine and runs Java applications. As the Java compiler compiles the source code into the Java bytecode, the same way the Java interpreter translates the Java bytecode into the code that can be understood by the Operating System.
When a Java interpreter is installed on any platform that means it is JVM (Java virtual machine) enabled platform. It (Java Interpreter) performs all of the activities of the Java run-time system. It loads Java class files and interprets the compiled byte-code. You would be glad to know that some web browsers like Netscape and the Internet Explorer are Java enabled. This means that these browsers contain Java interpreter. With the help of this Java interpreter we download the Applets from the Internet or an intranet to run within a web browser. The interpreter also serves as a specialized compiler in an implementation that supports dynamic or "just in time," compilation which turns Java byte-code into native machine instructions. 
Interpreters are not much different than compilers. They also convert the high level language into machine readable binary equivalents. Each time when an interpreter gets a high level language code to be executed, it converts the code into an intermediate code before converting it into the machine code. Each part of the code is interpreted and then execute separately in a sequence and an error is found in a part of the code it will stop the interpretation of the code without translating the next set of the codes. Outlining the basic working of the interpreter the above figure shows that first a source code is converted to an intermediate form and then that is executed by the interpreter.

Sunday, December 28, 2014

Explain about the security aspect of Java

The Java platform provides a number of features designed to improve the security of Java applications. This includes enforcing runtime constraints through the use of the Java Virtual Machine (JVM), a security manager that sandboxesuntrusted code from the rest of the operating system, and a suite of security APIs that Java developers can utilise. Despite this, criticism has been directed at the programming language, and Oracle, due to an increase in malicious programs that revealed security vulnerabilities in the JVM, which were subsequently not properly addressed by Oracle in a timely manner.
The binary form of programs running on the Java platform is not native machine code but an intermediate bytecode. The JVM performs verification on this bytecode before running it to prevent the program from performing unsafe operations such as branching to incorrect locations, which may contain data rather than instructions. It also allows the JVM to enforce runtime constraints such as array bounds checking. This means that Java programs are significantly less likely to suffer from memory safety flaws such as buffer overflow than programs written in languages such as C which do not provide such memory safety guarantees.

The platform does not allow programs to perform certain potentially unsafe operations such as pointer arithmetic or unchecked type casts. It also does not allow manual control over memory allocation and deallocation; users are required to rely on the automatic garbage collection provided by the platform. This also contributes to type safety and memory safety.

About Java SDK

The Java Development Kit (JDK) is a software development environment used for developing Java applications and applets. It includes the Java Runtime Environment (JRE), an interpreter/loader (java), a compiler (javac), an archiver (jar), a documentation generator (javadoc) and other tools needed in Java development.
Java developers are initially presented with two JDK tools, java and javac. Both are run from the command prompt. Java source files are simple text files saved with an extension of .java. After writing and saving Java source code, the javac compiler is invoked to create .class files. Once the .class files are created, the 'java' command can be used to run the java program.

For developers who wish to work in an integrated development environment (IDE), a JDK bundled with Netbeans can be downloaded from the Oracle website. Such IDEs speed up the development process by introducing point-and-click and drag-and-drop features for creating an application.

There are different JDKs for various platforms. The supported platforms include Windows, Linux and Solaris. Mac users need a different software development kit, which includes adaptations of some tools found in the JDK.

JDK contents

The JDK has as its primary components a collection of programming tools, including:

  • java – the loader for Java applications. This tool is an interpreter and can interpret the class files generated by the javac compiler. Now a single launcher is used for both development and deployment. The old deployment launcher, jre, no longer comes with Sun JDK.
  • javac – the compiler, which converts source code intoJava bytecode
  • jar – the archiver, which packages related class librariesinto a single JAR file. This tool also helps manage JAR files.
  • javadoc – the documentation generator, which automatically generates documentation from source code comments
  • jdb – the debugger
  • jps – the process status tool, which displays process information for current Java processes
  • javap – the class file disassembler
  • appletviewer – this tool can be used to run and debug Java applets without a web browser
  • javah – the C header and stub generator, used to write native methods
  • javaws – the Java Web Start launcher for JNLP applications
  • extcheck – a utility which can detect JAR-file conflicts
  • apt – the annotation-processing tool
  • jhat – (experimental) Java heap analysis tool
  • jstack – (experimental) utility which prints Java stack traces of Java threads
  • jstat – (experimental) Java Virtual Machine statistics monitoring tool

Friday, December 26, 2014

Explain about the dynamic behavior of core java


Dynamic Behaviours  is a design pattern similar to the Chain of Responsibility pattern, is ideally suited for applications that must change the class of objects fluidly at runtime.
Java is entirely built on Dynamic memory allocation . i.e the memory will be allocated dynamically at the time of creating objects. The unused objects are automatically  removed by the garbage collector.
Java supports runtime polymorphism which is also termed as dynamic polymorphism. Which states that if the super class method is overridden in the sub class then the JVM identifies the appropriate method invocation at run time dynamically.

Explain about the performance aspects of Core Java


Performance has been an important issue for Java developers with any language. Performance includes both speed of execution and the memory, the process, occupies. That is, how to make our program run faster and at the same time using less memory and disk space. There is no correct formula on performance because different applications have different characteristics and bottlenecks and also performance differs across different hardware, operating systems and development tools like virtual machines and compilers. Based on the performance issues in Java  we can make suitable design and implementation options for specific tasks.
Most of the latest versions of Java tools offer various approaches to increase performance compared to the basic JDK1.0 version of byte code interpretation. The tools approaches includes compiling the bytecode into machine code at runtime. Some areas where performance enhancement can be done include  a) methodinlining and adaptive inlining where methods are inlined basing on their use and number of calls  b) synchronization  c) compiling Java source code into native code of the operating system etc. As a designer, examining and choosing of appropriate tools is also important. Using a JVM with built-in JIT compiler increases the performance 40 times. Choosing the right tool is very important rather than trying to tune the code for performance aspects.
Most of the times the programmer writes the code without providing the default constructor.  If the programmer does not provide his own default constructor, the JVM creates one and supplies and this takes time. So, always provide a default constructor in your program.