Monday, August 15, 2022

Java Runtime class

 Java Runtime class is used to interact with java runtime environment. Java Runtime class provides methods to execute a process, invoke GC, get total and free memory etc. There is only one instance of java.lang.Runtime class is available for one java application.

The Runtime.getRuntime() method returns the singleton instance of Runtime class.

Important methods of Java Runtime class

No.MethodDescription
1)public static Runtime getRuntime()returns the instance of Runtime class.
2)public void exit(int status)terminates the current virtual machine.
3)public void addShutdownHook(Thread hook)registers new hook thread.
4)public Process exec(String command)throws IOExceptionexecutes given command in a separate process.
5)public int availableProcessors()returns no. of available processors.
6)public long freeMemory()returns amount of free memory in JVM.
7)public long totalMemory()returns amount of total memory in JVM.

Java Runtime exec() method

  1. public class Runtime1{  
  2.  public static void main(String args[])throws Exception{  
  3.   Runtime.getRuntime().exec("notepad");//will open a new notepad  
  4.  }  
  5. }  

How to shutdown system in Java

You can use shutdown -s command to shutdown system. For windows OS, you need to provide full path of shutdown command e.g. c:\\Windows\\System32\\shutdown.

Here you can use -s switch to shutdown system, -r switch to restart system and -t switch to specify time delay.


  1. public class Runtime2{  
  2.  public static void main(String args[])throws Exception{  
  3.   Runtime.getRuntime().exec("shutdown -s -t 0");  
  4.  }  
  5. }  

How to shutdown windows system in Java

  1. public class Runtime2{  
  2.  public static void main(String args[])throws Exception{  
  3.   Runtime.getRuntime().exec("c:\\Windows\\System32\\shutdown -s -t 0");  
  4.  }  
  5. }  

How to restart system in Java

  1. public class Runtime3{  
  2.  public static void main(String args[])throws Exception{  
  3.   Runtime.getRuntime().exec("shutdown -r -t 0");  
  4.  }  
  5. }  

Java Runtime availableProcessors()

  1. public class Runtime4{  
  2.  public static void main(String args[])throws Exception{  
  3.   System.out.println(Runtime.getRuntime().availableProcessors());  
  4.  }  
  5. }  

Java Runtime freeMemory() and totalMemory() method

In the given program, after creating 10000 instance, free memory will be less than the previous free memory. But after gc() call, you will get more free memory.

  1. public class MemoryTest{  
  2.  public static void main(String args[])throws Exception{  
  3.   Runtime r=Runtime.getRuntime();  
  4.   System.out.println("Total Memory: "+r.totalMemory());  
  5.   System.out.println("Free Memory: "+r.freeMemory());  
  6.     
  7.   for(int i=0;i<10000;i++){  
  8.    new MemoryTest();  
  9.   }  
  10.   System.out.println("After creating 10000 instance, Free Memory: "+r.freeMemory());  
  11.   System.gc();  
  12.   System.out.println("After gc(), Free Memory: "+r.freeMemory());  
  13.  }  
  14. }  
Total Memory: 100139008
Free Memory: 99474824
After creating 10000 instance, Free Memory: 99310552
After gc(), Free Memory: 100182832

Friday, July 29, 2022

Arrays of Primitive Data Types

An array is a collection of similar data types. Array is a container object that hold values of homogenous type. It is also known as static data structure because size of an array must be specified at the time of its declaration.

An array can be either primitive or reference type. It gets memory in heap area. Index of array starts from zero to size-1.

Array Declaration

Syntax :

datatype[] identifier;
or
datatype identifier[];

Both are valid syntax for array declaration. But the former is more readable.

Example :

int[] arr;
char[] arr;
short[] arr;
long[] arr;
int[][] arr; //two dimensional array.

Initialization of Array

new operator is used to initialize an array.

Example :

int[] arr = new int[10];    //10 is the size of array.
or
int[] arr = {10,20,30,40,50};

Accessing array element

As mention ealier array index starts from 0. To access nth element of an array. Syntax

arrayname[n-1];

Example : To access 4th element of a given array

int[] arr={10,20,30,40};
System.out.println("Element at 4th place"+arr[3]);
The above code will print the 4th element of array arr on console.

foreach or enhanced for loop

J2SE 5 introduces special type of for loop called foreach loop to access elements of array. Using foreach loop you can access complete array sequentially without using index of array. Let us see an exapmle of foreach loop.

class Arraydemo
{
public static void main(String[] args)
  {
    int[] arr={10,20,30,40};
	for(int x:arr)
	{
	System.out.println(x);
	}
   }
}
Output:
10
20
30
40

Wednesday, July 13, 2022

BCA Object Oriented Programming in Java(OOP) Syllabus

This page contains Syllabus of Object Oriented Programming in Java of BCA.

TitleObject Oriented Programming in Java
Short NameOOP
Course codeCACS204
Nature of courseTheory + Practical
Semesterthird-semester
Full marks60 + 20 + 20
Pass marks24 + 8 + 8
Credit Hrs3
Elective/CompulsaryCompulsary

 Units and Unit Content

Course Description

This course covers preliminary concepts of object-oriented approach in programming with basic skills using Java. Control structures, Classes, methods and argument passing and iteration; graphical user interface basics Programming and documentation style.

Course Objectives 

The general objectives of this course are to provide fundamental concepts of Object Oriented Programming and make students familiar with Java environment and its applications.

1. Introduction to Java
teaching hours: 2 hrs

Definition, History of Java, The Internet and Java's Place of IT, Applications and Applets, Java Virtual Machine, Byte Code-not an Executable code, Procedure Oriented vs. Object-Oriented Programming, Compiling and Running a Simple Program, Setting up your Computer for Java Environment, Writing a program, Compiling, Interpreting and Running the Program, Handling Common Errors. 

2. Tokens, Expressions and Control Structures
teaching hours: 5 hrs

Primitive Data Types: Integers, Floating-Point types, Characters, Booleans; User Defined Data Types, Declarations, Constants, Identifiers, Literals, Type Conversion and Casting, Variables: Variable Definition and Assignment, Default Variable Initializations;  Command-Line Arguments, Arrays of Primitive Data Types, Comment Syntax, Garbage Collection, Expressions, Using Operators: Arithmetic, Bitwise, Relational, Logical, Assignment, Conditional, Shift, Ternary, Auto-increment and Auto-decrement, Using Control Statements(Branching: if, switch; Looping: while, do-while, for; Jumping statements: break, continue and return)

3. Object Oriented Programming Concepts
teaching hours: 9 hrs

Fundamentals of Classes: A  Simple Class, Creating Class Instances, Adding methods to  a class, Calling Functions/Methods, Abstraction, Encapsulation, Using 'this' Keyword, Constructors, Default constructors, More on methods: Passing by Value,by Reference, Access Control, Methods that Return Values, Polymorphism and Method Overloading, Recursion; Nested and Inner Classes

4. Inheritance & Packaging
teaching hours: 3 hrs

Inheritance: Using 'extends' keyword, Subclasses and Superclasses, 'super' keyword usage. Overriding Methods, Dynamic Method Dispatch; The Object class, Abstract and Final Classes, Package: Access Control; Interfaces: Defining an Interface, Implementing and applying interfaces.

5. Handling Error / Exceptions
teaching hours: 2 hrs

Basic Exceptions, Proper use of exceptions, User defined Exceptions, Catching Exception: try, catch; Throwing and re-throwing: throw, throws; Cleaning up using the finally clause.

6. Handling Strings
teaching hours: 2 hrs

Creation, Concatenation and Conversion of a String, Changing Case, Character Extraction, String Comparision, Searching Strings, Modifying Strings, String Buffer.

7. Threads
teaching hours: 7 hrs

Create/Instantiate/Start New Threads: Extending java.lang.Thread, Implementingbjava.lang.Runnable Interface; Understand Thread Execution, Thread Priorities, Synchronization, Inter-Thread Communication, Deadlock.

8. I/O and Streams
teaching hours: 2 hrs

java.io package, Files and directories, Streams and Character Streams; Reading/Writing Console Input/Output, Reading and Writing files, The Serialization Interface, Serialization & Deserialization.

9. Understanding Core Packages
teaching hours: 3 hrs

Using java.lang Package: java.lang.Math, Wrapper classes and associated methods (Number, Double, Float; Integer, Byte; Short, Long; Character, Boolean); Using java.util package: Core classes (Vector, Stack, Dictionary, Hashtable, Enumerations, Random Number Generation).

10. Holding Collection of Data
teaching hours: 3 hrs

Arrays And Collection Classes/Interfaces, Map/List/Set Implementations: Map Interface, List Interface, Set Interface, Collection Classes: Array List, Linked List, Hash Set and Tree Set, Accessing Collections/Use of An Iterator, Comparator.

11. Java Applications
teaching hours: 8 hrs

About AWT & Swing, About JFrame (a top level window in Swing), Swing components (JLabel, About text component like JTextField, JButton, Event Handling in Swing Applications, Layout Management using FlowLayout, Border Layout, Grid Layout, Using JPanel, Choice components like JCheck Box, JRadio Button, Borders components, JCombo Box & its events, JList & its events with MVC patterns, Key & Mouse Event Handling, Menus in swing, JText Area, Dialog boxes in swing, JTable for Displaying Data in Tabular form, MDI using JDesktop Pane & JInternal Frame, Using IDE like Netbeans, JBuilder for building java applications using Drag & Drop), Adapter classes.

12. Introduction to Java Applets
teaching hours: 1 hrs

Definition, Applet lifecycle methods, Build a simple applet, Using Applet Viewer, Adding Controls: Animation Concepts.

13. Database Programming using JDBC
teaching hours: 2 hrs

Using Connection, Statement & Result Set Interfaces for Manipulating Data with the Databases.


Text Books                        

1. Deitel & Dietel. -Java: How to-pikigrarn-. 9th Edition. TearsorrEducation. 2011, ISBN: 9780273759168      

2. Herbert Schildt. "Java: The CoriviaeReferi4.ic e 61 Seventh Edition. McGraw -Hill 2006, 1SBN; 0072263857

Reference Books 

1. Bruce Eckel, -Thinking in Java", 4111 Edition, Prentice Hall, 2006, ISBN: 0- 13-187248-6

2. Cay Horstmann and Grazy Cornell, "Core Java Volume 1-Fundamentals", Ninth edition, Prentice Hall, 2012, ISBN: 978-0137081899

3. E. Ralagurusan-iy, "Programming with Java: A Primer", 4th Edition, Tata McGraw Hill Publication. India,

Saturday, April 30, 2022

Introduction to Java Programming Language

 Java is a powerful object-oriented programming language developed by the famous  Canadian computer scientist, James Aruther Gosling at Sun Microsystems in the year 1995 along with his colleagues Mike Sheridan and Patrick Naughton. Gosling who is best known as the father of the Java programming language is also credited with the name Dr.Java for his incredible creation of the fast-paced technological world. Gosling has a clear vision of the Write Once, Run Anywhere principle while designing this platform-independent programming language which stands out even today.  

History of Java

Before getting started with java, let's go back to the era that gave birth to this powerful yet robust programming language named JAVA. The seed of the Java language was initially planted in the mind of Sun’s Microsoft lead architect James Aruther Gosling, as a part of a research project in 1991. Gosling along with his colleagues started working to develop advanced software for a wide spectrum of network devices and embedded systems.

In the initial phase, the language of choice was C++ and with the passage of time, they realized the difficulties with C++ in designing and implementation, and later it demanded the need for an exclusive programming language platform. Consequently, the Java programming platform is designed by adapting the design and architecture plans sketch from various other programming languages. 

Firstly this programming language was named OAK, after the tree that stood near Gosling’s office. But unfortunately, due to some copyright problems, they were forced to change the name. Several names like Green, Silk, DNA, WRL, etc were on their list and eventually, they decided to end up with a fresh and warm name to their new language which is JAVA, the name of an Indonesian coffee.

Java Features/ Java Buzzwords 

The creator of Java designed this beautiful language with the inclusion of some distinguishable features which makes this language vivid and compatible even today. Their design goal was to develop a technology that is simple, portable but secure, and robust with promising high performance on multiple platforms in a distributed network.  The unique features that molded this powerful language are termed Java Buzzwords. 

Key Features of Java

So, What are the major features of Java programming?

  1. Simple 

     The first and foremost design goal of the Java programming language is the simplicity of the language. The language is designed in such a way that anyone can quickly grasp the basic programming knowledge and can start to code even as an absolute beginner.

  2. Object-oriented

    Another important feature that is incorporated in the Java programming language is the concept of object-oriented programming - in the sense, each and everything in java is an object which integrates data and behavior. The programming system of Java has embraced the OOPS concept to function effectively in this fast-paced and complex network-based environment. OOPs, concepts are visualized in the below diagram.

    OOPS Java
  3. Familiar

    Familiar means closely acquainted. Yes, Java programming language has a close acquaintance with C and  C++ and it may look similar to C and C++. This is because the style and syntax of java were borrowed from those languages discarding all complexities and skeptical concepts.  Programmers who are familiar with C, C++, and associated languages can effortlessly migrate to the Java platform with a quite short learning curve. 

  4. Robust

    Java is robust in the sense:

    • Java scrutinizes the code during compile-time and runtime to eliminate the errors and thereby provide error-prone codes.
    • Java is capable of managing the memory tightly and efficiently by utilizing the Garbage Collector which locates the unused objects and deletes them to secure space in the memory.
    • Java is also effective in handling exceptions with the help of a mechanism called exception handling.
    • Java does not have explicit pointers too.
  5. Secure

    Java is a secure programming language because it is designed in a way that it can function in distributed environments without the fear of being attacked by intruders or untrustworthy parties.

    What makes Java the most secure language is the bytecode that developed after compilation. The bytecode is close to machine language and is not readable by humans. Hence the possibility to be modified by any third party is minuscule. 

    Moreover, java programs always run in the sandbox(JRE) with no or minimal interconnection with the Operating System thereby preventing the invasion of untrusted sources and so are extensively used in developing virus-free and temper-free applications.

  6. Architecture Neutral 
    Key Features of Java

    To deploy the java based applications in heterogeneous network environments, the Java byte code - an architecturally neutral intermediate format has been designed. From the diagram, it is pretty clear that the java source code is converted to java byte codes by the Java compiler. This intermediate code can be efficiently transferred to various hardware and software platforms.

  7. Portable

    Another prominent feature of Java technology that is clearly tied with architecture neutrality is portability(platform independence) which means the program or code written in one platform can run readily on another platform without any changes(or minimal change).

    The important component that incorporates both architecture neutrality and portability is the JVM(Java Virtual Machine). As the name indicates, it acts like a virtual platform and performs specific implementation for specific hardware and specific software platforms. Refer diagram given in architectural neutral.

  8. High Performance 

    Java technology accounts for a high degree of performance. Always assured great performance by facilitating a strategy by which the interpreter can run at full speed without bothering the runtime environment check. The automatic garbage collector guarantees the availability of memory whenever it is needed which expedites better performance.

  9. Interpreted

    The involvement of the compiler makes java a compiled language where the java source code gets converted into some kind of machine instructions called bytecode. Similarly, the intervention of JVM which serves as an interpreter entitles java as an interpreted language. The JVM takes the byte code and executes it on a real computer.

  10. Multithreaded  

    Multithreading is an important feature of the Java language. It simply means doing multiple things at a time. A multithreaded java application can run two or more threads simultaneously thereby attaining maximum utilization of CPU and a high degree of interactivities for the end-user.

  11. Dynamic 

    Java language is said to be dynamic in a way that the language and its run-time system are dynamic in their linking phase though the compiler uncompromisingly sticks on its static type checking. To be more specific anything that happens on run-time is said to be dynamic, here in Java on-demand basis one can link and load classes, code modules, or even interactive executable codes from across the network.

Features Discarded From C & C++

To achieve the simplicity of the Java programming language, designers had removed many of the features causing redundancy and uncertainty. The indecisive features withdrawn from C and C++ are listed below:

Java has :

  • No preprocessor, no typedef and no 
  • No complex data types like Structure, Union, and Enum
  • No pointer data types
  • No functions
  • No Multiple inheritances 
  • No operator overloading
  • No Goto Statements
  • No Automatic Coercions
     

Java Application:

The incredibly impressive features of java make java 'the king of all programming languages and extremely popular in all aspects of technology, be it in a desktop application or web development or in big data analysis. Java since its launch has been continually chosen as the high-ranking programming language till now. The 10 top-notched applications that run on java with their real-world examples are tabularized below.

SL NOJava ApplicationsExample
1Desktop GUI  applicationsAcrobat Reader,  ThinkFree
2Mobile applicationsNetflix, Google Earth, Uber
3Web-based applicationsAmazon, Broadleaf
4Embedded SystemsSim Card, Blue-ray disc player
5Application ServersWebSphere, WebLogic
6Web ServersApache Tomcat, Rimfax Web Server
7Enterprise ApplicationsERP, CRM
8Scientific ApplicationsMatlab
9Big Data ApplicationsHadoop, Apache HBase
10Software ToolsEclipse, Net Beans

Java is not limited to a specific area, it grounds its way in all aspects and hence the applications that rely on java are countless. So undoubtedly we can say, JAVA programming language is the best option for everyone, be it an absolute beginner or professional.

Tuesday, April 19, 2022

JAVA URL

 https://mrcet.com/downloads/digital_notes/IT/Java%20Programming.pdf

https://www.iitk.ac.in/esc101/share/downloads/javanotes5.pdf

https://www.cs.cmu.edu/afs/cs.cmu.edu/user/gchen/www/download/java/LearnJava.pdf


https://www.tutorialsduniya.com/notes/java-notes/



https://examupdates.in/java-programming-notes/

https://www.cs.usfca.edu/~parrt/doc/java/JavaBasics-notes.pdf

https://www.smartzworld.com/notes/java-programming-pdf-notes-java-pdf-notes/

https://ocw.mit.edu/courses/6-092-introduction-to-programming-in-java-january-iap-2010/pages/lecture-notes/


LECTURE NOTES

Abbreviations

API = Application Programming Interface

I/O = input/output

LEC #TOPICSFILES
1Types, variables, operators(PDF)
2More types, methods, conditionals(PDF)
3Loops and arrays(PDF)
4Objects and classes(PDF)
5Access control, class scope, packages, Java API(PDF)
6Design, debugging, interfaces(PDF)
7Inheritance, exceptions, file I/O(PDF)

techguruspeaks

  Core Java programming Introduction to Java Java Features Writing a Simple Java Program Java Keywords and Comments Variables, Identifiers ...