Friday 30 October 2020

Java Environment

 

 

Java Environment 


Java  environment  includes a number of development  tools , classes  and methods.  The development  tools  are  part of  the  system known  as Java Development  Kit (  JDK)  and the classes  and methods are  part of  Java Standard  Lirary ( JSL) , also  known  as  the  Application  Programming  Interface ( API) .


 

 

Java Development kits ( JDK )

 

 

Java Development  kits ( JDK ) 

 

The  JDK   comes  with  a set  of tools that  are used  for  developing  and running   Java program . It includes:


1. Appletviewer ( It is used  for  viewing  the  applet )

 

2. Javac ( It  is a  java  Compiler )

 

3. Java ( It is a java Interpreter)

 

4. Javap ( java diassembler, which  convert  byte code  into  program description )

 

5.  Javah (  It  is  for  java C header  files )

 

6. Javadoc (  It is for  creating  HTML  document )

 

7. Jdb ( It  is  java debugger )

 

 

 

 For  compiling  and running  the program  we have to  use  following  commands  :-




(a)  javac ( java compiler )  :-   

In java , we  can use any text editor  for writing  program  and  then  save that  program  with  "java"  extension .  Java  compiler  converts the  source  code or  program  in bytecode and  interpreter  convert  "  java " file  in "class" file .

 

syntax :-

 C:\javac filename.java

if  my filename is "abc.java" them  the syntax will be:

 C:\javac abc.java

 

 

(b)  java  ( Java interpreter ) :-

 We can use any text editor for  writing  program  and  then save that  program with  "java" extension . Java compiler  converts the source  code  or program  in  bytecode  and interpreter convert  "java" file  in  "class" file .

 

syntax :-

C:\ java  filename 

 if my filename is abc. java  then  the syntax  will be:

C:\ java abc  

 

 

 

 


Simple Java program

 

 

Simple Java program 


Consider  a simple  java  program below :-



class FirstProgram 

{

   public static void main(String args[])

    {

      System.out.println ("This is my first program ");

 

    }

 

}

 

 

 

 

 

1. The  file must be named  " FirstProgram .java"  to equivalent the class name  containing  the main  method .

 

2.  Java  is case  sensitive. This  program  defines  a class  called "FirstProgram ".

 

3. A class  is an  object oriented  term .  It is  designed  to perform  a specific  task . A java  class  is  defined by  its  class name , an open  curly  brace, a list  of  methods  and  fields, and a close curly  brace.



4. The  name of  the  class  is mode  of  alphabetical  charecters and  digits  without  spaces,  the  first charecter must be alphabetical.

 

 

5.  The line public static void main(String args[]) shows where  the  program will  start  running .  The  world  main  means  that  this  is the main  method  and  the JVM  starts running  any  program  by  executing  this method first.

 

 

 6. The main method  in "FirstProgram.java" consists of  a single  statement  :

System.out.println ("This is my first program "); 


The  statement  outputs  the  character between  quotes to the console.

 

 

 

 

 

JVM architecture

 

 

JVM  architecture:-

   If we start  learning  java , we  would want  to learn  full details of  how  JVM  really  functioning . Here  is  JVM  architecture .

 

JVM has various sub components internally .

1. Class loader sub-system :  JVM 's class  loader  sub - system  perform 3 tasks

    (a). It loads class file into memory 

    (b). It  verified  byte code  instructions 

     (c). It  allots  memory  required for  the program.

 

 

2. Run time  data area :  This  is  the memory  resource  used by JVM  and it  is divided  into  5 parts :-

  a.  Method area - Method area  stores class code  and  method code.

  b. Heap - Objects are created on heap.

  c.  Java stacks - Java stacks are the places                 where  the java  methods  are executed.A java stacks  contains  frames . On each  frame, a  separate  method is executed.

  d. Program counter registers - The program counter registers  store  memory  address of  the instruction  to be  executed  by  the  micro-processor.

 

 e. Native mathod stacks -  The native  method stacks are places  where  native  methods  ( for example, C  language  programs )  are  executed . Native  method is  a function , which  is written  in  another  language other than Java.

 

 

Native  method interface

 

Native method  library 

 

Execution  engine 

 

 

 

 

 


Java is not 100% pure object-oriented language

 

 

 Java is not 100% pure  object-oriented language because of following  reasons:-


1.   Everything in Java  is not  considered as a Object , there are  primitive  data  types available.


example - For  numbers  we are  using  the  int which  is  not  a object  type. ( only integer is  object type ).



2.  All  feature  of  OOPS language is not  fully  supported  by Java .


example - Multiple  inheritance, operator  overloading  , etc.


For a pure object  oriented  language  ,  there  should  be 6 features available  with it . They are :-


1. Encapsulation /  Information  Hiding .

 

2. Inheritance. 


3. Polymorphism/ Dynamic  Binding .

 

4. All  pre -defined  type  should  be  objects.

 

5. All  operation  performed  by  sending  messages  to  Objects.

 

6. All user - defined  type  are  objects .



But  in java , features  4 and 5  are  lacking . That 's  why  it is not  100%  pure  object oriented programming  language.






JVM ( Java Virtual Machine )

 

 

What is JVM  ( Java Virtual Machine ) ? 


JVM ( Java Virtual Machine ) :-

    All programming language compilers  convert the  source code to machine  code . Same  job done by Java Compiler  to run a Java program, but  the difference  is  that Java compiler  convert the source  code  into intermediate code   is called as bytecode .This machine is called the Java Virtual Machine  and  it  exists only  inside the computer memory . 




following  figure  shows the  process of  compilation :


Java program  -----Java compiler -----Virtual machine code 

 

 

 The  Virtual machine code  is not  machine  specific .  The  machine specific code is generated . By  java  interpreter  by acting  as an intermediary between the  virtual machine and  real  machine  shown below:-

 

Byte code ---Java interpreter---- Machine code 

 

Java Object  Framework act as the intermediary  between the user  programs  and the  virtual  machine which  in   turn  act  as the  intermediary between  the operating system  and the Java Object Framework.

 

 

 

 

 

Difference between C++ and JAVA

 

 

 

Difference between C++  and  JAVA 




JAVA 

1. Java is  true Object-Oriented language.

 

2. Java does not support  operator  overloading .

3. It supports lables  with  loops  and  statement     blocks.

 

4. Java does not have template classes  as in C++.

 

5. Java compiled into byte code  for  the  java virtual machine . The  source code  is  independent on operating system .

 

6. Java does not  support multiple  inheritance of classes  but it supports  interface.

 

7.Runs in a  protected  virtual machine .


8. Java  does  not  support  global variable variable .Every variable should declare in class.


9. Java does not use pointe.


10.  It Strictly  enforces an object oriented programming  paradiam.


11. There  are no  header  files in java.


12. De - allocation  of memory  will be take  care of  by JVM.


13. Java supports  4 access specifiers : Private ,Public, Protected and  Deault.


14. Only  constructors are  there  in java .  No  destructors  are available.



             DIFFERENCE

                     

 

 

C++

 

1. C++ is basically C with Object -Oriented extension.

2. C++ supports operator overloading .

 

3. It supports goto  statement .

 

4.  C++ has template classes.

 

5. Source code  can be written to be  plateform  independent and  written to  take  advantage  of  platform . C++  typically compiled into machine code.


6. C++ supports  multiple inheritance of  classes.


7. Exposes low -level system  facilities.


8. C++  support global  variable.


9. C++  uses  pointer . 

 

10.  It allow  both  procedural programming  and  object - oriented  programming .

 

11. We have to use header  file  in C++.

 

12.  De -allocating  memory  is the  responsibility of  the  programmer.

 

13. There are 3  access  specifiers in C++ : Private , Public   and Protected.

 

14. There are  constructors and deconstructors in C++. 

 

 

 

 

 

Thank you 💖

 

Thursday 29 October 2020

What is Bytecode

 

What is Bytecode 



The key  that  allow Java  to solve both  the  security and  the  porability problems  is that  the output  of a  Java  compiler  is not  executable  code . Rather , it is  bytecode . Bytecode  is a  highly optimized  set  of   instruction  designed  to be  executed  by the java  run -time   system , which  is called  the JAVA VIRTUAL MACHINE  (JVM) . In essence,  the original  JVM  was designed  as an  interpreter  for  bytecode . This  may come  as a bit  of  a surprise  since  many  modern  language are  designed  to be  compiled  into  executable  code  because  of  performance  conerns.

 

 




Java Buzzwords

 

 

Features of Java 


               Java Buzzwords



The following  are the list of buzzwords of Java:-

 

1. Simple 

2. Secure 

3. Portable

4. Object -Oriented 

5. Robust

6. Multithreaded

7. Architecture-neutral

8. Interpreted and High performance

9. Distributed

10. Dynamic 





Simple :-

    Java was designed to be easy  for the professional programmer to learn  and use effectively . Assuming  that  we have some programming experience, we  will  not  find  java  hard  to master. If  we already  understand that  basic concepts of  object-oriented programming , learning  java will  be even  easier.




Secure :-

As we are likely aware , every  time we download  a " normal"  program , we are taking  a risk , because  the code we are  downloading  might  contain  a virus, Trojan  horse , or other  harmful  code. At the core  of the problem  is the fact  that  malicious code  can  cause  its damage  because  it has  gained  unauthorized  access to system resources.

 

 

 

Portable :-

Portability is a major aspect  of the internet because  there  are many  different  types  of computers  and  operating  system  connected to it .  If a java program were  to be  run  on virtually any  computer  connected  to the  internet , there  needed to some  way  to enable  that  program  to  execute on different systems.

 

 

 

Object- Oriented :-

Although influenced  by  its  predecessors, Java  was not  designed  to be source -code  compatible with  any  other  language . This  allowed  the java  team  the freedom  to  design  with  a blank  slate, One  outcome  of this  was a clean , usable ,  pragmatic  approach to  objects . 

 

 

 

Robust :-

 The multiplatformed  environment  of the Web place  extraordinary demands on a program , because  the program must  execute  reliably  in a variety  of  systems . Thus , the  ability to create robust  programs was given  a high priority  in the design of java . To gain reliability ,Java  restricts  we  in a few  key  areas to force  we find  our  mistakes early  in program development .

 

 

 

 

Multithreaded :-

Java  was designed  to  meet the real  -world  requirement  of creating  interactive , networked  programs.  To accomplish this , Java  supports  multithreaded  programming , which  allow  us  to write  programs  that  do  many  things  simultaneously.  The java  run -time  system . 

 

 

 

 

 Architecture- Neutral :-

A central  issue for  the java  designers  was that  of code  longevity  and  portability . One of the main  problem facing  programmers  is that  no guarantee exists that  if we  write  a  program  today , it will run  tomorrow- even  on the  same  machine . Operating  system  upgrades ,  processor  upgrades , and  changes  in core  system  resources  can all  combine  to make  a program  malfunction .

 

 

 

Interpreted and High Performance :-

Java  enables  the creation  of  cross -platform  programs by  compiling  into  an  intermediate  representation  called  Java Bytecode. This code can be  executed on  any  system  that  implements  the Java  Virtual  Machine . Most  previous attempts at cross -platform  solutions  have  done  so  at  the  expense of performance.





Distributed :-

Java  is  designed  for  the distributed environment  of the internet  because  it handle  TCP/IP protocols.  In fact , accessing  a  resource  using  a URL is   not much  different  from  accessing  a file . Java  also  supports  Remote Method  Invocation (RMI) .This feature  enables a program  to  invoke  methods across  a network .

 

 

 

 

 Dynamic :-

Java  programs carry  with  them  substantial  amounts  of  run - time  type  information  that  is used to verify and  resolve  accesses to objects  at  run time . This  make  it possible  to  dynamically  link  code  in a safe  and expedient manner . This  is crucial  to  the robustness of  the java  environment , in  which  small  fragments  of  bytecode may  be dynamically updated on  a running  system .







History of Java

 

 

              History of Java  

 

 

 Java  is a general -purpose , object-oriented programming language developed by Sun Microsystem  of USA  in  1991. Originally  called  Oak by  James   Gosling . Java  was invented  for  the  development  of software  for  consumer electronic devices like  TVs , toaster , etc . The  main aim had  to make  java simple , portable  and reliable.




year  and beginning of java  and versions of java 


1990  -Sun desided to developed software  that could  be used  for electronic  devices.  And  the  project  called  as Green Project  head  by  James Gosling.

 

1991  - Announcement of a new  language named  '' Oak ''.

 

1992  - The team verified  the  application of their  new language  to  manage a list  of home  appliances using  a hand held  device.

 

 

 

 

 

  

 

 

Thank you 💖

 

 

 

 

 










Concepts of Java

 

 Basic concepts of Java 



There  are some basic concepts of object oriented programming as follows:


1. Object

2.  Class

3.  Data  abstraction

4.  Data encapsulation

5.  Inheritance

6.  Polymorphism

7.  Dynamic binding




OBJECT :- 

   Object  are important runtime entities in object oriented  method.   They  may  characterize a location , a bank  account  , and  a table  of  data  or any  entry  that  the program must handle  






CLASSES :-

  A class is  a set  of objects  with  similar  properties , common  behavior , and  common  link  to  other  objects.  The complete  set of data and code  of an  object  can be  made  a user  defined  data  type  with  the help of class. The  object are variable of class.

 

 

 

 

DATA ABSTRACTION :-

   Data  abstraction  refers to  the act  of  representing  important  description  without  including   the background  details or explanations. Classes use  the concept of  abstraction and  are  defined  as a  list  of  abstract attributes  such  as size , cost  and  functions  operate on  these  attributes.



DATA ENCAPSULATION :-

   Data  Encapsulation  means  wrapping  of data  and functions into a single  unit . it is most  useful   feature  of class .The  data  is not  easy  to go  to the outside world and  only those  functions  which  are enclosed  inthe  class can access it. This  insulation  of data  from  direct  access  by the program is called  as DATA HIDING .

 

 

 

INHERITANCE :-

 Inheritance  is the process by which objects of one class can get  the  properties  of objects of another  class. Inheritance  means  one class of objects  inherits data  and  behaviors from  another  class . Inheritance  maintains the  hierarchical classification  in which  a class  inherits from its parents .

 

 

 

POLYMORPHISM :-

Polymorphism   means  the ability to take  more  than  one  form . Polymorphism  play a main role in  allocate  objects  having  different  internal structures  to share  the same  external  interface. This means that a general class of operations  may to accessed  in the  same manner  even  though  specific  activities  associated  with  each  operation  may differ .  Polymorphism  is broadly  used  in implementing  inheritance.




DYNAMIC BINDING  :-

 Binding  refers to the linking of a procedure call to the code to  be executed  in  response  to the  call.  Dynamic  binding  means  that  the code  related  with  a  given  procedure call  is not  know  until  the time  of  the  call at run time .  Dynamic binding  is associated  polymorphism and  inheritance.




 


What is java





What is java 


Java :-

 Java is a general purpose, high -level  programming  language developed by Sun Microsystems. A  small  team  of  engineers, known  as the Green  Team ,  initiated the  language in 1991. Java  was  originally called  OAK , and  was  designed  for handheld devices  and  set-top boxes.  

                     OAK  was unsuccessful, so in 1995  Sun changed  the  name  to  Java  and modified the language to  take  advantage of  the  burgeoning World Wide Web. 









Student Marks Calculation app using java

      import javax.swing. *; import java.awt.event.ActionEvent ; import java.awt.event.ActionListener ; public class Student { private J...