chapter1 : java basics
Post on 09-Feb-2017
377 Views
Preview:
TRANSCRIPT
Subject : Advance Java (J2EE)
Class : SYMCA
Subject Teacher : Prof. V. V Shaga
Unit-IJava Basics
Contents
• Introduction• Java Buzzwords• Byte code• Sample Java Program• Type Conversion and Casting
Introduction• JAVA is high level third generation
programming language• JAVA is a Platform for application development• JAVA derives much of its character from C and
C++• IDE’s for JAVA are :
Notepad,Notepad++,Jcreator, TextPad, DosEditor, Eclipse
Java BuzzwordsSimple- C++ Programmers can move to java will require less efforts Secure- don’t instruct commands to the machine directly. Java program fully secured under the control of the JVMRobust -Platform Independent ,Object Oriented ,Programming Language, Memory management ,Exception HandlingMultithreaded - multiple task simultaneouslyArchitecture-neutral - developed and executed anytime in future. No effect of changing environments like hardware, processor, Operating system.
Java BuzzwordsPortable - ability to run the program on any platform and no dependency on the underlying hardware Object-oriented - object oriented model in Java is simple and easy to extendInterpreted - JVM interprets the ByteCode into Machine instructions during runtime.High performance - interpret only the piece of the code that is required to execute and untouch the rest of the codeDistributed - Remote Method Invocation (RMI) using which a program can invoke method of another program across a network and get the output.Dynamic - update the pieces of libraries without affecting the code using it
The Bytecode
• Not executable code• It is a highly optimized set of instructions
designed to be executed by the java run time system which is called JVM
.Java file
JAVA Complier
BYTE CODE
.class file
JAVA VIRTUAL MACHINE
101010101
interpreted & executedby
Executable Machine Code
JIT Complier
101010101
Sample Programclass First { public static void main(String args[]) { System.out.println(“welcome in java”); System.out.println(“This is simple java
program”); } }
Assignment
1. Explain in detail java buzzwords.2. What is JVM? Explain the execution of java
program.3. Write the program to compute the area of circle.
Date : 04-Aug-2014Submission date : 11-Aug-2014
Type Conversion and Casting• Implicit conversion(automatic conversion)– The two types are compatible– The destination type is larger than source
type. byteshortintlongfloatdouble
Java will automatically convert int expressions to double values without loss of informationint i = 5;double x = i + 10.5;
Type Conversion and Casting• Explicit conversion– Two types are incompatible– Syntax for conversion : (target-type) value;double float longintshortbyte
Example :To convert double expressions to int requires a typecasting operation and truncation will occuri = (int) (10.3 * x)
Some more Examples on Type-Casting..byte b;int i=257;double d=323.142;
1) Convert int to byte b=(byte)i; Ans = 1
2) Convert double to inti=(int)d; Ans= 323
3) Convert double to byteb=(byte)d;Ans = 67
Assignments1.Write down about data types in
java. [Hint: write only how many bits,
range and its default value and example]
Eg:Short:It is 16 bit integer data type. Value range from -32768 to 32767. Default value zero. example: short s=11;
top related