Pages

Thursday, 28 April 2022

Feature of Java or Java buzzwords.

The primary objective of Java programming language creation was to make it a portable, simple, and secure programming language. Apart from this, there are also some excellent features that play an important role in the popularity of this language. The features of Java are also known as Java buzzwords.


The following are the most important features of the Java language given below.
  1. Object-Oriented
  2. Simple
  3. Secured
  4. Platform independent
  5. Robust
  6. Portable
  7. Architecture neutral
  8. Dynamic
  9. Interpreted
  10. High Performance
  11. Multi-threaded
  12. Distributed
1. Object-oriented
Java is an object-oriented programming language. Everything in Java is an object. Object-oriented means we organize our software as a combination of different types of objects that incorporate both data and behavior.

Object-oriented programming (OOPs) is a methodology that simplifies software development and maintenance by providing some rules.

Basic concepts of OOPs are:
Object:
  • Instance of a class
  • Real time entity
Class:
  • Provides the definition of object
  • collection of objects
Inheritance:
  • Creating new class from already existing class
  • Object of one class acquires the property of object of another class
Polymorphism:
  • Poly - Many
  • Morphic - Forms
  • An operation exhibits different behaviors in different instances Example: Operator Overloading ,Method overloading 
Abstraction:
  • Representing essential feature without including background details
Encapsulation:
  • Wrapping/Binding up of variables (data) and methods(code) into a single unit 

2. 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++ (so easier for programmers to learn it after C++).
Java has removed many complicated and rarely-used features, for example, explicit pointers, operator overloading, etc.
There is no need to remove unreferenced objects because there is an Automatic Garbage Collection in Java.

3.Secured
Java is best known for its security. With Java, we can develop virus-free systems. 
Java is secured because:
No explicit pointer
Java Programs run inside a virtual machine sandbox

Classloader: Classloader in Java is a part of the Java Runtime Environment (JRE) which is used to load Java classes into the Java Virtual Machine dynamically. It adds security by separating the package for the classes of the local file system from those that are imported from network sources.

Bytecode Verifier: It checks the code fragments for illegal code that can violate access rights to objects.

Security Manager: It determines what resources a class can access such as reading and writing to the local disk.

Java language provides these securities by default. Some security can also be provided by an application developer explicitly through SSL, JAAS, Cryptography, etc.

4.Platform Independent
Java is platform-independent because it is different from other languages like C , C++ etc. which are compiled into platform specific machines while Java is a write once, run anywhere language. A platform is the hardware or software environment in which a program runs.

There are two types of platforms software-based and hardware-based. 
The Java platform differs from most other platforms in the sense that it is a software-based platform that runs on top of other hardware-based platforms. It has two components:

Runtime Environment
API(Application Programming Interface)
Java code can be executed on multiple platforms, for example, Windows, Linux, Sun Solaris, Mac/OS, etc. Java code is compiled by the compiler and converted into bytecode. This bytecode is a platform-independent code because it can be run on multiple platforms, i.e., Write Once and Run Anywhere (WORA).

5.Robust
Robust means it is strong. Java is robust because:
It uses strong memory management.
There is a lack of pointers that avoids security problems.
Java provides automatic garbage collection which runs on the Java Virtual Machine to get rid of objects which are not being used by a Java application anymore.
There are exception handling and the type checking mechanism in Java. All these points make Java robust.

6.Portable
Java is portable because it facilitates you to carry the Java bytecode to any platform. It doesn't require any implementation.

7. Architecture-neutral
Java is architecture-neutral because there are no implementation-dependent features, for example, the size of primitive types is fixed.

In C programming, int data type occupies 2 bytes of memory for 32-bit architecture and 4 bytes of memory for 64-bit architecture. However, it occupies 4 bytes of memory for both 32 and 64-bit architectures in Java.

8.Dynamic
Java is a dynamic language. It supports the dynamic loading of classes. It means classes are loaded on demand. It also supports functions from its native languages, i.e., C and C++.
Java supports dynamic compilation and automatic memory management (garbage collection).

9. Interpreted
It is used to interact with JVM (Java Virtual Machine) and loads the .class file into class loader



Class Loader: The class loader reads the .class file and save the byte code in the method area.

Method Area: There is only one method area in a JVM which is shared among all the classes. This holds the class level information of each .class file.

Heap: Heap is a part of JVM memory where objects are allocated. JVM creates a Class object for each .class file.

Stack: Stack is a also a part of JVM memory but unlike Heap, it is used for storing temporary variables.

PC Registers: This keeps the track of which instruction has been executed and which one is going to be executed. Since instructions are executed by threads, each thread has a separate PC register.

Native Method stack: A native method can access the runtime data areas of the virtual machine.

Native Method interface: It enables java code to call or be called by native applications. Native applications are programs that are specific to the hardware and OS of a system.

Garbage collection: A class instance is explicitly created by the java code and after use it is automatically destroyed by garbage collection for memory management.

10. High-performance
Java is faster than other traditional interpreted programming languages because Java bytecode is "close" to native code. It is still a little bit slower than a compiled language (e.g., C++). Java is an interpreted language that is why it is slower than compiled languages, e.g., C, C++, etc.

11.Multi-threaded
A thread is like a separate program, executing concurrently. We can write Java programs that deal with many tasks at once by defining multiple threads. The main advantage of multi-threading is that it doesn't occupy memory for each thread. It shares a common memory area. Threads are important for multi-media, Web applications, etc.

12.Distributed
Java is distributed because it facilitates users to create distributed applications in Java. RMI (Remote Method Invocation) and EJB (Enterprise Java Beans)are used for creating distributed applications. This feature of Java makes us able to access files by calling the methods from any machine on the internet.

Tuesday, 26 April 2022

Java Operators

Operator in Java is a symbol that is used to perform operations. For example: +, -, *, / etc.

There are many types of operators in Java which are given below:
  1. Unary Operator
  2. Arithmetic Operator
  3. Shift Operator
  4. Relational Operator
  5. Bit wise Operator
  6. Logical Operator
  7. Ternary / Conditional Operator
  8. Assignment Operator
  9. Special Operator
Java Operator Precedence:

1. Unary Operators:
Java Unary Operator Example 1: ++ and --

public class OperatorExample
{  
public static void main(String args[])
{  
int x=10;  
System.out.println(x++);//10 (11)  
System.out.println(++x);//12  
System.out.println(x--);//12 (11)  
System.out.println(--x);//10  
}
}  

Output:
10
12
12
10

Java Unary Operator Example 2: ++ and --
public class OperatorExample
{  
public static void main(String args[])
{  
int a=10;  
int b=10;  
System.out.println(a++ + ++a);//10+12=22  
System.out.println(b++ + b++);//10+11=21  
}
}  
Output:
22
21

Java Unary Operator Example 3: ~ and !
public class OperatorExample
{  
public static void main(String args[])
{  
int a=10;  
int b=-10;  
boolean c=true;  
boolean d=false;  
System.out.println(~a);//-11 (minus of total positive value which starts from 0)  
System.out.println(~b);//9 (positive of total minus, positive starts from 0)  
System.out.println(!c);//false (opposite of boolean value)  
System.out.println(!d);//true  
}
}  

Output:
-11
9
false
true

2. Arithmetic Operators {(5) : +, - ,* ,/ ,% }
Java arithmetic operators are used to perform addition, subtraction, multiplication, and division. They act as basic mathematical operations.

Java Arithmetic Operator Example
public class OperatorExample
{  
public static void main(String args[])
{  
int a=10;  
int b=5;  
System.out.println(a+b);//15  
System.out.println(a-b);//5  
System.out.println(a*b);//50  
System.out.println(a/b);//2  
System.out.println(a%b);//0  
}
}  
Output:
15
5
50
2
0

Java Arithmetic Operator Example: Expression
public class OperatorExample
{  
   public static void main(String args[])
   {  
     System.out.println(10*10/5+3-1*4/2);  
   }
}  
Output:
21

3. Shift Operators:{(3) : >> , << , >>>}
Java Left Shift Operator:
The Java left shift operator << is used to shift all of the bits in a value to the left side of a specified number of times.
Java Left Shift Operator Example
public class OperatorExample
{  
public static void main(String args[])
{  
System.out.println(10<<2);//10*2^2=10*4=40  
System.out.println(10<<3);//10*2^3=10*8=80  
System.out.println(20<<2);//20*2^2=20*4=80  
System.out.println(15<<4);//15*2^4=15*16=240  
}
}  
Output:
40
80
80
240

Java Right Shift Operator:
The Java right shift operator >> is used to move the value of the left operand to right by the number of bits specified by the right operand.

Java Right Shift Operator Example
public OperatorExample
{  
public static void main(String args[])
{  
System.out.println(10>>2);//10/2^2=10/4=2  
System.out.println(20>>2);//20/2^2=20/4=5  
System.out.println(20>>3);//20/2^3=20/8=2  
}
}  
Output:
2
5
2

Java Shift Operator Example: >> vs >>>
public class OperatorExample
{  
public static void main(String args[])
{  
    //For positive number, >> and >>> works same  
    System.out.println(20>>2);  
    System.out.println(20>>>2);  
    //For negative number, >>> changes parity bit (MSB) to 0  
    System.out.println(-20>>2);  
    System.out.println(-20>>>2);  
}
}  
Output:
5
5
-5
1073741819

4.Relational Operator{(6) : <,>,<=,>=,==,!=}

Java Relational Operator Example:
public class RelationalOperators
{
public static void main(String args[])
{
int a = 10;
int b = 20;
System.out.println("a == b = " + (a == b) ); 
System.out.println("a != b = " + (a != b) ); 
System.out.println("a > b = " + (a > b) ); 
System.out.println("a < b = " + (a < b) ); 
System.out.println("b >= a = " + (b >= a) ); 
System.out.println("b <= a = " + (b <= a) );
}
}

Output
a == b = false 
a != b = true 
a > b = false 
a < b = true
b >= a = true 
b <= a = false


5.Bit wise Operator{(7) : &,|,~,^,>>,<<,>>>}
1.Bitwise AND (&) represented as & operator in C takes two numbers as operands and does AND gate function on every bit of two numbers. The result of AND is 1 only if both bits are 1.
For example:
  a  = 14 --------------1110     
  b  = 9    -------------1001
(Result a&b : 8) ---1000

2.Bitwise inclusive OR (|) represented as | operator in C takes two numbers as operands and does OR gate function on every bit of two numbers. The result of OR is 1 only if any one of the bits are 1.
For example:
  a  = 14  -------------1110     
  b  = 9    -------------1001
(Result a|b: 15)  ---1111

3.Bitwise exclusive OR ( ^) represented as ^ operator in C takes two numbers as operands and does x-OR gate function on every bit of two numbers. The result of OR is 1 only if any one of the bits are 1.
For example:
  a  = 14  -------------1110     
  b  = 9    -------------1001
(Result a^b: 7)  ---0111

4.Bitwise NOT(~) represented as ~ operator in C takes one number as operands and does NOT gate function  on every bit.
For example:
  a  = 14  -------------1110     
(Result ~a: -15)  ---1's complement is  0001 
To this result perform 2's complement i.e negative number 
  1110
+       1
---------
  1111 which is -15

For example:
  a  = 9  -------------1001     
(Result ~a: -10)  ---1's complement is  0110 
To this result perform 2's complement i.e negative number 
  1001
+       1
---------
   1010 which is -10

5.Bitwise right shift >> represented as >> operator in C takes one number as operands and does right shift one bit function  on every bit.
For example:
  a  = 9      -------------1001     
(Result a>>2: 2)  ---  0010

6.Bitwise left shift << represented as << operator in C takes one number as operands and does left shift one bit function  on every bit.
For example:
  a  = 9   --------------------1001     
(Result a<<2: 36)  --- 100100


Java Bitwise Operator Example:
public class BitwiseOperator
{
public static void main(String args[])
{
int p = 60; /* 60 = 0011 1100 */
int q = 13; /* 13 = 0000 1101 */ 
int c = 0;
c = p & q; /* 12 = 0000 1100 */ 
System.out.println("p & q = " + c );
c = p | q; /* 61 = 0011 1101 */ 
System.out.println("p | q = " + c );
c = p ^ q; /* 49 = 0011 0001 */ 
System.out.println("p ^ q = " + c );
c = ~p; /*-61 = 1100 0011 */ 
System.out.println("~p = " + c );
c = p << 2; /* 240 = 1111 0000 */
System.out.println("p << 2 = " + c );
c = p >> 2; /* 15 = 1111 */ 
System.out.println("p >> 2 = " + c );
c = p >>> 2; /* 15 = 0000 1111 */
System.out.println("p >>> 2 = " + c );
}
}

Output
p & q = 12 
p | q = 61 
p ^ q = 49
~p = -61
p << 2 = 240
p >> 2 = 15
p >>> 2 = 15


6.Logical Operator{(3) : &&,||,|}
Logical Operators are used to combine two or more conditions/constraints. The result of the operation of a logical operator is a Boolean value either true or false.

For example, the logical AND represented as ‘&&’ operator in C returns true when both the conditions under consideration are satisfied. Otherwise it returns false. 
Therefore, a && b returns true when both a and b are true (i.e. non-zero)

a

b

a &&b

0

0

0

0

1

0

1

0

0

1

1

1


For example, the logical OR represented as ‘||’ operator in C returns false when both the conditions under consideration are not satisfied. Otherwise it returns true. 
Therefore, a || b returns false when both a and b are false (i.e. zero)

a

b

a ||b

0

0

0

0

1

1

1

0

1

1

1

1

For example, the logical NOT represented as ‘|’ operator in C returns true for the given false condition similarly it gives false for the given true condition  
Therefore, if a is  true then the logical output  of a is false, similarly if a is false then the logical output is true

a

!a

0

1

1

0


Java Logical Operator Example: 
public class LogicalOperators
{
public static void main(String args[])
{
boolean p = true; 
boolean q = false;
System.out.println("p && q = " + (p&&q)); 
System.out.println("p || q = " + (p||q) ); 
System.out.println("!(p && q) = " + !(p && q));
}
}

Output
p && q = false 
p || q = true
!(p && q) = true

Java AND Operator Example: Logical && and Bitwise &
The logical && operator doesn't check the second condition if the first condition is false. It checks the second condition only if the first one is true.

The bitwise & operator always checks both conditions whether first condition is true or false.

public class OperatorExample
{  
public static void main(String args[])
{  
int a=10;  
int b=5;  
int c=20;  
System.out.println(a<b&&a<c);//false && true = false  
System.out.println(a<b&a<c);//false & true = false  
}
}  
Output:
false
false

Java AND Operator Example: Logical && vs Bitwise &
public class OperatorExample
{  
public static void main(String args[])
{  
int a=10;  
int b=5;  
int c=20;  
System.out.println(a<b&&a++<c);//false && true = false  
System.out.println(a);//10 because second condition is not checked  
System.out.println(a<b&a++<c);//false && true = false  
System.out.println(a);//11 because second condition is checked  
}
}  
Output:
false
10
false
11

Java OR Operator Example: Logical || and Bitwise |
The logical || operator doesn't check the second condition if the first condition is true. It checks the second condition only if the first one is false.

The bitwise | operator always checks both conditions whether first condition is true or false.

public class OperatorExample
{  
public static void main(String args[])
{  
int a=10;  
int b=5;  
int c=20;  
System.out.println(a>b||a<c);//true || true = true  
System.out.println(a>b|a<c);//true | true = true  
//|| vs |  
System.out.println(a>b||a++<c);//true || true = true  
System.out.println(a);//10 because second condition is not checked  
System.out.println(a>b|a++<c);//true | true = true  
System.out.println(a);//11 because second condition is checked  
}
}  
Output:
true
true
true
10
true
11

7.Ternary / Conditional Operator
Java Ternary operator is used as one line replacement for if-then-else statement and used a lot in Java programming. It is the only conditional operator which takes three operands.
Java Ternary Operator Example
public class OperatorExample
{  
public static void main(String args[])
{  
int a=2;  
int b=5;  
int min=(a<b)?a:b;  
System.out.println(min);  
}
}  
Output:
2

Another Example:
public class OperatorExample
{  
public static void main(String args[])
{  
int a=10;  
int b=5;  
int min=(a<b)?a:b;  
System.out.println(min);  
}
}  
Output:
5

8.Assignment Operator{(10): +=,-=,*=,/=,%=,>>=,<<=,&=,!=,^=}
Java assignment operator is one of the most common operators. It is used to assign the value on its right to the operand on its left.


Java Assignment Operator Example
public class OperatorExample
{  
public static void main(String args[])
{  
int a=10;  
int b=20;  
a+=4;//a=a+4 (a=10+4)  
b-=4;//b=b-4 (b=20-4)  
System.out.println(a);  
System.out.println(b);  
}
}  
Output:
14
16

Java Assignment Operator Example
public class OperatorExample
{  
public static void main(String[] args)
{  
int a=10;  
a+=3;//10+3  
System.out.println(a);  
a-=4;//13-4  
System.out.println(a);  
a*=2;//9*2  
System.out.println(a);  
a/=2;//18/2  
System.out.println(a);  
}
}  
Output:
13
9
18
9

Example
public class AssignmentOperator 
{
   public static void main(String args[])
 {
      int a = 5;
      int b = 10;
      int c = 0;
      c = a + b;
      System.out.println("c = a + b = " + c );

      c += a ;
      System.out.println("c += a  = " + c );

      c -= a ;
      System.out.println("c -= a = " + c );

      c *= a ;
      System.out.println("c *= a = " + c );

      a = 10;
      c = 15;
      c /= a ;
      System.out.println("c /= a = " + c );

      a = 10;
      c = 15;
      c %= a ;
      System.out.println("c %= a  = " + c );

      c &= a ;
      System.out.println("c &= a  = " + c );

      c ^= a ;
      System.out.println("c ^= a   = " + c );

      c |= a ;
      System.out.println("c |= a   = " + c );
      c <<= 2 ;
      System.out.println("c <<= 2 = " + c );

      c >>= 2 ;
      System.out.println("c >>= 2 = " + c );

      c >>= 2 ;
      System.out.println("c >>= 2 = " + c );

   }
}

Output
c = a + b = 15
c += a  = 20
c -= a = 15
c *= a = 75
c /= a = 1
c %= a  = 5
c &= a  = 0
c ^= a   = 10
c |= a   = 10
c <<= 2 = 40
c >>= 2 = 10
c >>= 2 = 2

Java Assignment Operator Example: Adding short
public class OperatorExample
{  
public static void main(String args[])
{  
short a=10;  
short b=10;  
//a+=b;//a=a+b internally so fine  
a=a+b;//Compile time error because 10+10=20 now int  
System.out.println(a);  
}
}  
Output:
Compile time error

After using the type cast we can remove the compile time error:
public class OperatorExample
{  
public static void main(String args[])
{  
short a=10;  
short b=10;  
a=(short)(a+b);//20 which is int now converted to short  
System.out.println(a);  
}
}  
Output:
20

9.Special Operator
instanceof Operator
The java instanceof operator is used to test whether the object is an instance of the specified type (class or subclass or interface) i.e for object reference variables.
Syntax:
( Object reference variable ) instanceof (class/interface type)

Java instanceof Operator Example:
public class InstanceOfOperator
{
public static void main(String args[])
{
String location = "mvpcolony";
// following will return true since location is type of String
boolean result = location instanceof String; 
System.out.println( result );
}
}
Output :
true

Java Operator Precedence and Associativity

Example :
class Precedence 
{
    public static void main(String[] args) 
{
      int a = 10, b = 5, c = 1, result;
    result = a - ++c - ++b; // 10 - 2 - 6  
    System.out.println(result);
    }
}
Output:
2

Example :
class Precedence 
{
    public static void main(String[] args) 
{
      int a = 10, b = 5, c = 1, result;
     result = a * ++c - ++b; // 10 * 2 - 6  
     System.out.println(result);
    }
}
Output:
14

Java Data Types

There is a basic java data type for each variable in Java.

The data type of a variable determines the type of data the variable can contain, and what operations we can execute on it.

Every bit of processed data is divided into types. There are various kinds of data types in Java, the data types are mainly of two categories:
a. Primitive Data Types in Java
Primitive data types are fundamental data types offered by Java. These are the basic data values. These data types are hard coded into the Java compiler so that it can recognize them during the execution of the program.

There are 8 types of primitive data types in Java:
Data Type   Default size
byte          1 byte
short          2 byte
int             4 byte
long             8 byte
double     8 byte
float             4 byte
boolean         1 bit
char             2 byte
Note:
  • byte, short, int and long data types are used for storing whole numbers.
  • float and double are used for fractional numbers.
  • char is used for storing characters(letters).
  • boolean data type is used for variables that holds either true or false.
byte:
This can hold whole number between -128 and 127. Mostly used to save memory and when you are certain that the numbers would be in the limit specified by byte data type.
Default size of this data type: 1 byte.
Default value: 0
Example:
class JavaExample 
{
    public static void main(String[] args)
    {
    byte num;
    num = 113;
    System.out.println(num);
    }
}
Output:
113

Note:
Try the same program by assigning value assigning 150 value to variable num, you would get type mismatch error because the value 150 is out of the range of byte data type. The range of byte as I mentioned above is -128 to 127.

short:
This is greater than byte in terms of size and less than integer. Its range is -32,768 to 32767.
Default size of this data type: 2 byte

short num = 45678;

int: 
Used when short is not large enough to hold the number, it has a wider range: -2,147,483,648 to 2,147,483,647
Default size: 4 byte
Default value: 0
Example:
class JavaExample
 {
    public static void main(String[] args)
   {
       short num;
       num = 150;
    System.out.println(num);
    }
}
Output:
150
The byte data type couldn’t hold the value 150 but a short data type can because it has a wider range.

long:
Used when int is not large enough to hold the value, it has wider range than int data type, ranging from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.
size: 8 bytes
Default value: 0
Example:
class JavaExample 
{
    public static void main(String[] args) 
    {
      long num = -12332252626L;
    System.out.println(num);
    }
}
Output:
-12332252626

double:
Sufficient for holding 15 decimal digits
size: 8 bytes
Example:
class JavaExample 
{
    public static void main(String[] args)
   {
      double num = -42937737.9d;
    System.out.println(num);
    }
}
Output:
-4.29377379E7

float: 
Sufficient for holding 6 to 7 decimal digits
size: 4 bytes
Example:
class JavaExample 
{
    public static void main(String[] args) 
    {
      float num = 19.98f;
    System.out.println(num);
    }
}
Output:
19.98

boolean:
holds either true of false.
Example:
class JavaExample 
{
    public static void main(String[] args) 
   {
     boolean b = false;
    System.out.println(b);
    }
}
Output:
false

char: 
It holds characters.
size: 2 bytes
Example:
class JavaExample 
{
    public static void main(String[] args) 
    {
        char ch = 'Z';
    System.out.println(ch);
    }
}
Output:
Z

b. Non-Primitive Data Types in Java
Non-Primitive data types are the reference data types. These are the special data types that are user-defined. The program already contains their definition. Some examples of non-primitive or reference data types are classes, interfaces, String, arrays, etc.

Type casting:
Type casting is nothing but assigning a value of one primitive data type to another. When you assign the value of one data type to another, you should be aware of the compatibility of the data type. If they are compatible, then Java will perform the conversion automatically known as Automatic Type Conversion and if not, then they need to be casted or converted explicitly.

There are two types of casting in Java as follows:
Widening Casting(automatically): This involves the conversion of a smaller data type to the larger type size.
byte -> short -> char -> int -> long -> float -> double

Narrowing Casting(manually): This involves converting a larger data type to a smaller size type. 
double -> float -> long -> int -> char -> short -> byte

Widening Casting(Implicit)
This type of casting takes place when two data types are automatically converted. It is also known as Implicit Conversion. This happens when the two data types are compatible and also when we assign the value of a smaller data type to a larger data type.

Narrowing Casting(Explicit)
In this case, if you want to assign a value of larger data type to a smaller data type, you can perform Explicit type casting or narrowing. This is useful for incompatible data types where automatic conversion cannot be done.

Ex:
public class Narrowing
{
public static void main(String[] args)
{
double d = 200.06;

//explicit type casting 
long l = (long)d;
 
//explicit type casting
 int i =(int) l;
System.out.println("Double Data type value "+d);

//fractional part lost
System.out.println("Long Data type value "+l);

//fractional part lost
System.out.println("Int Data type value "+i);
}
}

Output:
Double Data type value 200.06
Long Data type value 200
Int Data type value 200


Java - Syllabus & Model Question paper

Java - Syllabus

Objectives:

To introduce the fundamental concepts of Object-Oriented programming and to design &implement object oriented programming concepts in Java.

Course Learning Outcomes: At the end of this course student will:

1.Understand the benefits of a well-structured program

2.Understand different computer programming paradigms

3.Understand underlying principles of Object Oriented Programming in Java

4.Develop problem-solving and programming skills using OOP concepts

5.Develop the ability to solve real-world problems through software development in high-level programming language like Java

UNIT– I

Introduction to Java: Features of Java, The Java virtual Machine ,Parts of Java

Naming Conventions and Data Types: Naming Conventions in Java, Data Types in Java, Literals

Operators in Java: Operators, Priority of Operators

Control Statements in Java: if... else Statement, do... while Statement, while Loop, for Loop, switch Statement, break Statement, continue Statement, return Statement

Input and Output: Accepting Input from the Keyboard ,Reading Input with Java.util.Scanner Class, Displaying Output with System.out.printf(), Displaying Formatted Output with String.format()

Arrays:Types of Arrays,2DArrays and 3D Arrays, arrayname.length ,Command Line Arguments.

UNIT– II

Strings: Creating Strings, String Class Methods, String Comparison, Immutability of Strings

Introduction to OOPs: Problems in Procedure Oriented Approach, Features of Object-Oriented Programming System (OOPS)

Classes and Objects: Object Creation, Initializing the Instance Variables, Access Specifiers, Constructors

Methods in Java: Method Head error Method Prototype, Method Body, Understanding Methods, Static Methods, Static Block, The keyword ‘this’, Instance Methods, Passing Primitive Data Types to Methods, Passing Objects to Methods, Passing Arrays to Methods.

Inheritance: Inheritance, The keyword ‘super’, The Protected Specifier, Types of Inheritance

UNIT– III

Polymorphism: Polymorphism with Variables, Polymorphism using Methods, Polymorphism with Static Methods, Polymorphism with Private Methods, Polymorphism with Final Methods, final Class

Type Casting: Types of Data Types, Casting Primitive Data Types, Casting Referenced Data Types, The Object Class

Abstract Classes: Abstract Method and Abstract Class

Interfaces: Interface, Multiple Inheritance using Interfaces

Packages:Package,Different Types of Packages, The JAR Files, Interfaces in a Package, Access Specifiers in Java, Creating API Document, Exception Handling: Errors in Java Program, Exceptions, throws Clause, throw Clause, Types of Exceptions, Re – throwing an Exception.

UNIT– IV

Streams: Stream, Creating a File using File Output Stream, Reading Data from a File using File Input Stream, Creating a File using File Writer, Reading a File using File Reader.

Threads: Single Tasking, Multi Tasking, Uses of Threads, Creating a Thread and Running it, Terminating the Thread, Single Tasking Using a Thread, Multi Tasking Using Threads, Multiple Threads Acting on Single Object, Thread Class Methods. Thread Communication, Thread Priorities,  Applications of Threads, Thread Life Cycle.

UNIT– V

Servlet and JSP: Introduction to Servlet, Life Cycle of Servlet, Introduction to JSP , Life Cycle of a JSP, difference between Servlet and JSP, basic programs using JSP.

Java Database Connectivity: Database Servers, Database Clients, JDBC (Java Database Connectivity), Working with Oracle Database, Working with MySQL Database, Stages in a JDBC Program, Registering the Driver, Connecting to a Database, Preparing SQL Statements, Using JDBC Bridge Driver to Connect to Oracle Database, Retrieving Data from Oracle Database, working with Result Sets.

Model Question Paper

Section – A

Answer the following 5 X 10= 50M

1. (a)Explain the concept of Object Oriented Programming. Applications of OOPs. [CO1]

Or

    (b)Explain about control structures. With examples each.    [CO1]

2. (a)Explain about arrays and types of arrays.With examples. [CO2]

Or

    (b)Define anInheritance.Write type of inheritance with example.  [CO2]

3. (a)Write about Polymorphism and types of Polymorphism with example. [CO3]

Or

(b)Write about Interface with an example program. [CO3] 

4. (a)Define Exception Handling, write types of exceptions. Write a program using exception. [CO4]

Or

(b)Explain about Thread Life Cycle. [CO4]

5. (a)Define Servlet and JSP and write a program to demonstrate JSP. [CO5]

Or

    (b)Write a short note on JDBC and write program to connect to Oracle Database.    [CO5]


Section – B

Answer any five questions. 5 X 3 = 15 M


6. Define operator.  List all operators and explain with example any three of them.  [CO1]

7. What is java virtual machine? Explain. [CO1]

8. Define constructor.  Explain about types of constructor. [CO2]

9. Define inheritance. Write a java program to implement single inheritance. [CO3]

10. Write a short note on throw key word. [CO4]

11. Draw thread Life Cycle diagram. [CO4]

12. Define package. How to create user defined packages with example? [CO5]

13. Write a short note on Thin Driver. [CO5]

Section – C

     Answer all Questions 5 X 2 = 10M

14. Write a short note on break and continue statements. [CO1]

15. What are various types of access specifiers? [CO2]

16. What is an abstract method?                      [CO3]

17. Define run() method in Threads. [CO4]      

18. What is a Result Set?                                          [CO5]


Monday, 25 April 2022

Introduction to Java

Java programming language is a high-level, object-oriented, general-purpose and secure programming language. It was developed by James Gosling at Sun Microsystems in 1991. At that time, they called it "OAK" later they changed the name to Java in 1995. 

Java is the most widely used programming language. Java is freely accessible to users, and we can run it on all the platforms. Java follows the WORA (Write Once, Run Anywhere) principle, and it is platform-independent.

Java is the name of an island in Indonesia where the first coffee(named java coffee) was produced. And this name was chosen by James Gosling while having coffee near his office. Note that Java is just a name, not an acronym.

Editions of Java or Parts of Java:

There are three editions of Java. Each Java edition has different capabilities. The editions of Java are:

1. Java Standard Editions (SE): We use this edition to create programs for a desktop computer.

2. Java Enterprise Edition (EE): We use this edition to create large programs that run on the server and to manage heavy traffic and complex transactions.

3. Java Micro Edition (ME): We use this edition to develop applications for small devices such as set-top boxes, phones, and appliances, etc.

Java Environment- JVM, JRE, and JDK


1. JDK (Java Development Kit)
Java Development Kit provides an environment that helps to develop and execute the Java program. 

JDK, along with the JRE, contains other resources like the interpreter, loader. compiler, an archiver (jar), and a documentation generator (Javadoc). These components together help you to build Java programs.

2. JRE (Java Runtime Environment)
JRE is a collection of tools. These tools together allow the development of applications and provide a runtime environment. JVM is a part of JRE.

3. JVM (Java Virtual Machine)
Java Virtual Machine provides a runtime environment in which we can execute the bytecode. It performs the following tasks:

Loading the code
Verifying the code
Executing the code
Providing a runtime environment

JDK = JRE + Development Tools ( Compilers, Debuggers)
  
JDK = (JVM + Libraries) + Development Tools ( Compilers, Debuggers)

JDK = Java Developer Kit - The JDK is what you need to compile JAVA source code

JRE = Java Runtime Environment -  is what you need to run a JAVA Program and contains a JVM, among other things such as Libraries.

JVM = Java Virtual Machine -  The JVM actual run java byte code





For Example:


Difference between C,C++,JAVA:

C:
C is a general-purpose, structured, procedural, and high-level programming language developed by Dennis MacAlistair Ritchie in 1972 at Bell Laboratories. The successor of the C language was CPL (Combined Programming Language). It is mainly used for system programming such as to develop the operating system, drivers, compilers, etc.

The best-known example of the operating system that was developed using C language is Unix and Linux.

Features of C Language
  • Machine independent and portable
  • Modern Control Flow and Structure
  • Rich set of operators
  • Simple, Fast, and efficient
  • Case-sensitive
  • Low memory use
  • Easily extendable
  • Statically-typed
C++ (C WITH CLASS):
C++ is an object-oriented, general-purpose, programming language developed by Bjarne Stroustrup at Bell Labs in 1979. It is based on C language or we can say that it is an extension of C language. It is used to develop high-performance applications.

Features of C++ Language:
  • Case-sensitive
  • Compiler based
  • Platform-independent
  • Portability
  • Dynamic memory allocation
Java
Java is also an object-oriented, class-based, static, strong, robust, safe, and high-level programming language. It was developed by James Gosling in 1995. It is bot compiled and interpreted. It is used to develop enterprise, mobile, and web-based applications.

Features of Java
  • Object-oriented
  • Architecture-neutral
  • Platform independent
  • Dynamic and Distributed
  • Robust
  • Secure
  • Multithreaded
The following figure demonstrates that C++ is based on the C language and Java is based on the C++ and C language.


Servlet - JSP Programs

JSP(Java Server Pages) Programs : JavaServer Pages (JSP) is a Java standard technology that enables you to write dynamic data-driven pages f...