Unit-I 1JavaBAsic Intro
Unit-I 1JavaBAsic Intro
PROGRAMMI
NG
NEED OF PROGRAMMING LANGUAGE
INTRODUCTION
• started by extending the C++ which was currently going on at that time.
• Initially it was designed for small, embedded systems in electronic appliances like
set-top boxes.
• Firstly, it was called "Greentalk" by James Gosling, and the file extension was .gt.
• After that, it was called Oak and was developed as a part of the Green project.
• Java is an island in Indonesia where the first coffee was produced (called Java
coffee). It is a kind of espresso bean. Java name was chosen by James Gosling
JavaScript PHP
Java
OOP R-
Languages
programming
Kotlin Ruby
C++
JAVA FEATURES (BUZZWORDS)
• Simple
• Object-Oriented
• Portable
• Platform independent
• Secured
• Robust
• Architecture neutral
• Interpreted
• High Performance
• Multithreaded
• Distributed
• Dynamic
SIMPLE
• Java is very easy to learn, and
• Its syntax is simple, clean and easy to understand.
• According to Sun Microsystem, Java language is a simple programming language because:
• Java syntax is based on C++
• Java has removed many complicated and rarely-used features.
• Explicit pointers, operator overloading, etc.
• There is no need to remove unreferenced objects because there is an Automatic Garbage
Collection in Java.
OBJECT-ORIENTED
• Java is an object-oriented programming language.
• Everything in Java is an object.
• Object-oriented means we organize software as a combination of different types of
objects that incorporate both data and behavior.
• Basic concepts of OOPs are object, class, inheritance, polymorphism, abstraction,
encapsulation.
PLATFORM INDEPENDENT
• it is different from other languages like C, C++, etc. which are compiled into platform specific
machines .
• Java is guaranteed to be write-once, run-anywhere language.
• On compilation Java program is compiled into bytecode. This bytecode is platform independent and
can be run on any machine, plus this bytecode format also provide security. Any machine with Java
Runtime Environment can run Java Programs.
PORTABLE
• Java is portable because it facilitates you to carry the Java
bytecode to any platform.
• It doesn't require any implementation.
• Everything related to storage is predefined, example: size of
primitive data types
• The WORA (Write Once Run Anywhere) concept and
platform-independent feature make Java portable
ROBUST
• Java is robust because: it is capable of handling unexpected termination of a
program.
• Exception handling and the type checking mechanism in Java.
• Int occupies 4 bytes of memory for both 32 and 64-bit architectures in Java.
DISTRIBUTED
• Java is also a distributed language.
• Programs can be designed to run on computer networks.
• Java has a special class library for communicating using TCP/IP protocols.
• Creating network connections is very much easy in Java as compared to C/C++.
INTERPRETED
• The interpreter converts the source code line-by-line during the RUN Time.
• responsible for reading and executing the program.
• Java programming language uses both a compiler and an interpreter.
• Java programs are compiled to generate bytecode files then JVM interprets the bytecode file during
execution. Along with this JVM also uses a JIT compiler (it increases the speed of execution).
MULTI-THREADED
• Java multithreading feature makes it possible to write program that can do many tasks
simultaneously.
• Benefit of multithreading is that it utilizes same memory and other resources to execute
multiple threads at the same time, like While typing, grammatical errors are checked along.
4) JavaFX
19
Java Platforms / Editions
20
Java Platforms / Editions
2) Java EE (Java Enterprise Edition)
4) JavaFX
• String args[ ]
• It declares a parameter named args, which is an array of instances of the class String.
• It stores Java command line arguments and is an array of type java.lang.String class.
• Execute (JRE)
• Short
• Short is a 16-bit signed two’s complement integer. It stores whole numbers with values ranging from -
32768 to 32767. Its default value is 0.
• Syntax:
• short shortVariable;
• Int
• Int is a 32-bit signed two’s complement integer that stores integral values ranging from 2147483648 (-
2^31) to 2147483647 (2^31 -1). Its default value is 0.
• Syntax:
• int intVariable;
• Long
• long is a 64-bit signed two’s complement integer that stores values ranging from -
9223372036854775808(-2^63) to 9223372036854775807(2^63 -1). It is used when we need a range of
values more than those provided by int. Its default value is 0L. This data type ends with ‘L’ or ‘l’.
• Syntax:
• long longVariable;
VARIABLES
• A variable is a memory location or storage area to hold the data.
• Each variable should be given a unique Name (Identifier) to indicate the Storage Area.
JAVA COMMAND LINE ARGUMENTS
class CommandLineExample
{
public static void main(String args[])
{
System.out.println("Your first argument is: "+args[0]);
}
}
INPUT / OUTPUT FUNCTIONS IN JAVA
READING INPUT FROM CONSOLE
• Input can be given either from file or keyword. In java, input can be read from console in 3 ways:
• BufferedReader :- use the class “BufferedReader” and create the object “bufferedreader”. We
also take integer value and fetch string from the user.
• Scanner: It accepts multiple inputs from file or keyboard and divides into tokens. It has methods to
different types of input (int, float, string, long, double, byte) where tokenizer does not have.
SCANNER CLASS
• this class belongs to the java.util package.
• import java.util.Scanner;
• create an object of the Scanner class in java, you need to pass System.in in the constructor of the
Scanner class. System is a class in Java and in is a static variable of type InputStream . System.in
represents the standard input stream.
• Scanner input = new Scanner(System.in);
FUNCTION DESCRIPTION